Troubleshooting (Script Authors): Difference between revisions

From GreaseSpot Wiki
Jump to navigationJump to search
No edit summary
(Update for 4.0)
 
(40 intermediate revisions by 14 users not shown)
Line 1: Line 1:
[http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30356 free cool ringtones] [http://wc1.worldcrossing.com/WebX/.1de609f0 lorazepam online] [http://news.engin.brown.edu/forums/thread-view.asp?tid=187 cheap celexa] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30230 tramadol online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=211 free polyphonic ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=214 zanaflex online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=110 free nokia ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=189 cheap ortho] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=237 free samsung ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=151 soma online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=99 lorazepam online] [http://students.hsc.unt.edu/housing/item.cfm?type=2912 free sagem ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2907 free sprint ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a17 lipitor online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30334 free mp3 ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=234 sprint ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=141 buy vigrx] [http://wc1.worldcrossing.com/WebX/.1de60a23 free polyphonic ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a1f cheap lisinopril] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=197 free mp3 ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1349 order viagra] [http://library.cshl.edu/wp/vb/member.php?u=1382 cingular ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30310 tenuate online] [http://students.hsc.unt.edu/housing/item.cfm?type=2922 kyocera ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=206 free qwest ringtones] [http://wc1.worldcrossing.com/WebX/.1de609f9 norco online] [http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=351 buy clonazepam] [http://students.hsc.unt.edu/housing/item.cfm?type=2878 cheap sildenafil] [http://students.hsc.unt.edu/housing/item.cfm?type=2902 free nextel ringtones] [http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=357 free funny ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1347 cheap cialis] [http://library.cshl.edu/wp/vb/member.php?u=1365 ultracet online] [http://news.engin.brown.edu/forums/thread-view.asp?tid=210 sprint ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=158 cheap diazepam] [http://wc1.worldcrossing.com/WebX/.1de609ea free free ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a25 free samsung ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=88 free ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1358 cheap hydrocodone] [http://library.cshl.edu/wp/vb/member.php?u=1339 tramadol online] [http://students.hsc.unt.edu/housing/item.cfm?type=2868 cheap ambien] [http://news.engin.brown.edu/forums/thread-view.asp?tid=228 free mtv ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=104 free motorola ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=89 free funny ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=211 music ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=80 cool ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1388 fioricet online] [http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=361 free real ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=172 lorazepam] [http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=333 cheap soma] [http://news.engin.brown.edu/forums/thread-view.asp?tid=182 cheap clomid] [http://library.cshl.edu/wp/vb/member.php?u=1355 clonazepam] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=205 cheap paxil] [http://news.engin.brown.edu/forums/thread-view.asp?tid=184 lisinopril online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=124 samsung ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a04 sonyericsson ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=115 phentermine online] [http://library.cshl.edu/wp/vb/member.php?u=1387 free alltel ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a05 sprint ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=167 clonazepam online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30283 didrex online] [http://news.engin.brown.edu/forums/thread-view.asp?tid=157 ultram online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=230 verizon ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30309 celexa online] [http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=348 cheap norco] [http://wc1.worldcrossing.com/WebX/.1de60a11 buy diethylpropion] [http://news.engin.brown.edu/forums/thread-view.asp?tid=188 tenuate online] [http://news.engin.brown.edu/forums/thread-view.asp?tid=212 free verizon ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30308 cheap lipitor] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=82 buy diazepam] [http://library.cshl.edu/wp/vb/member.php?u=1380 verizon ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=163 adipex online] [http://students.hsc.unt.edu/housing/item.cfm?type=2859 cheap meridia] [http://news.engin.brown.edu/forums/thread-view.asp?tid=209 samsung ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=170 cingular ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=78 clomid] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30298 order lisinopril] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=74 cheap carisoprodol] [http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=352 paxil online] [http://news.engin.brown.edu/forums/thread-view.asp?tid=227 ericsson ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1386 free mono ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=69 cheap albuterol] [http://wc1.worldcrossing.com/WebX/.1de60a12 ericsson ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=171 cheap ambien] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=188 levitra online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=83 cheap didrex] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30358 midi ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2879 cheap clomid] [http://news.engin.brown.edu/forums/thread-view.asp?tid=186 cheap lipitor] [http://news.engin.brown.edu/forums/thread-view.asp?tid=215 sagem ringtones] [http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=346 meridia online] [http://students.hsc.unt.edu/housing/item.cfm?type=2923 free sony ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30237 cheap valium] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=171 cheap clomid] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=184 hoodia online] [http://wc1.worldcrossing.com/WebX/.1de60a1b free music ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30264 cheap hydrocodone] [http://wc1.worldcrossing.com/WebX/.1de609db cheap adipex] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30321 hgh online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=90 hgh online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30263 levitra online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=133 tracfone ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=226 free sony ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=117 propecia online] [http://news.engin.brown.edu/forums/thread-view.asp?tid=165 cheap vicodin] [http://library.cshl.edu/wp/vb/member.php?u=1340 soma online] [http://students.hsc.unt.edu/housing/item.cfm?type=2909 free verizon ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30252 buy meridia] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=221 cheap vicodin] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30347 verizon ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1354 alprazolam online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30330 free nokia ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2903 free qwest ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a26 free sharp ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30348 polyphonic ringtones] [http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=345 cheap viagra] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=239 sildenafil online] [http://students.hsc.unt.edu/housing/item.cfm?type=2876 buy didrex] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=142 wellbutrin] [http://students.hsc.unt.edu/housing/item.cfm?type=2872 cyclobenzaprine] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30333 free funny ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a00 cheap rivotril] [http://library.cshl.edu/wp/vb/member.php?u=1356 paxil online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30357 free sharp ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=123 free sagem ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30268 order xenical] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=92 cheap hydrocodone] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=100 cheap lortab] [http://students.hsc.unt.edu/housing/item.cfm?type=2850 cheap phentermine] [http://students.hsc.unt.edu/housing/item.cfm?type=2869 cheap lorazepam] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=116 free polyphonic ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1361 xenical online] [http://library.cshl.edu/wp/vb/member.php?u=1362 wellbutrin online] [http://wc1.worldcrossing.com/WebX/.1de60a2b but ultracet] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=113 cheap paxil] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30279 cheap ultracet] [http://news.engin.brown.edu/forums/thread-view.asp?tid=229 free jazz ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2863 buy alprazolam] [http://wc1.worldcrossing.com/WebX/.1de609f4 mono ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1353 vicodin] [http://students.hsc.unt.edu/housing/item.cfm?type=2880 cheap albuterol] [http://wc1.worldcrossing.com/WebX/.1de609eb funny ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=181 free ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2887 cheap pharmacy online] [http://library.cshl.edu/wp/vb/member.php?u=1364 cheap nexium] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=222 cheap vigrx] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=166 buy ativan] [http://library.cshl.edu/wp/vb/member.php?u=1381 free polyphonic ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=180 flexeril] [http://wc1.worldcrossing.com/WebX/.1de609fd free punk ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=102 midi ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a2c ultram] [http://students.hsc.unt.edu/housing/item.cfm?type=2853 cheap fioricet] [http://students.hsc.unt.edu/housing/item.cfm?type=2899 free tracfone ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=185 hydrocodone online] [http://library.cshl.edu/wp/vb/member.php?u=1378 sprint ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1350 order meridia] [http://news.engin.brown.edu/forums/thread-view.asp?tid=152 valium online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=208 cheap phentermine] [http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=349 cheap vicodin] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=77 free cingular ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a0c wellbutrin online] [http://students.hsc.unt.edu/housing/item.cfm?type=2860 cheap adipex] [http://news.engin.brown.edu/forums/thread-view.asp?tid=223 midi ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=126 cheap sildenafil] [http://library.cshl.edu/wp/vb/member.php?u=1383 sagem ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=197 cheap flexeril] [http://students.hsc.unt.edu/housing/item.cfm?type=2898 free free ringtones] [http://wc1.worldcrossing.com/WebX/.1de609ff real ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30336 free qwest ringtones] [http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=343 cialis] [http://students.hsc.unt.edu/housing/item.cfm?type=2924 ericsson ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=183 albuterol online] [http://library.cshl.edu/wp/vb/member.php?u=1342 cheap phentermine] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=220 free real ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2883 cheap lipitor] [http://news.engin.brown.edu/forums/thread-view.asp?tid=203 funny ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=73 cheap ativan] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=218 free qwest ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=202 free tracfone ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=96 levitra online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=105 free mp3 ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1375 free real ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30238 phentermine online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30355 punk ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30349 cingular ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=199 music ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2914 sony ericsson ringtones] [http://wc1.worldcrossing.com/WebX/.1de609e7 diazepam online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30315 buy lortab] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=143 wwe ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2906 free samsung ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=174 order cyclobenzaprine] [http://wc1.worldcrossing.com/WebX/.1de60a03 free sony ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2857 cheap ativan] [http://wc1.worldcrossing.com/WebX/.1de60a2d valium online] [http://students.hsc.unt.edu/housing/item.cfm?type=2856 cheap cialis] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30242 fioricet online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=160 adipex online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=232 sony ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2900 funny ringtones] The article [http://www.oreillynet.com/pub/a/network/2005/11/01/avoid-common-greasemonkey-pitfalls.html Avoid Common Pitfalls in Greasemonkey] covers some of the most common problems people come across when writing [[user script]]s.
If your problem is not listed, try [[Getting Help]].
 
If your problem is not listed, please ask on the [[mailing list]].


__TOC__
__TOC__


== Changes don't take effect when editing a script ==
== Variables change before a GM_xmlhttpRequest or setTimeout callback runs ==


You may be editing your original copy of the script, not the installed copy.
Problem example:
Once you create and install a script, you need to follow [[FAQ#How_do_I_edit_a_script_I.27m_working_on.3F|these steps]] to make sure you're editing the installed, active copy.


Also, changing the [[include and exclude rules]] in the [[metadata block]] of the installed script does not do anything, as the script metadata is only accessed during installation. The script must be re-installed (or [[config.xml]] edited manually) for these changes to take.
<pre class='sample-bad'>
for (var i = document.links.length - 1; i >= 0; --i) {
  var link = document.links[i];
 
  GM.xmlHttpRequest({
    method: "GET",
    url: "http://example.com/lookup?url=" + link.href,
    onload: function(result) {
      link.href = result.responseText;
    }
  });
}</pre>


Note: You can change the [[include and exclude rules]] in the Manage User Scripts window and those changes will take effect.
The request is asynchronous, meaning the rest of the code doesn't wait for it to complete. The <code>for</code> keeps running as the request loads. When the request for the first link on the page completes and the <code>onload</code> callback function runs, the <code>link</code> variable might point to a different link altogether, typically the last one (since the <code>for</code> loop completes much quicker than the HTTP requests).


== Variables change before a GM_xmlhttpRequest or setTimeout callback runs ==
One solution is to pass those values that you want unchanged into a function surrounding the request, as arguments. Then they will be in a different scope, and will no longer be changed from the outside.
 
Solution example with named function:
<pre class='sample-good'>
function do_it(link_inside) {
  GM_xmlhttpRequest({
    method: "GET",
    url: "http://example.com/lookup?url=" + link_inside.href,
    onload: function(result) {
      link_inside.href = result.responseText;
    }
  });
}
 
for (var i = document.links.length - 1; i >= 0; --i) {
  var link = document.links[i];
  do_it(link);
}
</pre>


Problem example:
Solution example with anonymous function:


  for (var i=0; i < document.links.length; i ) {
<pre class='sample-good'>
    var link = document.links[i];
for (var i = document.links.length - 1; i >= 0; --i) {
  var link = document.links[i];
    
    
  (function (link_inside) {
     GM_xmlhttpRequest({
     GM_xmlhttpRequest({
       method: "GET",
       method: "GET",
       url: '
       url: "http://example.com/lookup?url=" + link_inside.href,
      onload: function(result) {
        link_inside.href = result.responseText;
      }
    }); 
  })(link);
}
</pre>
 
Solution example with iteration in the "onload" function. Note that this processes each element one by one.
 
<pre class='sample-good'>
(function getNext(i) {
  var link = document.links[i];
  GM_xmlhttpRequest({
    method: "GET",
    url: "http://example.com/lookup?url=" + link.href,
    onload: function(result) {
      link.href = result.responseText;
      if (--i >= 0) {
        getNext(i);
      }
    }
  });
})(document.links.length - 1);
</pre>
 
== Form POST data ==
 
When using [[GM.xmlHttpRequest]] to POST form data, remember to add the '''Content-Type''' parameter:
 
<pre class='sample-good'>
GM_xmlhttpRequest({
  method: "POST",
  url: myurl,
  headers: {
    "Content-Type": "application/x-www-form-urlencoded"
  },
  data: mydata,
  onload: function(res) { /* Some code */ }
});
</pre>
 
== Character set ==
 
Various issues can arise when working in the wrong character set. In general, writers are advised to use the standard utf-8 format, which isn't supported in the latest version of Windows Notepad. Other workarounds include using JavaScript to parse characters which would otherwise be invalid in other formats, from integer values.
 
<pre class='sample-good'>
var values = [72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33];
alert(String.fromCharCode.apply(String, values));
</pre>
 
<!-- 4.0 + files = fail
== Installing from /tmp ==
 
If you try to install a user script located in the /tmp directory, Greasemonkey will not bring up the install dialog, and the Install button at the top of the page will not do anything.  To solve this, simply move the .user.js file to another directory, such as your home directory.
-->

Latest revision as of 16:20, 3 November 2017

If your problem is not listed, try Getting Help.

Variables change before a GM_xmlhttpRequest or setTimeout callback runs

Problem example:

for (var i = document.links.length - 1; i >= 0; --i) {
  var link = document.links[i];
  
  GM.xmlHttpRequest({
    method: "GET",
    url: "http://example.com/lookup?url=" + link.href,
    onload: function(result) {
      link.href = result.responseText;
    }
  });
}

The request is asynchronous, meaning the rest of the code doesn't wait for it to complete. The for keeps running as the request loads. When the request for the first link on the page completes and the onload callback function runs, the link variable might point to a different link altogether, typically the last one (since the for loop completes much quicker than the HTTP requests).

One solution is to pass those values that you want unchanged into a function surrounding the request, as arguments. Then they will be in a different scope, and will no longer be changed from the outside.

Solution example with named function:

function do_it(link_inside) {
  GM_xmlhttpRequest({
    method: "GET",
    url: "http://example.com/lookup?url=" + link_inside.href,
    onload: function(result) {
      link_inside.href = result.responseText;
    }
  });
}
  
for (var i = document.links.length - 1; i >= 0; --i) {
  var link = document.links[i];
  do_it(link);
}

Solution example with anonymous function:

for (var i = document.links.length - 1; i >= 0; --i) {
  var link = document.links[i];
  
  (function (link_inside) {
    GM_xmlhttpRequest({
      method: "GET",
      url: "http://example.com/lookup?url=" + link_inside.href,
      onload: function(result) {
        link_inside.href = result.responseText;
      }
    });  
  })(link);
}

Solution example with iteration in the "onload" function. Note that this processes each element one by one.

(function getNext(i) {
  var link = document.links[i];
  GM_xmlhttpRequest({
    method: "GET",
    url: "http://example.com/lookup?url=" + link.href,
    onload: function(result) {
      link.href = result.responseText;
      if (--i >= 0) {
        getNext(i);
      }
    }
  });
})(document.links.length - 1);

Form POST data

When using GM.xmlHttpRequest to POST form data, remember to add the Content-Type parameter:

GM_xmlhttpRequest({
  method: "POST",
  url: myurl,
  headers: {
    "Content-Type": "application/x-www-form-urlencoded"
  },
  data: mydata,
  onload: function(res) { /* Some code */ }
});

Character set

Various issues can arise when working in the wrong character set. In general, writers are advised to use the standard utf-8 format, which isn't supported in the latest version of Windows Notepad. Other workarounds include using JavaScript to parse characters which would otherwise be invalid in other formats, from integer values.

var values = [72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33];
alert(String.fromCharCode.apply(String, values));