Reply-command Library

Library for Ventero's Reply-command

目前为 2016-03-23 提交的版本。查看 最新版本

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.cn-greasyfork.org/scripts/18199/114918/Reply-command%20Library.js

  1. // ==UserScript==
  2. // @ name Ventero's AutoUpdater Framework
  3. // @ description Library for many of Ventero's scripts
  4. // @ version
  5. // @ license Public Domain
  6. // ==/UserScript==
  7. // The following code is released under public domain.
  8. // ==/UserScript==
  9.  
  10. var AutoUpdater_47963 = {
  11. id: 47963,
  12. days: 2,
  13. time: new Date().getTime(),
  14. version: GM_info.script.version,
  15. name: GM_info.script.name,
  16. call: function(response, secure) {
  17. GM_xmlhttpRequest({
  18. method: 'GET',
  19. url: 'http'+(secure ? 's' : '')+'://userscripts.org/scripts/source/'+this.id+'.meta.js',
  20. onload: function(xpr) {AutoUpdater_47963.compare(xpr, response);},
  21. onerror: function(xpr) {if (secure) AutoUpdater_47963.call(response, false);}
  22. });
  23. },
  24. enable: function() {
  25. GM_registerMenuCommand("Enable "+this.name+" updates", function() {
  26. GM_setValue('updated_47963', new Date().getTime()+'');
  27. AutoUpdater_47963.call(true, true)
  28. });
  29. },
  30. compareVersion: function(r_version, l_version) {
  31. var r_parts = r_version.split('.'),
  32. l_parts = l_version.split('.'),
  33. r_len = r_parts.length,
  34. l_len = l_parts.length,
  35. r = l = 0;
  36. for(var i = 0, len = (r_len > l_len ? r_len : l_len); i < len && r == l; ++i) {
  37. r = +(r_parts[i] || '0');
  38. l = +(l_parts[i] || '0');
  39. }
  40. return (r !== l) ? r > l : false;
  41. },
  42. compare: function(xpr,response) {
  43. this.xversion=/\/\/\s*@version\s+(.+)\s*\n/i.exec(xpr.responseText);
  44. this.xname=/\/\/\s*@name\s+(.+)\s*\n/i.exec(xpr.responseText);
  45. if ( (this.xversion) && (this.xname[1] == this.name) ) {
  46. this.xversion = this.xversion[1];
  47. this.xname = this.xname[1];
  48. } else {
  49. if ( (xpr.responseText.match("the page you requested doesn't exist")) || (this.xname[1] != this.name) )
  50. GM_setValue('updated_47963', 'off');
  51. return false;
  52. }
  53. var updated = this.compareVersion(this.xversion, this.version);
  54. if ( updated && confirm('A new version of '+this.xname+' is available.\nDo you wish to install the latest version?') ) {
  55. try {
  56. location.href = 'http://userscripts.org/scripts/source/' + this.id + '.user.js';
  57. } catch(e) {}
  58. } else if ( this.xversion && updated ) {
  59. if(confirm('Do you want to turn off auto updating for this script?')) {
  60. GM_setValue('updated_47963', 'off');
  61. this.enable();
  62. alert('Automatic updates can be re-enabled for this script from the User Script Commands submenu.');
  63. }
  64. } else if (response)
  65. alert('No updates available for '+this.name);
  66. },
  67. check: function() {
  68. if (GM_getValue('updated_47963', 0) == "off")
  69. this.enable();
  70. else {
  71. if (+this.time > (+GM_getValue('updated_47963', 0) + 1000*60*60*24*this.days)) {
  72. GM_setValue('updated_47963', this.time+'');
  73. this.call(false, true);
  74. }
  75. GM_registerMenuCommand("Check "+this.name+" for updates", function() {
  76. GM_setValue('updated_47963', new Date().getTime()+'');
  77. AutoUpdater_47963.call(true, true)
  78. });
  79. }
  80. }
  81. };
  82. if (typeof GM_xmlhttpRequest !== 'undefined' &&
  83. typeof GM_updatingEnabled === 'undefined') // has an updater?
  84. try {
  85. if (unsafeWindow.frameElement === null)
  86. AutoUpdater_47963.check();
  87. } catch(e) {
  88. AutoUpdater_47963.check();
  89. }