Skip to content

Instantly share code, notes, and snippets.

@Sitethief
Last active June 19, 2022 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sitethief/660bf6100c59203181a30f1c20b16e36 to your computer and use it in GitHub Desktop.
Save Sitethief/660bf6100c59203181a30f1c20b16e36 to your computer and use it in GitHub Desktop.
Sitethiefs Collection Search String
// ==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