Browse Source

first commit

master
Andrea Cimbalo 10 years ago
commit
daf2a4a1e9
4 changed files with 91 additions and 0 deletions
  1. +28
    -0
      gif.js
  2. +4
    -0
      jquery-2.1.4.min.js
  3. +39
    -0
      main.js
  4. +20
    -0
      manifest.json

+ 28
- 0
gif.js View File

@ -0,0 +1,28 @@
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);
var urlTextArea = document.createElement('textarea');
urlTextArea.value = response.url;
document.body.appendChild(urlTextArea);
urlTextArea.select();
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 to clipboard", "contexts": ["video"],
"id": "copyGifUrl",
"documentUrlPatterns": ["*://9gag.com/"]});
chrome.contextMenus.create({"title": "Download gif file", "contexts": ["video"],
"id": "downloadGif",
"documentUrlPatterns": ["*://9gag.com/"]});
});

+ 4
- 0
jquery-2.1.4.min.js
File diff suppressed because it is too large
View File


+ 39
- 0
main.js View File

@ -0,0 +1,39 @@
var currentVideo = null;
jQuery("#list-view-2").on( "click", ".badge-evt.post-read-more", function( event ) {
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();
event.preventDefault();
});
jQuery( document ).ready(function() {
jQuery("#overlay-container").remove();
});
$("#list-view-2").on('contextmenu', "video", function(e) {
currentVideo = jQuery(event.target);
});
function downloadURI(uri, name)
{
var link = document.createElement("a");
link.download = "dsfsd";
link.href = uri;
link.click();
}
chrome.extension.onMessage.addListener(
function(request, sender, sendResponse) {
if (request.command == "copyGifUrl" || request.command == "downloadGif"){
url = currentVideo.parent().data("image").replace("a.gif", ".gif")
}
if (request.command == "copyGifUrl"){
sendResponse({url: url});
}else if (request.command == "downloadGif"){
console.log(currentVideo.parents("article").find("h2").text().trim());
downloadURI(url, currentVideo.parents("article").find("h2").text().trim() + ".gif");
}
}
);

+ 20
- 0
manifest.json View File

@ -0,0 +1,20 @@
{
"manifest_version": 2,
"name": "Getting started example",
"description": "This extension shows a Google Image search result for the current page",
"version": "1.0",
"permissions" : [
"activeTab",
"contextMenus",
"clipboardWrite"
],
"content_scripts": [ {
"js": [ "jquery-2.1.4.min.js", "main.js" ],
"matches": ["http://9gag.com/*", "https://9gag.com/*"]
}],
"background": {
"persistent": false,
"scripts": ["gif.js"]
}
}

Loading…
Cancel
Save