diff --git a/gif.js b/gif.js index 5057329..bf66dd3 100644 --- a/gif.js +++ b/gif.js @@ -1,8 +1,20 @@ function onClickHandler(info, tab) { chrome.tabs.getSelected(null, function(tab) { - if (info.menuItemId == "copyGifUrl"){ - chrome.tabs.sendMessage(tab.id, {command: info.menuItemId}, function(response) { - console.log(response.url); + switch( info.menuItemId ){ + case "copyGifUrl": + copyToClipboard( info, tab ); + break; + case "downloadGif": + chrome.tabs.sendMessage(tab.id, {command: info.menuItemId}); + break; + } + + }); +} + +function copyToClipboard(info, tab){ + + chrome.tabs.sendMessage(tab.id, {command: info.menuItemId}, function(response) { var urlTextArea = document.createElement('textarea'); urlTextArea.value = response.url; document.body.appendChild(urlTextArea); @@ -10,19 +22,26 @@ function onClickHandler(info, tab) { document.execCommand('copy'); document.body.removeChild(urlTextArea); }); - }else if (info.menuItemId == "downloadGif"){ - chrome.tabs.sendMessage(tab.id, {command: info.menuItemId}); - } - }); -} +} chrome.contextMenus.onClicked.addListener(onClickHandler); -chrome.runtime.onInstalled.addListener(function() { - chrome.contextMenus.create({"title": "Copy Gif Url", "contexts": ["video"], - "id": "copyGifUrl", - "documentUrlPatterns": ["*://9gag.com/"]}); - chrome.contextMenus.create({"title": "Download Gif", "contexts": ["video"], - "id": "downloadGif", - "documentUrlPatterns": ["*://9gag.com/"]}); -}); +chrome.contextMenus.create({ "title": "Copy Gif Url", + "contexts":["video"], + "id": "copyGifUrl", + "documentUrlPatterns": ["*://9gag.com/*"] + + }, + confirmMenuCreation ); + +chrome.contextMenus.create({ "title": "Download Gif", + "contexts":["video"], + "id": "downloadGif", + "documentUrlPatterns": ["*://9gag.com/*"] + + }, + confirmMenuCreation ); + +function confirmMenuCreation(){ + // console.log("Created context menu"); +} diff --git a/main.js b/main.js index fc8c155..1f50058 100644 --- a/main.js +++ b/main.js @@ -12,9 +12,9 @@ function setLongPostListener(){ jQuery("#list-view-2").on( "click", ".badge-evt.post-read-more", function( event ) { event.preventDefault(); - actual = jQuery(event.target); - actual.parent().find("img").attr("src", actual.attr('href').replace("/gag/", "http://img-9gag-fun.9cache.com/photo/") + "_700b_v1.jpg"); - actual.remove(); + post = jQuery(event.target); + post.parent().find("img").attr("src", post.attr('href').replace("/gag/", "http://img-9gag-fun.9cache.com/photo/") + "_700b_v1.jpg"); + post.remove(); }); @@ -51,20 +51,20 @@ jQuery(document).ready(function() { setVideoListener(); console.log("9gag Mod Successfully Loaded!"); - hash = window.location.hash.substring(1); - if (hash){ - count = 0; - while (count < 15){ - count++; - article = jQuery("article[data-entry-id='" + window.location.hash +"']"); - if (article.length){ - jQuery("html, body").animate({ scrollTop: jQuery("article[data-entry-id='" + hash +"']").offset().top}, 1000); - break; - }else{ - jQuery("html, body").animate({ scrollTop: jQuery("div.loading").offset().top}, 1000); - } - } - } + // hash = window.location.hash.substring(1); + // if (hash){ + // count = 0; + // while (count < 15){ + // count++; + // article = jQuery("article[data-entry-id='" + window.location.hash +"']"); + // if (article.length){ + // jQuery("html, body").animate({ scrollTop: jQuery("article[data-entry-id='" + hash +"']").offset().top}, 1000); + // break; + // }else{ + // jQuery("html, body").animate({ scrollTop: jQuery("div.loading").offset().top}, 1000); + // } + // } + // } }); diff --git a/manifest.json b/manifest.json index dbc322f..7654874 100644 --- a/manifest.json +++ b/manifest.json @@ -1,5 +1,5 @@ { - "manifest_version": 2, + "name": "9GAG lilik mod", "description": "Mod to make 9gag a better place", @@ -16,5 +16,6 @@ "background": { "persistent": false, "scripts": ["gif.js"] - } + }, + "manifest_version": 2 }