-
-
Save radiantly/e1c7319214c77fa007f323fc56cd0239 to your computer and use it in GitHub Desktop.
// ==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); | |
})(); |
The same does not happen on Google Chrome or other chromium browsers. Maybe someone can test this on Safari?
Same as Firefox on Safari 15.
This doesn't happen in Chrome because it supports the ping
attribute on <a>
tags. More info on that here and here.
The ping attribute is basically adds link tracking into the browser. When a user clicks on <a>
tag in Chrome with a ping
attr, the link gets clicked like normal but the browser also sends a non-blocking logging request in the background to the ping url.
This doesn't happen in Chrome because it supports the
ping
attribute on<a>
tags. More info on that here and here.The ping attribute is basically adds link tracking into the browser. When a user clicks on
<a>
tag in Chrome with aping
attr, the link gets clicked like normal but the browser also sends a non-blocking logging request in the background to the ping url.
How does ping work when copying & pasting a link?
does ping
get blocked/ignored when do-not-track is set in the request?
How does ping work when copying & pasting a link?
When copying an <a>
tag's link the ping request isn't made, but on Google their JS of course will detect your copying and send a background logging/ping request anyway.
does ping get blocked/ignored when do-not-track is set in the request?
In Chrome there's no way built-in way to turn off ping
requests. uBlock Origin can do it though and I highly recommend it: https://chrome.google.com/webstore/detail/ublock-origin/cjpalhdlnbpafiamejdnhcphjbkeiagm
An alternative solution, implemented as an addon https://github.com/dandanua/copy-true-link/blob/main/content.js
An alternative solution, implemented as an addon https://github.com/dandanua/copy-true-link/blob/main/content.js
And here an alternative solution as bookmarklet
javascript:(function(){window.addEventListener("mousedown",(event)=>{event.stopImmediatePropagation();},true);})()
Store this as bookmark (URL) drag in into the bookmark toolbar and click it once before you copy a link
(yes you have to remember click it but nothing to install which I prefer)
You want to add same handler for 'focus' event. Thats what Google uses on Image search.
One reason I would highly recommend DuckDuckGo (and the ddgr
CLI). You could also use the googler
CLI.
Thanks, this is so useful!
It happens on the standard version of Firefox but not on Firefox Nightly, maybe the problem is not Google itself
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!
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.
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.
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)
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.
Well so much for "Don't Be Evil"