-
-
Save tomato111/681d634ded1a9bd3107e2baf60460a35 to your computer and use it in GitHub Desktop.
| // ==UserScript== | |
| // @name ReplaceURLs(GoogleImages) | |
| // @namespace https://ashiato1.blog.fc2.com/ | |
| // @description Replace URL with original image URL in Google Images | |
| // @author tomato111 | |
| // @version 0.0.15 | |
| // @downloadURL https://gist.githubusercontent.com/tomato111/681d634ded1a9bd3107e2baf60460a35/raw/ReplaceURLs(GoogleImages).user.js | |
| // @updateURL https://gist.githubusercontent.com/tomato111/681d634ded1a9bd3107e2baf60460a35/raw/ReplaceURLs(GoogleImages).user.js | |
| // @match *://*/search?*udm=* | |
| // @match *://*/search?*tbm=isch* | |
| // @run-at document-start | |
| // @grant none | |
| // ==/UserScript== | |
| (function () { | |
| function replace_url(a) { | |
| const imageURL_RE = /[?&]imgurl=(.+?)&/i; | |
| const href = a.getAttribute('href'); | |
| if (imageURL_RE.test(href)) { | |
| let imageURL = decodeURIComponent(RegExp.$1); | |
| imageURL = imageURL.replace('-origin.fc2.', '.fc2.'); | |
| a.setAttribute('href', imageURL); | |
| a.onmousedown = function () { /*nop*/ }; | |
| } | |
| } | |
| function replace_on_mouseup(nodeSnapshots) { | |
| for (let i = 0; i < nodeSnapshots.snapshotLength; i++) { | |
| const a = nodeSnapshots.snapshotItem(i); | |
| a.addEventListener("mouseup", function () { | |
| //console.log("mouseup", a); | |
| replace_url(a); | |
| }, { once: true, capture: true }); | |
| } | |
| } | |
| document.addEventListener('DOMContentLoaded', function () { | |
| const a_xpath = '//a'; | |
| const obs_target = document.querySelector('div#islrg') || document.querySelector('div#rso'); | |
| const nodeSnapshots = document.evaluate(a_xpath, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); | |
| if (nodeSnapshots.snapshotLength) { | |
| replace_on_mouseup(nodeSnapshots); | |
| } | |
| const observer = new MutationObserver(function (MutationRecords) { | |
| MutationRecords.forEach(function (Record) { | |
| Record.addedNodes.forEach(function (node) { | |
| if (node.nodeType === node.ELEMENT_NODE && node.tagName === "DIV") { | |
| const nodeSnapshots = document.evaluate('.' + a_xpath, node, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); // .== self::node() | |
| replace_on_mouseup(nodeSnapshots); | |
| } | |
| }); | |
| }); | |
| }); | |
| observer.observe(obs_target, { | |
| subtree: true, | |
| childList: true | |
| }); | |
| }, false); | |
| })(); |
tomato111
commented
Feb 19, 2018

ReplaceURLs(GoogleImages) 0.0.7 does not work. Firefox 77.0b9 x64, Microsoft Windows 10.0.18363.836, Tampermonkey 4.10.6112.
Um… working fine on Tampermonkey 4.10.6112.
If it is working properly, middle-click on the image to open the original image.
Sorry I couldn't help.
If it is working properly, middle-click on the image to open the original image.
Middle-click [1] - the webpage [2] still opens. Instead http://img1.reactor.cc/pics/post/full/Санкт-Петербург-погода-Ведьмак-(The-Witcher)-фэндомы-4241887.jpeg
[1] https://www.google.com/search?as_st=y&tbm=isch&hl=en&as_q=ведьмак болото&as_epq=&as_oq=&as_eq=&cr=&as_sitesearch=&safe=images&tbs=isz:lt,islt:2mp#imgrc=TVyonUsCBECrgM
[2] http://reactor.cc/post/3357630
Firefox 78.0b2 (64-bit).
Now I understand how this script works. Yes, thanks, everything is fine (Mozilla Firefox 79.0b4 (64-bit), Tampermonkey 4.11.6114).
