A LILiK chrome extension for the well known 9gag website
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

28 lines
1.1 KiB

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