Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name OWOT Character Hider
- // @namespace http://ourworldoftext.com/
- // @version 1.0
- // @description gimmickCellar does what OWon't.
- // @author gimmickCellar
- // @match *://ourworldoftext.com/*
- // @grant none
- // ==/UserScript==
- (function() {
- 'use strict';
- // 1. Wait for OWOT variables to be initialized
- const startScript = () => {
- if (typeof w === 'undefined' || typeof Modal === 'undefined' || !w.menu) {
- setTimeout(startScript, 100);
- return;
- }
- // 2. Persistent State Handling
- const STORAGE_KEY = "owot_hider_prefs";
- let hiderState = {
- ascii: false,
- unicode: false,
- blocks: false,
- slc: false
- };
- const loadPrefs = () => {
- const saved = localStorage.getItem(STORAGE_KEY);
- if (saved) {
- try {
- hiderState = Object.assign(hiderState, JSON.parse(saved));
- } catch (e) { console.error("Failed to load hider prefs", e); }
- }
- };
- const savePrefs = () => {
- localStorage.setItem(STORAGE_KEY, JSON.stringify(hiderState));
- };
- // 3. Identification Logic
- const isBlockChar = (code) => (code >= 0x2580 && code <= 0x259F);
- const isSLC = (code) => {
- // Range for Symbols for Legacy Computing + Octants
- return (code >= 0x1FB00 && code <= 0x1FBFF) ||
- (code >= 0x1CD00 && code <= 0x1CDE5) ||
- [0x1CEA0, 0x1CEA3, 0x1CEA8, 0x1CEAB, 0x1FBE6, 0x1FBE7].includes(code);
- };
- // 4. Core Renderer Patch
- const originalRenderChar = window.renderChar;
- window.renderChar = function(textRender, offsetX, offsetY, char, color, cellW, cellH, protectionValue, linkType, highlight, charX, charY, tileX, tileY, isOverflow) {
- // Identify character code (stripping potential bold/italic combining markers)
- const cleanChar = typeof clearCharTextDecorations === 'function' ? clearCharTextDecorations(char) : char;
- const code = cleanChar.codePointAt(0);
- let shouldHide = false;
- if (hiderState.ascii && code < 128) shouldHide = true;
- if (hiderState.unicode && code >= 128) shouldHide = true;
- if (hiderState.blocks && isBlockChar(code)) shouldHide = true;
- if (hiderState.slc && isSLC(code)) shouldHide = true;
- if (shouldHide) {
- // If we aren't in an overflow draw, we need to "erase" the cell
- if (!isOverflow) {
- let bgColor;
- // Use character-specific writability/protection value
- if (protectionValue === 0) bgColor = w.styles.public;
- else if (protectionValue === 1) bgColor = w.styles.member;
- else if (protectionValue === 2) bgColor = w.styles.owner;
- else bgColor = w.styles.public;
- textRender.fillStyle = bgColor;
- textRender.fillRect(offsetX, offsetY, cellW, cellH);
- }
- return true; // Refuse to render the character glyph
- }
- return originalRenderChar.apply(this, arguments);
- };
- // 5. Modal UI
- const hiderModal = new Modal();
- hiderModal.setMinimumSize(320, 280);
- const titleElm = document.createElement("div");
- Object.assign(titleElm.style, {
- fontWeight: "bold",
- marginBottom: "15px",
- textAlign: "center",
- fontSize: "16px",
- color: "#333"
- });
- titleElm.innerText = "Character Visibility Filters";
- hiderModal.client.appendChild(titleElm);
- hiderModal.createCheckboxField();
- const cbAscii = hiderModal.addCheckbox("Hide Standard ASCII");
- const cbUnicode = hiderModal.addCheckbox("Hide All Unicode");
- const cbBlocks = hiderModal.addCheckbox("Hide Block Elements (░▒▓█)");
- const cbSlc = hiderModal.addCheckbox("Hide Legacy Computing (SLC)");
- // Set initial checkbox states from saved data
- loadPrefs();
- cbAscii.cbElm.checked = hiderState.ascii;
- cbUnicode.cbElm.checked = hiderState.unicode;
- cbBlocks.cbElm.checked = hiderState.blocks;
- cbSlc.cbElm.checked = hiderState.slc;
- hiderModal.createClose();
- hiderModal.checkboxFieldOnInput(function() {
- hiderState.ascii = cbAscii.cbElm.checked;
- hiderState.unicode = cbUnicode.cbElm.checked;
- hiderState.blocks = cbBlocks.cbElm.checked;
- hiderState.slc = cbSlc.cbElm.checked;
- savePrefs();
- w.reloadRenderer(); // Clear pixel cache
- w.redraw(); // Force visual refresh
- });
- // 6. Add to Main Menu
- w.menu.addOption("Filter Characters", () => hiderModal.open());
- // Final trigger for first load if any prefs were active
- if (Object.values(hiderState).some(v => v === true)) {
- w.reloadRenderer();
- w.redraw();
- }
- };
- startScript();
- })();
Advertisement
Add Comment
Please, Sign In to add comment