-
-
Save Sitethief/d2a791c9bb6c670482ccbd0db1fdbc47 to your computer and use it in GitHub Desktop.
Reopen card page after login
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name NSReloadCardPageAfterLogin | |
// @namespace sitethiefs-ns-scripts | |
// @version 0.1.experimental | |
// @description Reopen card page after login, works best combined with a login script | |
// @author Sitethief of Vylixan | |
// @copyright MIT https://opensource.org/licenses/MIT | |
// @match https://www.nationstates.net/page=deck/card=*/* | |
// @match https://www.nationstates.net/*/page=deck/card=*/* | |
// @match https://www.nationstates.net/* | |
// @match https://www.nationstates.net | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=nationstates.net | |
// @grant GM.getValue | |
// @grant GM.setValue | |
// @require https://craig.global.ssl.fastly.net/js/mousetrap/mousetrap.min.js?a4098 | |
// ==/UserScript== | |
/* | |
* Copyright (c) 2023 Sitethief <sitethief at gmail.com> | |
* This file is licensed under the MIT license. | |
* https://opensource.org/licenses/MIT for more details. | |
*/ | |
(function () { | |
'use strict'; | |
/** | |
* | |
* Start of customizable options | |
* | |
**/ | |
const key = "enter"; // Key to use, enter would work best | |
/** | |
* | |
* End of customizable options | |
* | |
**/ | |
let url = document.URL; | |
let loggedinBody = document.getElementById("loggedin"); | |
function noinput_mousetrap(event) { | |
if (event.target.classList.contains("mousetrap")) { | |
event.preventDefault(); | |
event.stopPropagation(); | |
} | |
} | |
async function recordCardPage() { | |
await GM.setValue('NSReloadCardPageAfterLogin_cardpage', url); | |
} | |
async function reopenpage() { | |
let cardpage = await GM.getValue('NSReloadCardPageAfterLogin_cardpage', null); | |
if (cardpage && !url.includes('page=deck') && cardpage.includes('page=deck')) { | |
await GM.setValue('NSReloadCardPageAfterLogin_cardpage', null); | |
window.location.href = cardpage; | |
} | |
} | |
if (loggedinBody && !url.includes('page=deck')) { | |
Mousetrap.bind([key], function (ev) { | |
noinput_mousetrap(ev); | |
reopenpage(); | |
}) | |
} else { | |
recordCardPage(); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment