GM_update Tester

GM_Update is a library that allows you to update your script from any site that support meta.js standard or the main USO alternatives: OpenUserJS, Greasy Fork and MonkeyGuts. It now should support other browsers beside FireFox, like Chrome and Opera.

目前为 2014-11-01 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name GM_update Tester
  3. // @namespace TimidScript
  4. // @description GM_Update is a library that allows you to update your script from any site that support meta.js standard or the main USO alternatives: OpenUserJS, Greasy Fork and MonkeyGuts. It now should support other browsers beside FireFox, like Chrome and Opera.
  5. // @include www.example.com
  6. // @version 1.0.3 GF
  7. // @require http://openuserjs.org/src/libs/TimidScript/TSL_-_GM_Update.js
  8. // @icon https://i.imgur.com/FD46Ak3.png
  9. // @include *//www.example.com*
  10. // @include *//example.com*
  11. // @grant GM_xmlhttpRequest
  12. // @grant GM_info
  13. // @grant GM_getMetadata
  14. // @grant GM_getValue
  15. // @grant GM_setValue
  16. // @grant GM_deleteValue
  17. // @grant GM_registerMenuCommand
  18. // @homeurl https://greasyfork.org/en/scripts/4439-gm-update-tester
  19. // @changelog A better tester
  20. // ==/UserScript==
  21.  
  22. // @gm_update manual
  23. var notice = document.createElement("div");
  24. notice.setAttribute("style", "position: fixed; top: 10px; right: 10px; width: 400px; color: green; background-color: #E7E7F1; z-index: 999999999999; padding: 0 10px; border: 3px solid pink; margin: 0; text-align: left; font-size: 13px;");
  25.  
  26. notice.innerHTML = "<p>&nbsp;&nbsp;&nbsp;Example showing the two different ways of checking for online version on the main "
  27. + "user-scripts sites. The first is using homeURL property, the second is using the metaURL property.</p>"
  28. + "<p>For more information checkout the script, <a href='https://greasyfork.org/en/scripts/4439-gm-update-tester'>GM_updateTester</a> "
  29. + "page and <a href='https://openuserjs.org/libs/TimidScript/TSL_-_GM_Update'>GM_update</a> library page.</p>";
  30.  
  31. document.body.appendChild(notice);
  32.  
  33. CreateButton("GreasyFork", "https://greasyfork.org/scripts/4439-gm-update-tester");
  34. CreateButton("GreasyFork", "https://greasyfork.org/scripts/4439-gm-update-tester", "https://greasyfork.org/scripts/4439-gm-update-tester/code/GM_update%20Tester.meta.js");
  35.  
  36. CreateButton("OpenUserJS", "https://openuserjs.org/scripts/TimidScript/GM_update_Tester");
  37. CreateButton("OpenUserJS", "https://openuserjs.org/scripts/TimidScript/GM_update_Tester", "https://openuserjs.org/meta/TimidScript/GM_update_Tester.meta.js");
  38. CreateButton("MonkeyGuts", "https://monkeyguts.com/code.php?id=397");
  39.  
  40. notice.innerHTML += "Remember you can access the update from GreaseMonkey command menu.";
  41.  
  42. CreateButton("PrintOut Console Example").onclick = PersonlisedDisplay;
  43.  
  44. function CreateButton(site, home, meta)
  45. {
  46. var btn = document.createElement("div");
  47. btn.setAttribute("style", "margin: 5px; padding:5px; text-align: center; border: 1px red solid; background-color: #FBF8C8; color: red; border-radius: 5px; width: 380px; cursor: pointer;");
  48.  
  49. if (meta) btn.innerHTML = "Check using " + site + " <a href='" + meta + "'>metaURL</a>";
  50. else btn.innerHTML = "Check using " + site + " <a href='" + home + "'>homeURL</a>";
  51.  
  52. btn.homeURL = home;
  53. btn.metaURL = meta;
  54. btn.onclick = ShowStandardDialog;
  55.  
  56. notice.appendChild(btn);
  57.  
  58. return btn;
  59. }
  60.  
  61. function ShowStandardDialog(e)
  62. {
  63. //Reset stored information about online version
  64. GM_update.online = { name: "", version: "", description: "", changelog: "", date: "", userURL: "" };
  65. GM_update.installed.homeURL = this.homeURL;
  66. GM_update.installed.metaURL = this.metaURL;
  67.  
  68. GM_update.showUpdateDialog();
  69. GM_update.isThereANewVersion();
  70. }
  71.  
  72. function PersonlisedDisplay()
  73. {
  74. var url = "https://greasyfork.org/scripts/4439/code/4439.meta.js";
  75. GM_update.installed.homeURL = "https://greasyfork.org/scripts/4439-gm-update-tester";
  76. delete GM_update.installed.metaURL;
  77. GM_update.isThereANewVersion(url, updateCallback);
  78. }
  79.  
  80. function updateCallback(success)
  81. {
  82. console.log("Has new version check succeeded: ", success);
  83. if (success)
  84. {
  85. console.info("Do Version Match: ", GM_update.online.version == GM_update.installed.version);
  86. console.log("Installed/Online: ", GM_update.installed.version + "/" + GM_update.online.version)
  87. console.log(GM_update.installed);
  88. console.log(GM_update.online);
  89. }
  90. }