Browse Source

clean up gif.js and fixed domain url bug on context menu

master
edoardoo 9 years ago
parent
commit
3eb9fc237c
3 changed files with 55 additions and 35 deletions
  1. +35
    -16
      gif.js
  2. +17
    -17
      main.js
  3. +3
    -2
      manifest.json

+ 35
- 16
gif.js View File

@ -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");
}

+ 17
- 17
main.js View File

@ -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);
// }
// }
// }
});


+ 3
- 2
manifest.json View File

@ -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
}

Loading…
Cancel
Save