popup for coronabuddy

@require library

As of 23/05/2020. See the latest version.

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.sleazyfork.org/scripts/403976/808248/popup%20for%20coronabuddy.js

  1. // Vars
  2. let darkmodeEnabled;
  3.  
  4. let coronaBuddyPopup = /*html*/`
  5. <span onclick="document.querySelector('#coronaBuddyPopupInstance').remove" style="color: lime !important; top: 0; right: 0; padding: 1em 1em 1em 1em; display: block; position: absolute; cursor: pointer; font-weight: 800;">X</span>
  6. <div class="popup__banner">
  7. <p class="popup__banner--text">Coronabuddy</p>
  8. </div>
  9. <div class="popup">
  10. <textarea id="popup__textarea" class="popup__textarea class"></textarea>
  11. </div>
  12. <div class="popup__button--center">
  13. <button id="popup__save" class="popup__button popup__button--save"><p id="popup__save--text" class="popup__button--text">SAVE LIST</p></button>
  14. <button id="popup__clear" class="popup__button popup__button--clear"><p class="popup__button--text">CLEAR LIST</p></button>
  15. </div>
  16. <div class="popup__darkmode">
  17. <div class="popup__darkmode--text">Dark Mode?</div>
  18. <div id="popup__check" class="popup__darkmode--checkbox"></div>
  19. </div>
  20. `;
  21.  
  22. function saveNiggerList() {
  23. if (document.querySelector("#popup__textarea")) {
  24. GM.setValue(
  25. "gayNiggerList",
  26. document.querySelector("#popup__textarea").value
  27. ).then(() => {
  28. location.reload();
  29. });
  30. }
  31. }
  32.  
  33. function clearNiggerList() {
  34. if (document.querySelector("#popup__textarea")) {
  35. GM.setValue("gayNiggerList", "Gay Nigger 1, Gay Nigger 2").then(() => {
  36. location.reload();
  37. });
  38. }
  39. }
  40.  
  41. function coronaBuddyDarkmodeToggle() {
  42. if (darkModeEnabled === true) {
  43. darkModeEnabled = false;
  44. document
  45. .querySelector("#popup__check")
  46. .classList.remove("popup__darkmode--checkbox--check");
  47. GM.setValue("darkmodeEnabled", false).then(() => {
  48. location.reload();
  49. });
  50. } else {
  51. darkModeEnabled = true;
  52. document
  53. .querySelector("#popup__check")
  54. .classList.add("popup__darkmode--checkbox--check");
  55. GM.setValue("darkmodeEnabled", true).then(() => {
  56. location.reload();
  57. });
  58. }
  59. }
  60.  
  61. GM.registerMenuCommand(
  62. "Coronabuddy Options",
  63. function () {
  64. let coronaBuddyPopupInstance = document.createElement("div");
  65. coronaBuddyPopupInstance.id = "coronaBuddyPopupInstance"
  66. coronaBuddyPopupInstance.innerHTML = coronaBuddyPopup;
  67. coronaBuddyPopupInstance.style.cssText +=
  68. "position: fixed; top: 10em; text-align: center; max-width: 20em; height: 60vh; margin: 0 auto; background-color: black; left: 0; right: 0;";
  69.  
  70. document.body.appendChild(coronaBuddyPopupInstance);
  71. document.querySelector(".popup__button--save").onclick = saveNiggerList;
  72. document.querySelector(".popup__button--clear").onclick = clearNiggerList;
  73. document.querySelector("#popup__check").onclick = coronaBuddyDarkmodeToggle;
  74. GM.getValue("darkmodeEnabled", false).then((value) => {
  75. darkModeEnabled = value;
  76. if (value === false) {
  77. } else {
  78. document
  79. .querySelector("#popup__check")
  80. .classList.add("popup__darkmode--checkbox--check");
  81. }
  82. });
  83. document.querySelector("#popup__textarea").value = gayNiggerList;
  84. document
  85. .getElementById("popup__textarea")
  86. .addEventListener("keydown", function (event) {
  87. if (event.key === "Enter") {
  88. event.preventDefault();
  89. saveNiggerList();
  90. document
  91. .getElementById("popup__save")
  92. .classList.add("popup__button--invert");
  93. document
  94. .getElementById("popup__save--text")
  95. .classList.add("popup__button--invert");
  96. setTimeout(() => {
  97. document
  98. .getElementById("popup__save")
  99. .classList.remove("popup__button--invert");
  100. document
  101. .getElementById("popup__save--text")
  102. .classList.remove("popup__button--invert");
  103. }, 1000);
  104. }
  105. });
  106. },
  107. "r"
  108. );