Tampermonkey ignores @exclude
Asked Answered
P

3

16

I'm working on the translation of the dashboard/admin of Shopify using Tampermonkey.

For security purposes, there's some parts of the Shopify Admin Dashboard I don't want Tampermonkey to work with. There's text created by the merchant (in products, pages, collections, templates...) which Tampermonkey would replace which is really dangerous.

There's 2 approaches to solve this:

  1. "Instruct" Tampermonkey not to translate the content inside forms. (which seems to be the best approach)
  2. Use the @exclude directive.

I've used the latter but the script is not listening to @exclude. Here is the userscript:

// ==UserScript==
// @name       Shopify_Admin_Spanish
// @namespace  http://*.myshopify.com/admin
// @version    0.1
// @description  Tu tienda Shopify, por detrás, en español!
// @exclude    https://*.myshopify.com/admin/products
// @exclude    https://*.myshopify.com/admin/collections
// @exclude    https://*.myshopify.com/admin/blogs
// @exclude    https://*.myshopify.com/admin/pages
// @exclude    https://*.myshopify.com/admin/themes
// @match      https://*.myshopify.com/*
// @copyright  microapps.com
// ==/UserScript==

PS. I did all checks using Google Chrome, and am not willing to use any other browser.

Pinckney answered 16/9, 2014 at 9:12 Comment(2)
You can try adding '/' at the end of the excludes... I had to do that on greasemonkey before it would recognize some of my includesKlaxon
@KatCox doesn't work :-(Pinckney
A
18

@exclude is very precise. You need to put a trailing asterisk on each of the exclude lines. EG:

// @exclude    https://*.myshopify.com/admin/products*
// @exclude    https://*.myshopify.com/admin/collections*
// @exclude    https://*.myshopify.com/admin/blogs*
// @exclude    https://*.myshopify.com/admin/pages*
// @exclude    https://*.myshopify.com/admin/themes*

Consider (and install) this Tampermonkey script:

// ==UserScript==
// @name     _match and exclude testing
// @match    http://*.stackexchange.com/*
//
// @exclude  http://*.stackexchange.com/questions*
// @exclude  http://*.stackexchange.com/tags
// @require  http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// @grant    GM_addStyle
// ==/UserScript==

$("body").prepend ('<h1 style="background: yellow;">Match Script fired on this page.</h1>');

If you then visit arduino.stackexchange.com/tags, the script won't fire, but when visiting:

it will!

Changing the second exclude line to:

// @exclude  http://*.stackexchange.com/tags*

fixes the problem.


If you still have difficulty, specify your versions of Chrome, Tampermonkey, and operating system. And, provide target page(s) that demonstrate the problem.

Aquanaut answered 24/10, 2014 at 7:33 Comment(0)
R
0

For those that still struggle with this. I could see the script being enabled on a page (without actually checking its effects), just by looking at the extension icon and seeing the number badge (of active scripts). Open the dropdown, then click on the arrow next to the active script. It can turn out you have a payment provider embedded iframe in the page and the script is acting on that (correctly, as the exclude is not affecting it). The extension icon, and the dropdown list does not differentiate between different domains on a given page.

enter image description here

Rancho answered 8/5, 2022 at 8:10 Comment(0)
R
0

what always trips me up with @exclude in Tampermonkey:

@match *://*.somewebsite.com works well enough even when the website's window.location.href reports without a subdomain, like https://somewebsite.com.

but @exclude *://*.somewebsite.com/* does NOT recognize it. I would have to modify the @exclude to remove the subdomain as well, like @exclude *://somewebsite.com/*. only then does Tampermonkey realize that the script shouldn't actually run.

Roybal answered 6/7, 2023 at 21:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.