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.

47 lines
1.2 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 "copyGifUrl":
  5. copyToClipboard( info, tab );
  6. break;
  7. case "downloadGif":
  8. chrome.tabs.sendMessage(tab.id, {command: info.menuItemId});
  9. break;
  10. }
  11. });
  12. }
  13. function copyToClipboard(info, tab){
  14. chrome.tabs.sendMessage(tab.id, {command: info.menuItemId}, function(response) {
  15. var urlTextArea = document.createElement('textarea');
  16. urlTextArea.value = response.url;
  17. document.body.appendChild(urlTextArea);
  18. urlTextArea.select();
  19. document.execCommand('copy');
  20. document.body.removeChild(urlTextArea);
  21. });
  22. }
  23. chrome.contextMenus.onClicked.addListener(onClickHandler);
  24. chrome.contextMenus.create({ "title": "Copy Gif Url",
  25. "contexts":["video"],
  26. "id": "copyGifUrl",
  27. "documentUrlPatterns": ["*://9gag.com/*"]
  28. },
  29. confirmMenuCreation );
  30. chrome.contextMenus.create({ "title": "Download Gif",
  31. "contexts":["video"],
  32. "id": "downloadGif",
  33. "documentUrlPatterns": ["*://9gag.com/*"]
  34. },
  35. confirmMenuCreation );
  36. function confirmMenuCreation(){
  37. // console.log("Created context menu");
  38. }