Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tampermonkey ignores @exclude

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.

like image 664
alexandresaiz Avatar asked Sep 16 '14 09:09

alexandresaiz


People also ask

What script language does Tampermonkey use?

Tampermonkey is a donationware userscript manager that is available as a browser extension. This software enables the user to add and use userscripts, which are JavaScript programs that can be used to modify web pages.

Why do people use Tampermonkey?

Tampermonkey is a browser extension that allows you to manage user scripts to modify and alter webpages.


1 Answers

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

  • arduino.stackexchange.com/tags/
    or
  • arduino.stackexchange.com/tags?foo=bar

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.

like image 124
Brock Adams Avatar answered Sep 28 '22 03:09

Brock Adams