Last active
December 23, 2024 13:30
-
-
Save tomato111/681d634ded1a9bd3107e2baf60460a35 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==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); | |
| })(); |
Author
Now I understand how this script works. Yes, thanks, everything is fine (Mozilla Firefox 79.0b4 (64-bit), Tampermonkey 4.11.6114).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

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).