Last active
May 25, 2020 11:54
-
-
Save mistificator/53bb7f6afc41d1a8830707d06927c5bc 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 Google Hacked Pic | |
// @namespace http://www.google.*/ | |
// @include http://www.google.*/search?*tbm=isch* | |
// @include https://www.google.*/search?*tbm=isch* | |
// @include http://www.google.*/imgres?*imgurl=* | |
// @include https://www.google.*/imgres?*imgurl=* | |
// @version 0.2.1 | |
// @description Click left mouse button on image. Use Download and Copy Link buttons. Kek. | |
// @author Mist Poryvaev | |
// @grant none | |
// ==/UserScript== | |
var save_buttons = [], clipboard_buttons = []; | |
function makeSaveButton(tr) | |
{ | |
var td = tr.firstChild.cloneNode(true); | |
var a = td.firstChild; | |
a.removeAttribute("class"); | |
a.removeAttribute("jsaction"); | |
a.removeAttribute("ping"); | |
a.removeAttribute("href"); | |
a.setAttribute("id", "save_button"); | |
a.childNodes[1].textContent = "Скачать"; | |
save_buttons.push(a); | |
var path = a.childNodes[0].firstChild.firstChild; | |
path.setAttribute("d", "M 12 19 L 4 19 L 4 21 L 20 21 L 20 19 L 12 19 L 12 19 L 20 10 L 16 10 L 16 3 L 8 3 L 8 10 L 4 10 L 12 19 L 12 19 L 12 19"); | |
tr.insertBefore(td, tr.firstChild); | |
} | |
function makeLinkButton(tr) | |
{ | |
var td = tr.firstChild; | |
while (td) | |
{ | |
var a = td.firstChild; | |
if (a.childNodes[1] && a.childNodes[1].textContent == "Отправить") | |
{ | |
a.childNodes[1].textContent = "Копировать ссылку"; | |
a.removeAttribute("jsaction"); | |
clipboard_buttons.push(a); | |
return; | |
} | |
td = td.nextSibling; | |
} | |
} | |
function addSaveButton() | |
{ | |
var panels = Array.prototype.slice.call(document.getElementsByClassName("irc_but_r")); | |
for (var i = 0; i < panels.length; i++) | |
{ | |
var tr = panels[i].firstChild.firstChild; | |
makeSaveButton(tr); | |
makeLinkButton(tr); | |
} | |
} | |
function updateSaveButton() | |
{ | |
var images = Array.prototype.slice.call(document.getElementsByClassName("irc_mi")); | |
for (var i = 0; i < images.length; i++) | |
{ | |
var a = images[i].parentNode; | |
if (a.tagName.toUpperCase() == "A" && a.getAttribute("class") > "irc_mil") | |
{ | |
var src = images[i].getAttribute("src"); | |
if (src) | |
{ | |
a.setAttribute("href", src); | |
if (save_buttons[i]) | |
{ | |
save_buttons[i].setAttribute("href", src); | |
save_buttons[i].setAttribute("download", src); | |
} | |
if (clipboard_buttons[i]) | |
{ | |
clipboard_buttons[i].setAttribute("onclick", | |
"document.addEventListener('copy', function(e){e.clipboardData.setData('text/plain', '" + src + "'); e.preventDefault();}); document.execCommand('copy');"); | |
} | |
} | |
} | |
} | |
} | |
var prev_length1 = 0; | |
var timerId1 = setInterval(function() | |
{ | |
var length = document.getElementsByClassName("irc_but_r").length; | |
if(length == prev_length1 && prev_length1 > 0) | |
{ | |
addSaveButton(); | |
clearInterval(timerId1); | |
} | |
prev_length1 = length; | |
}, 10); | |
var prev_length2 = 0; | |
var timerId2 = setInterval(function() | |
{ | |
var length = document.getElementsByClassName("irc_mi").length; | |
if(length == prev_length2 && prev_length2 > 0) | |
{ | |
updateSaveButton(); | |
// clearInterval(timerId2); | |
} | |
prev_length2 = length; | |
}, 10); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The script is not recognized as a userscript. Firefox 77.0b9 x64, Microsoft Windows 10.0.18363.836, Tampermonkey 4.10.6112.