I am trying to learn some javascript at the moment and thought a simple greasemonkey script might be a good way to start.
What I want the script to do is to replace an existing url on a website with a different url from another location within the website.
E.G. replace “/mailbox.php?inbox” with “/account.php?action=mybookmarks”
There are a lot of examples of replacing existing urls with different ones on the web but they all use id’s to locate and replace urls.
This script is for a site I visit often and since I dont own it I dont have the ability to add id tags to the appropriate a tags, this makes writing this script a lot more difficult.
This is the code I have so far;
// ==UserScript==
// @name NZBmatrix mailbox url replace
// @include http://nzbmatrix.com/
// @description replace "/mailbox.php?inbox" with "/account.php?action=mybookmarks"
// ==/UserScript==
function urlreplace()
{
var allLinks = document.links;
if (allLinks != null)
{
for (i = 0; i <allLinks.length; ++i)
{
if (allLinks [i].href.indexOf ("/mailbox.php?inbox") > 0)
{
allLinks [i].href = allLinks [i].href.replace ("/account.php?action=mybookmarks");
}
}
}
};
any help or tips would be much appreciated