hoothin / UserScripts

Greasemonkey scripts ( Pagetual / Picviewer CE+ / DownloadAllContent ) 油猴腳本集 ユーザースクリプト集
https://greasyfork.org/users/8227-hoothin
3.03k stars 510 forks source link

I want this on Google image search, but not any other part of Google #594

Open FailSafeNow opened 4 months ago

FailSafeNow commented 4 months ago

Here is an example URL: https://www.google.com/search?q=image&udm=2

There is a very big problem. I only want to enable this for Google image search. I don't want to enable it for regular Google searches or any other kind of Google searches. Just image searches, and nothing else. And I can't do that. I can enable the script for all of Google, or disable it for all of Google, but restricting the script to only certain URLs can't be done.

I tried this: [{ "name": "Google Search", "nextLink": [ "id('pnnext')|id('navbar navcnt nav')//td[span]/following-sibling::td[1]/a|id('nn')/parent::a", "id('pnprev')|id('navbar navcnt nav')//td[span]/following-sibling::td[1]/a|id('nn')/parent::a" ], "pageElement": "id('rso')|id('center_col')/style[contains(.,'relative')][id('rso')]|id('search')/div/div/style[1]", "action": 1, "pageNum": "&start={10($p-1)}", "pageBarTop": 55, "url": "^https?://[^./]+\.google(?:\.[^./]{2,3}){1,2}/(?:c(?:se|ustom)|search|webhp|m|#)(?:\?.\budm=2\b.*)?$", "replaceElement": "[role='navigation']>[role='presentation']", "css": "ol>li{display: inline-flex;}" }]

And then I tried this:

[ { "name": "Google Search", "nextLink": [ "id('pnnext')|id('navbar navcnt nav')//td[span]/following-sibling::td[1]/a|id('nn')/parent::a", "id('pnprev')|id('navbar navcnt nav')//td[span]/following-sibling::td[1]/a|id('nn')/parent::a" ], "pageElement": "id('rso')|id('center_col')/style[contains(.,'relative')][id('rso')]|id('search')/div/div/style[1]", "action": 1, "pageNum": "&start={10($p-1)}", "pageBarTop": 55, "url": "^https?://[^./]+\.google(?:\.[^./]{2,3}){1,2}/(?:c(?:se|ustom)|search|webhp|m|#)(?:\?.\budm=2(?:&|$).*)?$", "replaceElement": "[role='navigation']>[role='presentation']", "css": "ol>li{display: inline-flex;}" } ]

The process for making rules is impossibly complex. I should be able to simply set rules that say "Work on this URL"/"Don't work on this URL". The advertising on GreasyFork that says "You can also configure your own rules for any site on config page easily." is false. It isn't easy. It's impossible. And if I spend another second on the rules page, I'll have a stroke. This is one of the most frustrating processes I've ever encountered.

skofkyo commented 4 months ago

RegExp for JSON string

\ to \\
\? to \\?
hoothin commented 4 months ago

To ensure performance, the url will be truncated to the first 500 characters for comparison. As a result, 'udm=2' will be discarded. So don't use url to limit it, use include and exclude instead. For example:

{
    "name": "Google disable",
    "url":  "^https://(?:www\\.)?google\\..*/search",
    "exclude": "[data-id=mosaic]",
    "enable": 0
}

It means that all sites without an element with the attribute "[data-id=mosaic]" inside will be disabled.