From 3629a07e1b86709bbf48178893fa79dfcc97ef47 Mon Sep 17 00:00:00 2001 From: Francisco Penedo Date: Wed, 25 Oct 2023 00:45:06 +0200 Subject: [PATCH] Add subscribe to RSS button to Ao3 works --- ao3-subscribe.user.js | 130 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 ao3-subscribe.user.js diff --git a/ao3-subscribe.user.js b/ao3-subscribe.user.js new file mode 100644 index 0000000..182169f --- /dev/null +++ b/ao3-subscribe.user.js @@ -0,0 +1,130 @@ +// ==UserScript== +// @name ao3 subscribe to feed +// @version 1 +// @require http://crypto.stanford.edu/sjcl/sjcl.js +// @grant GM.getValue +// @grant GM.setValue +// @include https://archiveofourown.org/works/* +// ==/UserScript== +// User script for Firefox + +// Password management + +async function decodeOrPrompt(targVar, userPrompt, setValVarName, encKey) { + if (targVar) { + targVar = unStoreAndDecrypt(targVar, encKey); + } + else { + targVar = prompt( + userPrompt + ' not set for ' + location.hostname + '. Please enter it now:', + '' + ); + await GM.setValue(setValVarName, encryptAndStore(targVar, encKey)); + } + return targVar; +} + +function encryptAndStore(clearText, encKey) { + return JSON.stringify(sjcl.encrypt(encKey, clearText)); +} + +function unStoreAndDecrypt(jsonObj, encKey) { + return sjcl.decrypt(encKey, JSON.parse(jsonObj)); +} + +async function getCredentials() { + var encKey = await GM.getValue("encKey", ""); + var usr = await GM.getValue("ttrssUser", ""); + var pword = await GM.getValue("ttrssPass", ""); + + if (!encKey) { + encKey = prompt( + 'Script key not set for ' + location.hostname + '. Please enter a random string:', + '' + ); + await GM.setValue("encKey", encKey); + + usr = pword = ""; // New key makes prev stored values (if any) unable to decode. + } + usr = await decodeOrPrompt(usr, "TTRSS user", "ttrssUser", encKey); + pword = await decodeOrPrompt(pword, "TTRSS password", "ttrssPass", encKey); + return { usr: usr, pword: pword }; +} + +// Function to add a button to the