Another Auto Update Script

By sizzlemctwizzle Last update Sep 22, 2009 — Installed 9,974 times. Daily Installs: 13, 7, 6, 13, 11, 13, 10, 12, 12, 5, 12, 20, 6, 9, 9, 6, 11, 13, 9, 11, 9, 8, 8, 8, 25, 8, 11, 4, 11, 7, 8
Script Summary:
Include the code in your user scripts so they check for updates automatically
Version: 1.1.9
Review Summary
5 stars
5 reviews (5)
4 stars
0 reviews (0)
3 stars
0 reviews (0)
2 stars
0 reviews (0)
1 star
0 reviews (0)

this script has 5 reviews


Attention: My updater can now be used via an @require. Instructions can be found here.




Below are instructions on using my old updater that you must manually copy into your script

What does it do?

This script does nothing but keep itself up-to-date. You must include this code in any script that you want to auto update. Just modify the first couple lines according to your script. The code is self-contained so there should be no conflict with the variable names used by your script.

How to use?

  1. Surround your Userscript meta header like this:
    scr_meta=<><![CDATA[ // Make sure to copy this line right above the script metadata
    // ==UserScript==
    // @name           Another Auto Update Script
    // @namespace      sizzlemctwizzle
    // @description    Include the code in your user scripts so they check for updates automatically
    // @version        1.1.7
    // @include        *
    // ==/UserScript==
    ]]></>.toString(); // Make sure to copy this line right below
  2. Somewhere in your script(probably at the bottom) paste this code:
    CheckScriptForUpdate = {
      // Config values, change these to match your script
     id: '38017', // Script id on Userscripts.org
     days: 2, // Days to wait between update checks
  3. Change the id value to the id of your script on Userscripts.org
  4. Either keep the days value to check for updates every two days or change it to something else.
  5. Paste the following code right beneath the previous:
    // Don't edit after this line, unless you know what you're doing ;-)
     name: /\/\/\s*@name\s+(.*)\s*\n/i.exec(scr_meta)[1],
     version: /\/\/\s*@version\s+(.*)\s*\n/i.exec(scr_meta)[1].replace(/\./g, ''),
     time: new Date().getTime(),
     call: function(response) {
        GM_xmlhttpRequest({
          method: 'GET',
    	  url: 'https://userscripts.org/scripts/source/'+this.id+'.meta.js',
    	  onload: function(xpr) {AnotherAutoUpdater.compare(xpr,response);}
          });
      },
     compare: function(xpr,response) {
        this.xversion=/\/\/\s*@version\s+(.*)\s*\n/i.exec(xpr.responseText);
        this.xname=/\/\/\s*@name\s+(.*)\s*\n/i.exec(xpr.responseText);
        if ( (this.xversion) && (this.xname[1] == this.name) ) {
          this.xversion = this.xversion[1].replace(/\./g, '');
          this.xname = this.xname[1];
        } else {
          if ( (xpr.responseText.match("the page you requested doesn't exist")) || (this.xname[1] != this.name) ) 
    	GM_setValue('updated_'+this.id, 'off');
          return false;
        }
        if ( (+this.xversion > +this.version) && (confirm('A new version of the '+this.xname+' user script is available. Do you want to update?')) ) {
          GM_setValue('updated_'+this.id, this.time+'');
          top.location.href = 'https://userscripts.org/scripts/source/'+this.id+'.user.js';
        } else if ( (this.xversion) && (+this.xversion > +this.version) ) {
          if(confirm('Do you want to turn off auto updating for this script?')) {
    	GM_setValue('updated_'+this.id, 'off');
    	GM_registerMenuCommand("Auto Update "+this.name, function(){GM_setValue('updated_'+this.id, new Date().getTime()+''); AnotherAutoUpdater.call(true);});
    	alert('Automatic updates can be re-enabled for this script from the User Script Commands submenu.');
          } else {
    	GM_setValue('updated_'+this.id, this.time+'');
          }
        } else {
          if(response) alert('No updates available for '+this.name);
          GM_setValue('updated_'+this.id, this.time+'');
        }
      },
     check: function() {
        if (GM_getValue('updated_'+this.id, 0) == 0) GM_setValue('updated_'+this.id, this.time+'');
        if ( (GM_getValue('updated_'+this.id, 0) != 'off') && (+this.time > (+GM_getValue('updated_'+this.id, 0) + (1000*60*60*24*this.days))) ) {
          this.call();
        } else if (GM_getValue('updated_'+this.id, 0) == 'off') {
          GM_registerMenuCommand("Enable "+this.name+" updates", function(){GM_setValue('updated_'+this.id, new Date().getTime()+'');AnotherAutoUpdater.call(true);});
        } else {
          GM_registerMenuCommand("Check "+this.name+" for updates", function(){GM_setValue('updated_'+this.id, new Date().getTime()+'');AnotherAutoUpdater.call(true);});
        }
        }
    };
    if (self.location == top.location && typeof GM_xmlhttpRequest != 'undefined') AnotherAutoUpdater.check();
  6. Install this script so you can be notified of when I make a change to the auto-update code.

Make a Donation via Paypal

I'm a college student, so that equates to not having much time or money, but I still find the time to work on my user scripts. I put a lot of time and effort into my scripts so if you find this script useful, please consider making a donation.

Make a donation with paypal