w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Greasemonkey script: get matched include rule

Greasemonkey does not tell a script which rule it matched. Instead, your script can test properties of the window.location object. EG:

if (/stackoverflow.com/i.test (location.hostname) ) {
    alert ("Yay!");
else if (/quora.com/i.test (location.hostname) ) {
    alert ("Uh oh!");

If you really wanted to, you could loop through the includes and matches arrays of the GM_info object, and try to determine which one(s) would fire on the current location, but that's not foolproof and there's zero need for it (except, maybe, an over-zealous code review of the script).

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.