Initial commit
This commit is contained in:
commit
9b03b8f634
|
|
@ -0,0 +1 @@
|
|||
# PLEASE PLEASE PLEASE back up your dictionary, I hacked this together
|
||||
|
|
@ -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'))
|
||||
}));
|
||||
})();
|
||||
Loading…
Reference in New Issue