// ==UserScript== // @name Google Search Real Links // @namespace http://mrob.com/time/scripts-beta // @version 20240120 // license: CC BY // @description Extract and copy real URLs from redirect URLs on Google, Fb, etc. // @author almahmud, gpt, and mrob27 // @match *://*.google.com/* // @match *://search.yahoo.com/* // @match *://*.facebook.com/* // @match *://hangouts.google.com/* // @grant GM.setClipboard // ==/UserScript== // // REVISION HISTORY // 20240120 Google result links now contain a H3 sub-element so we have to go to // the parent to get the A element. (function() { 'use strict'; document.addEventListener('contextmenu', function(event){ let target = event.target; //console.log("foo1"); console.log(target); if (target.tagName === 'H3') { target = target.parentNode; //console.log("go to parent:"); console.log(target); } // Check if the right-clicked element is a link if (target.tagName === 'A' && target.href) { let url = target.href; let testRE; let found = 0; // Define the regular expressions for each website if (found = document.URL.match("http(s|)://www.google")) { // console.log(found); testRE = url.match("url=([^&]*)&"); } else if (document.URL.match("http(s|)://mail.google")) { testRE = url.match("url\\?q=([^&]*)&"); } else if (document.URL.match("http(s|)://www.facebook")) { testRE = url.match("u=([^&]*)&"); } else if (document.URL.match("http(s|)://web.facebook")) { testRE = url.match("u=([^&]*)&"); } else if (document.URL.match("http(s|)://.*search.yahoo")) { testRE = url.match("RU=([^/]*)/"); } // Decode and copy the URL if a match is found if (testRE) { let realURL = decodeURIComponent(testRE[1]); // console.log(realURL); GM.setClipboard(realURL); // Copy to clipboard event.preventDefault(); // Prevent the default context menu action(s) } } }); })();