Idlescape Notepad

Notepad for Idlescape

  1. // ==UserScript==
  2. // @name Idlescape Notepad
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2.2
  5. // @description Notepad for Idlescape
  6. // @author Grettz
  7. // @match *://*.idlescape.com/game*
  8. // @require http://code.jquery.com/jquery-latest.js
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13. // Notes button
  14. $("#usersOnline").prepend('<button id="notesButton">Notes</button>');
  15. $("#notesButton").css("background-color", "inherit").css("color", "inherit").css("float", "left").css("border", "none").css("outline", "none");
  16. // Notepad
  17. $('.game-content').append(
  18. '<div id="notesContainer">' +
  19. '<textarea id="notesArea" name="Notes"></textarea>' +
  20. '<input type="button" id="saveNote" value="Save Note">' +
  21. '</div>'
  22. );
  23. $("#notesContainer").css("position", "relative").css("top", 0).css("left", 0).css("z-index", 100010);
  24. $("#notesContainer").css("display", "none").css("height", "0px").css("width", "0px");
  25. $("#notesArea").css("background-color", "white").css("resize", "both").css("white-space", "pre");
  26.  
  27. // Open/Close Notepad
  28. let notesOpen = false;
  29. $("#notesButton").on("click", () => {
  30. if (!notesOpen) { // Open notepad
  31. let width = "350px";
  32. let height = "200px";
  33. // Get saved notepad size from session
  34. let storedWidth = sessionStorage.getItem("notepadWidth");
  35. let storedHeight = sessionStorage.getItem("notepadHeight");
  36. if (storedWidth && storedHeight) {
  37. width = storedWidth;
  38. height = storedHeight;
  39. };
  40.  
  41. // Show and animate notepad
  42. $("#notesContainer").css("display", "block");
  43. $("#notesArea").animate({
  44. width: width,
  45. height: height
  46. }, 350, () => {
  47. notesOpen = true;
  48. });
  49.  
  50. } else { // Close notepad
  51. // Save notepad size for session
  52. let width = $("#notesArea").width() + 6 + "px";
  53. let height = $("#notesArea").height() + 6 + "px";
  54. sessionStorage.setItem("notepadWidth", width);
  55. sessionStorage.setItem("notepadHeight", height);
  56. $("#notesArea").animate({
  57. width: "0px",
  58. height: "0px"
  59. }, 350, () => {
  60. $("#notesContainer").css("display", "none");
  61. notesOpen = false;
  62. });
  63. };
  64. });
  65.  
  66. // Save button
  67. $("#saveNote").on("click", () => {
  68. saveNotes();
  69. });
  70.  
  71. function saveNotes() {
  72. let notes = $("#notesArea").val();
  73. localStorage.setItem("notesData", notes);
  74. console.log("Notes saved!");
  75. };
  76.  
  77. function loadNotes() {
  78. let notes = localStorage.getItem("notesData");
  79. if (notes == "undefined" || notes == null) {
  80. $("#notesArea").val("New Note");
  81. return
  82. };
  83. $("#notesArea").val(notes);
  84. console.log("Notes loaded!");
  85. };
  86.  
  87. window.addEventListener("beforeunload", saveNotes);
  88. window.addEventListener("load", loadNotes);
  89. })();