Skip to content

Instantly share code, notes, and snippets.

@radiantly
Last active December 28, 2023 04:31
Show Gist options
  • Star 124 You must be signed in to star a gist
  • Fork 9 You must be signed in to fork a gist
  • Save radiantly/e1c7319214c77fa007f323fc56cd0239 to your computer and use it in GitHub Desktop.
Save radiantly/e1c7319214c77fa007f323fc56cd0239 to your computer and use it in GitHub Desktop.
Prevent Google from mangling links on the search results when clicking or copying on Firefox
// ==UserScript==
// @name Prevent link mangling on Google
// @namespace LordBusiness.LMG
// @match https://www.google.com/search
// @grant none
// @version 1.1
// @author radiantly
// @description Prevent google from mangling the link when copying or clicking the link on Firefox
// ==/UserScript==
/*
* If you're on Firefox, you might have noticed that when you try to click (or copy) a link from
* a google search result, it redirects to an intermediate page instead of taking you immediately
* to the search result. This is specifically annoying when trying to copy a google search result
* to send to someone else, because it gives you the mangled google-ified link instead.
*
* The same does not happen on Google Chrome or other chromium browsers. Maybe someone can test
* this on Safari?
*
* To install this script, you'll need a user script manager like ViolentMonkey, after which you
* can click the Raw button (gist.github.com) to install.
*/
(function() {
/*
* The following 3 lines simply prevent the mousedown event from propagating to the respective
* event listeners attached to the various link elements.
*
* On testing, this does not seem to break any actual functionality on the site.
*/
window.addEventListener("mousedown", (event) => {
event.stopImmediatePropagation();
}, true);
})();
@ziotom78
Copy link

Thanks, this is so useful!

@cryptrz
Copy link

cryptrz commented Sep 28, 2021

It happens on the standard version of Firefox but not on Firefox Nightly, maybe the problem is not Google itself

@qezz
Copy link

qezz commented Sep 28, 2021

On TamperMonkey, I managed to make it work with the @include statement instead of @match

// @include     https://www.google.com/search*

UPD: Thanks for the great script!

@cgtyoder
Copy link

cgtyoder commented Sep 28, 2021

This is not working for me - I installed with GreaseMonkey on FF 92.0.1 and GM says the script is enabled, but copying links from google search results still results in that intermediate URL. Suggestions?

EDIT: Ok, just saw @qezz's comment - making that change fixed it for me.

@NightMachinery
Copy link

NightMachinery commented Oct 3, 2021

Any way to do this on iOS Safari? Perhaps with their new extension API?

Update: The bookmarklet works, but is needs to be triggered each time manually which sucks.

@outloudvi
Copy link

Also, you may also want other regional sites of Google to be included:

(co* instead of com* is a workaround for google.co.jp)

// @match       https://www.google.co*/search

(P.S. Check qezz's comment if this does not work)

@n-buna404
Copy link

n-buna404 commented Aug 29, 2022

Thanks for sharing the script, I had found some vanilla methods that also work on firefox 104 which I thought to share here.

i) Right faraway method posted by benczur

"Right-click and hold" on some empty space away from the link. Move your mouse pointer (with right button still depressed) over the link. Release right-click and select 'Copy link location/shortcut'.(Credit to stormenet.)

ii) Inspector method posted by falconepl

Just activate the inspector tool (Shift+Ctrl+C shortcut), then right-click on a given link within Google Search results and select Copy Link Location. Because you've got the inspector tool activated, it would prevent Google's script from replacing original link's location with their own.

Source:https://webapps.stackexchange.com/questions/14120/copy-raw-link-found-by-google-search-not-the-one-with-extra-redirect-added

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment