Last active
June 19, 2022 08:55
-
-
Save Sitethief/660bf6100c59203181a30f1c20b16e36 to your computer and use it in GitHub Desktop.
Sitethiefs Collection Search String
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 NSCollectionSearchString | |
// @namespace sitethiefs-ns-scripts | |
// @version 0.2.3 | |
// @description Shows search string on card deck page for usage on https://azure.nsr3n.info/card_queries/submit_advanced.sh | |
// @author Sitethief of Vylixan | |
// @copyright GPLv3 https://www.gnu.org/licenses/gpl-3.0.html | |
// @match https://www.nationstates.net/*page=deck | |
// @match https://www.nationstates.net/page=deck | |
// @icon https://www.google.com/s2/favicons?domain=nationstates.net | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
/** | |
* | |
* Start of User customizable options | |
* | |
**/ | |
let showCollectionID = true; // Set to true if you want to see collection ID's next to the collections | |
/** | |
* | |
* End of User customizable options | |
* | |
**/ | |
const body = document.getElementById('loggedin'); | |
let currentNationKey = ''; | |
if (body) { | |
currentNationKey = body.dataset.nname; | |
} | |
const collectionContainer = document.querySelector('table.deckscollectionstable'); | |
if (collectionContainer) { | |
let allCollections = []; | |
let notAllCollections = []; | |
collectionContainer.querySelectorAll('a').forEach(function (anchor) { | |
let splitURL = anchor.href.split('collection='); | |
let lastPart = splitURL[1]; | |
let collectionID = lastPart.split('/')[0]; | |
if (showCollectionID) { | |
let span = document.createElement('span'); | |
span.innerHTML = ' (' + collectionID + ')'; | |
anchor.parentElement.appendChild(span); | |
allCollections.push('collection:' + collectionID); | |
notAllCollections.push('!collection:' + collectionID); | |
} | |
}); | |
let spanAll = document.createElement('span'); | |
spanAll.innerHTML = 'deck:' + currentNationKey + ' & (' + allCollections.join(' & ') + ' )'; | |
collectionContainer.parentElement.appendChild(spanAll); | |
collectionContainer.parentElement.appendChild(document.createElement('br')); | |
collectionContainer.parentElement.appendChild(document.createElement('br')); | |
let spanNotAll = document.createElement('span'); | |
spanNotAll.innerHTML = 'deck:' + currentNationKey + ' & (' + notAllCollections.join(' & ') + ' )'; | |
collectionContainer.parentElement.appendChild(spanNotAll); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment