Reply-command (hotkey) Library

Library for Ventero's Reply-command (hotkey) script

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

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