Chat Timestamp And Whisper Link Library

Library for Ventero's Chat Timestamp And Whisper Link script

当前为 2016-03-23 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.cn-greasyfork.org/scripts/18206/114946/Chat%20Timestamp%20And%20Whisper%20Link%20Library.js

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