From 9b03b8f63485acbd684be6c27bb326308f4011b8 Mon Sep 17 00:00:00 2001 From: Holly McFarland Date: Sat, 15 Aug 2026 22:07:06 -0400 Subject: [PATCH] Initial commit --- README.md | 1 + dscrda.user.js | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 README.md create mode 100644 dscrda.user.js diff --git a/README.md b/README.md new file mode 100644 index 0000000..86d999b --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# PLEASE PLEASE PLEASE back up your dictionary, I hacked this together \ No newline at end of file diff --git a/dscrda.user.js b/dscrda.user.js new file mode 100644 index 0000000..0d80e88 --- /dev/null +++ b/dscrda.user.js @@ -0,0 +1,93 @@ +// ==UserScript== +// @name Deep Space Communications Relay Dictionary Adder +// @namespace https://hollymcfarland.com +// @version 2026-08-16 +// @description Easily add words to dictionary +// @author You +// @match https://dscr.dixonary.co.uk/ +// @grant none +// ==/UserScript== + +(function() { + 'use strict'; + + const handleSignalClick = (e) => { + const signal = e.target; + + const isUndef = signal.classList.contains("undef"); + + const signalNum = Number( + isUndef + ? /^@(-\d+)/.exec(signal.innerText)[1] + : / (-\d+)$/.exec(signal.title)[1] + ); + const signalDef = ( + isUndef + ? "" + : signal.innerText + ); + + const dictObject = JSON.parse(localStorage.getItem("dict-raw")); + + const newDef = prompt(`New definition for signal |${signalNum}:`, signalDef); + if (newDef === null) return; + const capitalDef = newDef.toUpperCase(); + + const descObect = { + "desc": "??? ADD NOTES HERE ???", + "formatMode": dictObject.beforeUserDefaultMode, + "formatModeAfter": dictObject.afterUserDefaultMode, + "breakOnDouble": false + } + + if (isUndef) { + const index = dictObject.wordDict.keys.findIndex((n) => (n < signalNum)) - 1; + if (index !== -2) { + // Insert in sorted order + dictObject.wordDict.keys.splice(index, 0, signalNum); + dictObject.wordDict.values.splice(index, 0, capitalDef); + dictObject.descDict.keys.splice(index, 0, signalNum); + dictObject.descDict.values.splice(index, 0, descObect); + } else { + // Insert at end + dictObject.wordDict.keys.push(signalNum); + dictObject.wordDict.values.push(capitalDef); + dictObject.descDict.keys.push(signalNum); + dictObject.descDict.values.push(descObect); + } + } else { + const index = dictObject.wordDict.keys.indexOf(signalNum); + dictObject.wordDict.values[index] = capitalDef; + } + + // I don't want to do this right so we're going to paste the new dictionary into the textarea and click "save" + document.querySelector(".dict-paste-contents").value = JSON.stringify(dictObject); + document.querySelector(".save-dictionary").click(); + }; + + const messages = document.querySelector(".view"); + + const config = { + childList: true, + attributes: true, + charaterData: true, + subtree: true, + attributeOldValue: true, + characterDataOldValue: true, + }; + const mutationCallback = function(mutationsList, observer) { + for (const mutation of mutationsList) { + for (const node of mutation.addedNodes) { + if (node.nodeType === 1 && node.classList.contains("signal") && !node.classList.contains("number")) { + node.addEventListener("click", handleSignalClick); + } + } + } + }; + + const observer = new MutationObserver(mutationCallback); + observer.observe(messages, config); + document.querySelector('.header span').addEventListener('click', (() => { + console.log(document.querySelector('.dict-paste-contents')) + })); +})(); \ No newline at end of file