gimmickCellar

Untitled

Feb 11th, 2026
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.25 KB | None | 0 0
  1. // ==UserScript==
  2. // @name OWOT Character Hider
  3. // @namespace http://ourworldoftext.com/
  4. // @version 1.0
  5. // @description gimmickCellar does what OWon't.
  6. // @author gimmickCellar
  7. // @match *://ourworldoftext.com/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. // 1. Wait for OWOT variables to be initialized
  15. const startScript = () => {
  16. if (typeof w === 'undefined' || typeof Modal === 'undefined' || !w.menu) {
  17. setTimeout(startScript, 100);
  18. return;
  19. }
  20.  
  21. // 2. Persistent State Handling
  22. const STORAGE_KEY = "owot_hider_prefs";
  23. let hiderState = {
  24. ascii: false,
  25. unicode: false,
  26. blocks: false,
  27. slc: false
  28. };
  29.  
  30. const loadPrefs = () => {
  31. const saved = localStorage.getItem(STORAGE_KEY);
  32. if (saved) {
  33. try {
  34. hiderState = Object.assign(hiderState, JSON.parse(saved));
  35. } catch (e) { console.error("Failed to load hider prefs", e); }
  36. }
  37. };
  38.  
  39. const savePrefs = () => {
  40. localStorage.setItem(STORAGE_KEY, JSON.stringify(hiderState));
  41. };
  42.  
  43. // 3. Identification Logic
  44. const isBlockChar = (code) => (code >= 0x2580 && code <= 0x259F);
  45.  
  46. const isSLC = (code) => {
  47. // Range for Symbols for Legacy Computing + Octants
  48. return (code >= 0x1FB00 && code <= 0x1FBFF) ||
  49. (code >= 0x1CD00 && code <= 0x1CDE5) ||
  50. [0x1CEA0, 0x1CEA3, 0x1CEA8, 0x1CEAB, 0x1FBE6, 0x1FBE7].includes(code);
  51. };
  52.  
  53. // 4. Core Renderer Patch
  54. const originalRenderChar = window.renderChar;
  55.  
  56. window.renderChar = function(textRender, offsetX, offsetY, char, color, cellW, cellH, protectionValue, linkType, highlight, charX, charY, tileX, tileY, isOverflow) {
  57.  
  58. // Identify character code (stripping potential bold/italic combining markers)
  59. const cleanChar = typeof clearCharTextDecorations === 'function' ? clearCharTextDecorations(char) : char;
  60. const code = cleanChar.codePointAt(0);
  61.  
  62. let shouldHide = false;
  63. if (hiderState.ascii && code < 128) shouldHide = true;
  64. if (hiderState.unicode && code >= 128) shouldHide = true;
  65. if (hiderState.blocks && isBlockChar(code)) shouldHide = true;
  66. if (hiderState.slc && isSLC(code)) shouldHide = true;
  67.  
  68. if (shouldHide) {
  69. // If we aren't in an overflow draw, we need to "erase" the cell
  70. if (!isOverflow) {
  71. let bgColor;
  72. // Use character-specific writability/protection value
  73. if (protectionValue === 0) bgColor = w.styles.public;
  74. else if (protectionValue === 1) bgColor = w.styles.member;
  75. else if (protectionValue === 2) bgColor = w.styles.owner;
  76. else bgColor = w.styles.public;
  77.  
  78. textRender.fillStyle = bgColor;
  79. textRender.fillRect(offsetX, offsetY, cellW, cellH);
  80. }
  81. return true; // Refuse to render the character glyph
  82. }
  83.  
  84. return originalRenderChar.apply(this, arguments);
  85. };
  86.  
  87. // 5. Modal UI
  88. const hiderModal = new Modal();
  89. hiderModal.setMinimumSize(320, 280);
  90.  
  91. const titleElm = document.createElement("div");
  92. Object.assign(titleElm.style, {
  93. fontWeight: "bold",
  94. marginBottom: "15px",
  95. textAlign: "center",
  96. fontSize: "16px",
  97. color: "#333"
  98. });
  99. titleElm.innerText = "Character Visibility Filters";
  100. hiderModal.client.appendChild(titleElm);
  101.  
  102. hiderModal.createCheckboxField();
  103. const cbAscii = hiderModal.addCheckbox("Hide Standard ASCII");
  104. const cbUnicode = hiderModal.addCheckbox("Hide All Unicode");
  105. const cbBlocks = hiderModal.addCheckbox("Hide Block Elements (░▒▓█)");
  106. const cbSlc = hiderModal.addCheckbox("Hide Legacy Computing (SLC)");
  107.  
  108. // Set initial checkbox states from saved data
  109. loadPrefs();
  110. cbAscii.cbElm.checked = hiderState.ascii;
  111. cbUnicode.cbElm.checked = hiderState.unicode;
  112. cbBlocks.cbElm.checked = hiderState.blocks;
  113. cbSlc.cbElm.checked = hiderState.slc;
  114.  
  115. hiderModal.createClose();
  116.  
  117. hiderModal.checkboxFieldOnInput(function() {
  118. hiderState.ascii = cbAscii.cbElm.checked;
  119. hiderState.unicode = cbUnicode.cbElm.checked;
  120. hiderState.blocks = cbBlocks.cbElm.checked;
  121. hiderState.slc = cbSlc.cbElm.checked;
  122.  
  123. savePrefs();
  124. w.reloadRenderer(); // Clear pixel cache
  125. w.redraw(); // Force visual refresh
  126. });
  127.  
  128. // 6. Add to Main Menu
  129. w.menu.addOption("Filter Characters", () => hiderModal.open());
  130.  
  131. // Final trigger for first load if any prefs were active
  132. if (Object.values(hiderState).some(v => v === true)) {
  133. w.reloadRenderer();
  134. w.redraw();
  135. }
  136. };
  137.  
  138. startScript();
  139. })();
Advertisement
Add Comment
Please, Sign In to add comment