Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I restrict chrome greasemonkey scripts to a single webpage, or just certain webpages?

Is there a way to prevent chrome from running greasemonkey scripts except for on certain domains? I could do some hackery with location.href, but it would be nice if there were a cleaner solution.

When I install by dragger script.user.js into the browser, the script automatically runs for all websites.

How do I prevent this?

like image 319
Stefan Kendall Avatar asked Jun 16 '11 14:06

Stefan Kendall


People also ask

Is Tampermonkey and Greasemonkey same?

Tampermonkey is used to run so-called userscripts (sometimes also called Greasemonkey scripts) on websites. Userscripts are small computer programs that change the layout of a page, add or remove new functionality and content, or automate actions.

What does Tamper monkey do?

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.

What is Greasemonkey Chrome?

Greasemonkey is a userscript manager made available as a Mozilla Firefox extension. It enables users to install scripts that make on-the-fly changes to web page content after or before the page is loaded in the browser (also known as augmented browsing).

Do Tampermonkey scripts work on Greasemonkey?

They are not exclusive for Tampermonkey users and the codes you find will work on any user script managers, including Greasemonkey.


2 Answers

Use @match, as described here.

Example:

// ==UserScript==
// @match http://*/*
// @match http://*.google.com/*
// @match http://www.google.com/*
// @match https://www.google.com/*
// ==/UserScript==
like image 58
Stefan Kendall Avatar answered Oct 14 '22 20:10

Stefan Kendall


using @include @exclude tags in metadata? http://diveintogreasemonkey.org/helloworld/metadata.html https://wiki.greasespot.net/Metadata_Block

like image 4
Satish Avatar answered Oct 14 '22 19:10

Satish