I am making a javascript greasemonkey script that redirects you when it finds a certain string in a webpage. Here is my code:
// ==UserScript==<br>
// @name No 009 Sound System!<br>
// @version 1.0<br>
// @namespace http://www.cakeman.biz/<br>
// @description Warn user when about to view a youtube video with 009 Sound System audio<br>
// @include http://*/*<br>
// @copyright 2011+, Zack Marotta
// ==/UserScript==
var result, search_term = 'somerandomsearchterm';
var str = document.URL;
var url_check = str.search(search_term);
if (url_check !== -1) {
var result = search_term;
alert(str);
window.location = "http://www.web.site";
}
Nothing happens when the script runs. What did I do wrong?
For some specific functions, you have to use
unsafeWindowinstead ofwindowin a Greasemonkey UserScript. If you want to get your script work at GreaseMonkey and other locations, use this:I’ve shrinkened by original answer, because that seems not to be your issue. Most likely, you’ve forgot to add
// @includeto your meta block.If your script has to redirect a certain, fixed page using GreaseMonkey, you can also shorten your scrip to:
For more information about the meta block, see: http://wiki.greasespot.net/Metadata_block