GC AIO Plugin: Notepad

Add a notepad to the sidebar on Grundo's Café

  1. // ==UserScript==
  2. // @name GC AIO Plugin: Notepad
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Add a notepad to the sidebar on Grundo's Café
  6. // @author https://www.grundos.cafe/userlookup/?user=supercow64
  7. // @match https://www.grundos.cafe/*
  8. // @icon https://www.grundos.cafe/static/images/favicon.66a6c5f11278.ico
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. const html = `<div class="notepad">
  14. <b>Notepad</b>
  15. <textarea id="aio_notepad"></textarea>
  16. </div>`
  17.  
  18. const defaultText = `Tip: Click "Edit Sidebar" and add this code to make the sidebar prettier
  19.  
  20. #aio_notepad {
  21. width: 100%;
  22. height: 200px;
  23. border: 1px solid lightblue;
  24. }`
  25.  
  26. // uncomment for testing
  27. // const localStorage = sessionStorage
  28.  
  29. async function main() {
  30. // add the sidebar
  31. const target = document.querySelector("#aio_sidebar > .dailies")
  32. if (!target) return
  33. target.insertAdjacentHTML(`beforebegin`, html)
  34.  
  35. // set the notepad text
  36. const notepad = document.querySelector("#aio_notepad")
  37. notepad.value = localStorage["aio_notepad"] ?? defaultText
  38. // save notepad changes
  39. notepad.addEventListener("change", async () => {
  40. localStorage["aio_notepad"] = notepad.value
  41. })
  42. }
  43.  
  44. main()