title: Script to modify a URL in greasemonkey
body: <p>I'm trying to change the following url:</p>
  
  <pre><code>http://www.example.net/?image=full&amp;action=view&amp;imageid=1361 
  </code></pre>
  
  <p>into</p>
  
  <pre><code>http://www.anothersite.com/download&amp;id=1361&amp;thumb=0
  </code></pre>
  
  <p>while preserving the id (<code>1361</code> in the example)</p>
  
  <p>(change 'example.net/?image=full&amp;action=view&amp;image' to 'anothersite.com/download&amp;' and add '&amp;thumb=0' at the end of the url)</p>
  
  <p>How do I write a GreaseMonkey script for that?</p>
  
  <hr>
  
  <p>ps. I've already googled it and copied the code below. It's working, but the problem is it adds '&amp;thumb=0' to the other link too (not just the 'replaced' link(s))</p>
  
  <pre><code>// ==UserScript==
  // @name        whatever
  // @namespace   lii
  // @description redirect to anothersite
  // @include     http://www.example.net/?image=full&amp;action=view*
  // @version     1
  // @grant       none
  // ==/UserScript==
  
  var links,thisLink;
  links = document.evaluate("//a[@href]",
      document,
      null,
      XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
      null);
  
  for (var i=0;i&lt;links.snapshotLength;i++) {
      var thisLink = links.snapshotItem(i);
  
      thisLink.href = thisLink.href.replace('http://www.example.net/?image=full&amp;action=view&amp;image',
                                            'http://www.anothersite.com/download&amp;')  + "&amp;thumb=0";
  
  }
  </code></pre>