Permalink
Browse files

Adding self-update code.

  • Loading branch information...
1 parent 321f5a8 commit 5c3c80a79384699c35d97908f1c9cacc5028092d @juliamae committed Apr 7, 2009
Showing with 55 additions and 1 deletion.
  1. +55 −1 gm-scripts/tumblr_h8.user.js
@@ -1,13 +1,16 @@
+scr_meta=<><![CDATA[
// ==UserScript==
// @name Tumblr H8
// @namespace h8cloud
// @description Provides a link to let you "h8" a post (as opposed to "<3"). H8ed posts and their reblogs are hidden from you forever!
// @include http://www.tumblr.com/dashboard
// @include http://www.tumblr.com/dashboard/*
// @exclude http://www.tumblr.com/dashboard/iframe*
+// @version 0.4.0
// @copyright 2k9, Julia West (http://h8cloud.com)
// @license (CC) Attribution-Share Alike 3.0 United States; http://creativecommons.org/licenses/by-sa/3.0/us/
// ==/UserScript==
+]]></>;
// Change this value to false if you do not want the posts you h8 to (anonymously) go to h8cloud.com
var sendH8 = true;
@@ -162,4 +165,55 @@ function sendH8ToCloud(id, post) {
},
data: dataString
});
-}
+}
+
+// Update Notifier Script
+CheckScriptForUpdate = {
+ // Config values, change these to match your script
+ id: '45673', // Script id on Userscripts.org
+ days: 1, // Days to wait between update checks
+ name: /\/\/\s*@name\s*(.*)\s*\n/i.exec(scr_meta)[1],
+ version: /\/\/\s*@version\s*(.*)\s*\n/i.exec(scr_meta)[1],
+ time: new Date().getTime() | 0,
+ call: function(response) {
+ GM_xmlhttpRequest({
+ method: 'GET',
+ url: 'https://userscripts.org/scripts/source/'+this.id+'.meta.js',
+ headers: {
+ 'User-agent': window.navigator.userAgent,
+ 'Accept': 'application/atom+xml,application/xml,text/xml',
+ },
+ onload: function(xpr) {CheckScriptForUpdate.compare(xpr,response);}
+ });
+ },
+ compare: function(xpr,response) {
+ this.xversion=/\/\/\s*@version\s*(.*)\s*\n/i.exec(xpr.responseText)[1];
+ this.xname=/\/\/\s*@name\s*(.*)\s*\n/i.exec(xpr.responseText)[1];
+ 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.time);
+ GM_openInTab('http://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', 'off');
+ GM_registerMenuCommand("Auto Update "+this.name, function(){GM_setValue('updated', new Date().getTime() | 0);CheckScriptForUpdate.call('return');});
+ alert('Automatic updates can be re-enabled for this script from the User Script Commands submenu.');
+ } else {
+ GM_setValue('updated', this.time);
+ }
+ } else {
+ if(response) alert('No updates available for '+this.name);
+ GM_setValue('updated', this.time);
+ }
+ },
+ check: function() {
+ if (GM_getValue('updated', 0) == 0) GM_setValue('updated', this.time);
+ if ( (GM_getValue('updated', 0) != 'off') && (+this.time > (+GM_getValue('updated', 0) + (1000*60*60*24*this.days))) ) {
+ this.call();
+ } else if (GM_getValue('updated', 0) == 'off') {
+ GM_registerMenuCommand("Enable "+this.name+" updates", function(){GM_setValue('updated', new Date().getTime() | 0);CheckScriptForUpdate.call(true);});
+ } else {
+ GM_registerMenuCommand("Check "+this.name+" for updates", function(){GM_setValue('updated', new Date().getTime() | 0);CheckScriptForUpdate.call(true);});
+ }
+ }
+};
+if (self.location == top.location && GM_xmlhttpRequest) CheckScriptForUpdate.check();

0 comments on commit 5c3c80a

Please sign in to comment.