diff --git a/fallen-london-action-counter/fallen-london-action-counter-beta.user.js b/fallen-london-action-counter/fallen-london-action-counter-beta.user.js new file mode 100644 index 0000000..949c063 --- /dev/null +++ b/fallen-london-action-counter/fallen-london-action-counter-beta.user.js @@ -0,0 +1,132 @@ +// ==UserScript== +// @name Fallen London Action Counter Beta +// @namespace https://github.com/ToostInc/userscripts +// @description Notifies user when actions have been regained +// @include /^https?:\/\/(www.)?fallenlondon\.com(\/(login)?)?$/ +// @author Joost Bremmer < contact at made of magic and wires dot online > +// @copyright 2019, Joost Bremmer +// @license MIT +// @version 2.0 +// @date 2019-10-11 +// @downloadURL https://github.com/MadeOfMagicAndWires/userscripts/raw/master/fallen-london-action-counter/fallen-london-action-counter.user.js +// @updateURL https://github.com/MadeOfMagicAndWires/userscripts/raw/master/fallen-london-action-counter/fallen-london-action-counter.user.js +// @grant GM_log +// @grant GM_getValue +// @grant GM_setValue +// @grant GM_xmlhttpRequest +// @run-at document-end +// ==/UserScript== + +/* + * Userscript that notifies the user when their actions have refilled + * Copyright © 2019 Joost Bremmer + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* global GM_getValue, GM_log, GM_setValue, GM_xmlhttpRequest*/ +"use strict"; + + +/* eslint-disable camelcase */ + +/** + * Prints debug messages if the verbose flag is set to true + * + * @param {String} msg the message to print to the console + * @return {undefined} + */ +function GM_debug(msg) { + const config = GM_getValue("config", null); + console.log(config); + + if(config && config.verbose) { + GM_log(msg); + } +} + + +async function getAuthorizationToken(response) { + if(response.status === 200) { + let jsonResponse = await JSON.parse(response.responseText); + + if(jsonResponse.jwt) { + GM_debug(`Found Authorization bearer: ${jsonResponse.jwt}`); + return jsonResponse.jwt; + } else { + return null; + } + } else if (response.status === 401) { + alert("Failed to log in; credentials were not correct"); + } else { + alert(`Failed to log in: status code ${response.status}`); + } +} + +async function getAuthorizationError(response) { + GM_debug(`Failed to log in: status code ${response.status}`); +} + +async function getCredentials() { + GM_xmlhttpRequest({ + "url" : "https://api.fallenlondon.com/api/login", + "method" : "POST", + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + }, + "data" : JSON.stringify({ + "email": await window.prompt("Please provide account e-mail", ""), + "password": await window.prompt("Please provide password", "") + }), + "onload": getAuthorizationToken, + "onerror": getAuthorizationError + }); +} + +function setUpConfig() { + let config = GM_getValue("config", null); + let configChanged = false; + + if(config === null) { + GM_log("First run, setting up default settings"); + + config = { "verbose" : false }; + } + if(!config.users) { + getCredentials(); + } + + if(configChanged) { + GM_setValue("config", config); + } +} + +/** + * Sets all settings to default if they are not present and sets up + * MutationObserver + * + * @return {undefined} + */ +function main() { + GM_debug("Start"); + setUpConfig(); +} + +main(); diff --git a/fallen-london-wiki-links/fallen-london-wiki-linking.meta.js b/fallen-london-wiki-links/fallen-london-wiki-linking.meta.js index d1ff480..45baa51 100644 --- a/fallen-london-wiki-links/fallen-london-wiki-linking.meta.js +++ b/fallen-london-wiki-links/fallen-london-wiki-linking.meta.js @@ -6,7 +6,7 @@ // @include /^https:\/\/(www\.)?fallenlondon\.com(\/(login)?)?$/ // @match https://www.fallenlondon.com/ // @version 2.7 -// @date 2019-10-11 +// @date 2021-03-16 // @grant none // @grant GM_log // @grant GM_setValue diff --git a/fallen-london-wiki-links/fallen-london-wiki-linking.user.js b/fallen-london-wiki-links/fallen-london-wiki-linking.user.js index 5163eaa..aa5bb4b 100644 --- a/fallen-london-wiki-links/fallen-london-wiki-linking.user.js +++ b/fallen-london-wiki-links/fallen-london-wiki-linking.user.js @@ -6,7 +6,7 @@ // @include /^https:\/\/(www\.)?fallenlondon\.com(\/(login)?)?$/ // @match https://www.fallenlondon.com/ // @version 2.7 -// @date 2019-10-11 +// @date 2021-03-16 // @grant none // @grant GM_log // @grant GM_setValue @@ -32,7 +32,7 @@ function GM_debug(msg) { /* eslint-enable camelcase */ /** - * Encodes strings to wikia compatible url naming scheme + * Encodes strings to wiki compatible url naming scheme * @param {String} s: string to encode * @return {String} encoded stirng **/ @@ -44,7 +44,7 @@ function encodeLink(s) { } /** - * Inserts links to relevant wikia page into storylet headers + * Inserts links to relevant wiki page into storylet headers * * @param {HTMLCollection} elements storylet header elements to add links to * @return {undefined} @@ -57,7 +57,7 @@ function insertLink(elements) { let name = header.innerText; let link = document.createElement("a"); - link.href = `https://fallenlondon.wikia.com/wiki/ ${encodeLink(name)}`; + link.href = `https://fallenlondon.wiki/wiki/${encodeLink(name)}`; link.style.color = "#282520"; link.innerText = name;