index.html 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Disable donation message</title>
  6. <base href="" target="_top" id="base">
  7. <script>base.href = document.location.href.replace("/media", "").replace("index.html", "").replace(/[&?]wrapper=False/, "").replace(/[&?]wrapper_nonce=[A-Za-z0-9]+/, "")</script>
  8. </head>
  9. <body>
  10. <div>
  11. <h1>Disable donation message</h1>
  12. <p>
  13. This tool will help you hide the Donate message. If required,
  14. it is also possible to reactivate the message.<br>
  15. The message is implemented as a "plugin". This program will try
  16. to find the appropriate plugin and activate or deactivate it.
  17. To do this, click on the corresponding buttons.<br>
  18. The tool requires admin permissions to activate and deactivate
  19. the plugin. Except for enabling or disabling the plugin as
  20. desired, the permissions are not used. This is also verifiable
  21. in the source code.
  22. </p>
  23. <p>
  24. If you have a comment or discover an error, please feel free to
  25. write to me at <a href="mailto:m.k@mk16.de">m.k@mk16.de</a>. <br>
  26. Sometimes it is necessary to restart Zeronet before the changes
  27. take effect.
  28. </p>
  29. <p>
  30. The program comes without any guarantee. Use is at your own risk.
  31. </p>
  32. <button onclick="grantAdmin();">Grant admin permissions</button>
  33. <button onclick="checkAdmin(enableMessage);">Try enabling the donation message</button>
  34. <button onclick="checkAdmin(disableMessage);">Try disabling the donation message</button>
  35. </div>
  36. <script src="js/ZeroFrame.js"></script>
  37. <script>
  38. zf = new ZeroFrame();
  39. function grantAdmin() {
  40. zf.cmd("siteInfo", [], siteInfo => {
  41. if(siteInfo.settings.permissions.indexOf("ADMIN") > -1) {
  42. zf.cmd("wrapperNotification", ["done", "Admin permissions have already been granted."]);
  43. } else {
  44. zf.cmd("wrapperPermissionAdd", ["ADMIN"], () => {
  45. location.reload();
  46. });
  47. }
  48. });
  49. }
  50. function checkAdmin(func) {
  51. zf.cmd("siteInfo", [], siteInfo => {
  52. if(siteInfo.settings.permissions.indexOf("ADMIN") > -1) {
  53. func();
  54. } else {
  55. zf.cmd("wrapperNotification", ["info", "Admin permissions are required to enable/disable the plugin."]);
  56. }
  57. });
  58. }
  59. function isMessagePlugin(plugin) {
  60. return plugin.name.includes("DonationMessage");
  61. }
  62. function changeMessageStatus(status) {
  63. zf.cmd("pluginList", [], res => {
  64. var pot = res.plugins.filter(isMessagePlugin).filter(plugin => { return (status ? ! plugin.enabled : plugin.enabled ); });
  65. if (pot.length === 0) {
  66. zf.cmd("wrapperNotification", ["done", "No corresponding plugins could be found. It seems as if the message was already disabled."]);
  67. } else if (pot.length === 1) {
  68. setEnabledPlugin(pot[0], status);
  69. } else {
  70. var text = "I found " + pot.length + " possible plugins: ";
  71. for (var i = 0; i < pot.length; i++) {
  72. text += (i + 1) + " = " + pot[i].name + "; ";
  73. }
  74. zf.cmd("wrapperNotification", ["info", text]);
  75. zf.cmd("wrapperPrompt", ["Which should be selected?", "text"], input => {
  76. var pluginNumber = parseInt(input);
  77. if (isNaN(pluginNumber)) {
  78. zf.cmd("wrapperNotification", ["error", "The entered number could not be interpreted."]);
  79. } else if (pluginNumber < 1) {
  80. zf.cmd("wrapperNotification", ["error", "The number entered is too small."]);
  81. } else if (pluginNumber > pot.length) {
  82. zf.cmd("wrapperNotification", ["error", "The number entered is too big."]);
  83. } else {
  84. setEnabledPlugin(pot[pluginNumber - 1], status);
  85. }
  86. });
  87. }
  88. });
  89. }
  90. function disableMessage() {
  91. changeMessageStatus(false);
  92. }
  93. function enableMessage() {
  94. changeMessageStatus(true);
  95. }
  96. function setEnabledPlugin(plugin, is_enabled) {
  97. zf.cmd("pluginConfigSet", [plugin.source, plugin.inner_path, "enabled", is_enabled], res => {
  98. if (res === "ok") {
  99. zf.cmd("wrapperNotification", ["done", "Plugin " + plugin.name + " " + (is_enabled ? "enabled" : "disabled") + "."]);
  100. } else {
  101. zf.cmd("wrapperNotification", ["error", "Failed to disable plugin " + plugin.name + "."]);
  102. }
  103. });
  104. }
  105. </script>
  106. </body>
  107. </html>