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.

56 lines
1.5 KiB

9 years ago
9 years ago
9 years ago
  1. function onClickHandler(info, tab) {
  2. chrome.tabs.getSelected(null, function(tab) {
  3. switch( info.menuItemId ){
  4. case "copyPostPermalink":
  5. case "copyGifUrl":
  6. copyToClipboard( info, tab );
  7. break;
  8. case "downloadGif":
  9. chrome.tabs.sendMessage(tab.id, {command: info.menuItemId});
  10. break;
  11. }
  12. });
  13. }
  14. function copyToClipboard(info, tab){
  15. chrome.tabs.sendMessage(tab.id, {command: info.menuItemId}, function(response) {
  16. var urlTextArea = document.createElement('textarea');
  17. urlTextArea.value = response.url;
  18. document.body.appendChild(urlTextArea);
  19. urlTextArea.select();
  20. document.execCommand('copy');
  21. document.body.removeChild(urlTextArea);
  22. });
  23. }
  24. chrome.contextMenus.onClicked.addListener(onClickHandler);
  25. chrome.contextMenus.create({ "title": "Copy Gif Url",
  26. "contexts":["video"],
  27. "id": "copyGifUrl",
  28. "documentUrlPatterns": ["*://9gag.com/*"]
  29. },
  30. confirmMenuCreation );
  31. chrome.contextMenus.create({ "title": "Download Gif",
  32. "contexts":["video"],
  33. "id": "downloadGif",
  34. "documentUrlPatterns": ["*://9gag.com/*"]
  35. },
  36. confirmMenuCreation );
  37. chrome.contextMenus.create({ "title": "Copy post permalink",
  38. "contexts":["link"],
  39. "id": "copyPostPermalink",
  40. "documentUrlPatterns": ["*://9gag.com/*"]
  41. },
  42. confirmMenuCreation );
  43. function confirmMenuCreation(){
  44. // console.log("Created context menu");
  45. }