From 54697d7a8d08e1684655451855e1b7d0a0a1f67d Mon Sep 17 00:00:00 2001 From: "f.strw" Date: Fri, 17 May 2024 10:15:54 +0300 Subject: [PATCH] v.1.01 - Thanks Google, very cool! - basically a full fucking rewrite because of another Google Image search minor design change no one asked for. --- script.user.js | 56 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 44 insertions(+), 12 deletions(-) diff --git a/script.user.js b/script.user.js index 4ba9244..c5218c7 100644 --- a/script.user.js +++ b/script.user.js @@ -1,27 +1,59 @@ // ==UserScript== // @name Google Images filter // @namespace https://fem.mint.lgbt/f.strw -// @version v1 +// @version v1.01 // @description Block certain websites from appearing on Google Images search result. // @author f.strw -// @include * +// @include * // @grant none // ==/UserScript== (function() { 'use strict'; - if (window.location.search.indexOf('&tbm=isch') > -1) { - var blockedDomains = ["redbubble.com", "etsy.com", "amazon.com", "amazon.de", "aliexpress.com", "teepublic.com", "badgeland.com", "ebay.com"]; - var links = document.getElementsByTagName("a"); - for (var i = 0; i < links.length; i++) { - for (var j = 0; j < blockedDomains.length; j++) { - if (links[i].href.indexOf(blockedDomains[j]) !== -1) { - var parentDiv = links[i].closest("div"); - if (parentDiv) { - parentDiv.remove(); + + function isButtonSelected(btnName) { + var buttons = document.querySelectorAll('div[jsname="bVqjv"]'); + + for (let btn of buttons) { + if (btn.hasAttribute('selected')) { + var btnText = btn.getElementsByTagName('span'); + for (let text of btnText) { + if (text.textContent == btnName) { + return true; } } } } - } + + return false; + } + + function removeImages() { + if (isButtonSelected("Images")) { + var blockedDomains = ["redbubble.com", "etsy.com", "amazon.com", "amazon.de", "amazon.sg", "aliexpress.com", "teepublic.com", "badgeland.com", "ebay.com"]; + var links = document.getElementsByTagName("a"); + for (var i = 0; i < links.length; i++) { + for (var j = 0; j < blockedDomains.length; j++) { + if (links[i].href.indexOf(blockedDomains[j]) !== -1) { + var parentDiv = links[i].closest("div"); + if (parentDiv && parentDiv.parentElement && parentDiv.parentElement) { + var grampsDiv = parentDiv.parentElement; + grampsDiv.remove(); + } + } + } + } + } + } + + function run() { + if (document.readyState === "complete" || document.readyState === "interactive") { + removeImages(); + } + else { + setTimeout(run, 100); + } + } + + run(); })(); \ No newline at end of file