13
votes

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.

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 includesKat Cox
@KatCox doesn't work :-(alexandresaiz

2 Answers

13
votes

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

0
votes

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