Copy Real Link

Extract and copy real URLs from redirect URLs on Google, Fb, etc.

目前为 2023-12-24 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Copy Real Link
  3. // @namespace https://thealmahmud.blogspot.com/
  4. // @version 1.2
  5. // @license CC BY
  6. // @description Extract and copy real URLs from redirect URLs on Google, Fb, etc.
  7. // @author almahmud & gpt
  8. // @match *://www.google.*/*search*
  9. // @match *://search.yahoo.com/*
  10. // @match *://*.facebook.com/*
  11. // @match *://hangouts.google.com/*
  12. // @grant GM_setClipboard
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. document.addEventListener('contextmenu', function(event){
  19. let target = event.target;
  20.  
  21. // Check if the right-clicked element is a link
  22. if (target.tagName === 'A' && target.href) {
  23. let url = target.href;
  24. let testRE;
  25.  
  26. // Define the regular expressions for each website
  27. if (document.URL.match("http(s|)://www.google")) {
  28. testRE = url.match("url=([^&]*)&");
  29. } else if (document.URL.match("http(s|)://mail.google")) {
  30. testRE = url.match("url\\?q=([^&]*)&");
  31. } else if (document.URL.match("http(s|)://www.facebook")) {
  32. testRE = url.match("u=([^&]*)&");
  33. } else if (document.URL.match("http(s|)://web.facebook")) {
  34. testRE = url.match("u=([^&]*)&");
  35. } else if (document.URL.match("http(s|)://.*search.yahoo")) {
  36. testRE = url.match("RU=([^/]*)/");
  37. }
  38.  
  39. // Decode and copy the URL if a match is found
  40. if (testRE) {
  41. let realURL = decodeURIComponent(testRE[1]);
  42. GM_setClipboard(realURL); // Copy to clipboard
  43. event.preventDefault(); // Prevent the default context menu
  44. }
  45. }
  46. });
  47. })();