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.

  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.4 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/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: 5px 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. + "<p>Remember you can access the update from GreaseMonkey command menu.</p>";
  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. CreateButton("OpenUserJS", "https://openuserjs.org/scripts/TimidScript/GM_update_Tester");
  36. CreateButton("OpenUserJS", "https://openuserjs.org/scripts/TimidScript/GM_update_Tester", "https://openuserjs.org/meta/TimidScript/GM_update_Tester.meta.js");
  37. CreateButton("MonkeyGuts", "https://monkeyguts.com/code.php?id=397");
  38. var btn = CreateButton("PrintOut Console Example");
  39. btn.textContent = "Printout version check in console";
  40. btn.onclick = PersonlisedDisplay;
  41. btn.style.marginTop = "10px";
  42.  
  43. function CreateButton(site, home, meta)
  44. {
  45. var btn = document.createElement("div");
  46. 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;");
  47.  
  48. if (meta) btn.innerHTML = "Check using " + site + " <a href='" + meta + "'>metaURL</a>";
  49. else btn.innerHTML = "Check using " + site + " <a href='" + home + "'>homeURL</a>";
  50.  
  51. btn.homeURL = home;
  52. btn.metaURL = meta;
  53. btn.onclick = ShowGMUpdateDialog;
  54.  
  55. notice.appendChild(btn);
  56. return btn;
  57. }
  58.  
  59. function ShowGMUpdateDialog(e)
  60. {
  61. //Reset stored information about online version
  62. GM_update.online = { name: "", version: "", description: "", changelog: "", date: "", userURL: "" };
  63. GM_update.installed.homeURL = this.homeURL;
  64. GM_update.installed.metaURL = this.metaURL;
  65. GM_update.showUpdateDialog();
  66. GM_update.isThereANewVersion();
  67. }
  68.  
  69.  
  70. function PersonlisedDisplay()
  71. {
  72. var url = "https://greasyfork.org/scripts/4439/code/4439.meta.js";
  73. GM_update.installed.homeURL = "https://greasyfork.org/scripts/4439-gm-update-tester";
  74. delete GM_update.installed.metaURL;
  75. GM_update.isThereANewVersion(url, updateCallback);
  76. }
  77.  
  78. function updateCallback(success)
  79. {
  80. console.log("Has new version check succeeded: ", success);
  81. if (success)
  82. {
  83. console.info("Do Version Match: ", GM_update.online.version == GM_update.installed.version);
  84. console.log("Installed/Online: ", GM_update.installed.version + "/" + GM_update.online.version)
  85. console.log(GM_update.installed);
  86. console.log(GM_update.online);
  87. }
  88. }