Skip to content

Instantly share code, notes, and snippets.

@Sitethief
Last active October 17, 2020 20:40
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/8b0c178d7095e67227840ecfdcc32138 to your computer and use it in GitHub Desktop.
Save Sitethief/8b0c178d7095e67227840ecfdcc32138 to your computer and use it in GitHub Desktop.
Collection Queue Add script
// ==UserScript==
// @name Collection Queue Add script
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Keep pressing 'v' while using a card queue to loop trough all the cards that need to be put into a collection. It will ad them to the top most collection
// @author Sitethief of Vylixan
// @match *://www.nationstates.net/page=deck/card=*/season=*/?manage_collections=*
// @match *://www.nationstates.net/page=deck/card=*/season=*
// @grant none
// @require https://craig.global.ssl.fastly.net/js/mousetrap/mousetrap.min.js?a4098
// ==/UserScript==
/**
* Instructions: use the card query server to add cards
* Configure the collectionID variable
* Open the first card, and keep pressing v
*
**/
/*
* Keybinds:
* [v]
*/
(function() {
'use strict';
function noinput_mousetrap(event) {
if (event.target.classList.contains("mousetrap")) {
event.preventDefault();
event.stopPropagation();
}
}
// this needs to be the collection ID
let collectionID = '25399';
Mousetrap.bind(['v'], function(ev) {
noinput_mousetrap(ev);
if (!window.location.href.includes('manage_collections')) {
let infoBar = document.querySelector("p.info");
if(infoBar) {
let nextButton = document.querySelector("#next_element_button");
if (nextButton) {
nextButton.formAction = nextButton.formAction + '/template-overall=none/?manage_collections=1';
console.log(nextButton);
nextButton.click();
}
} else if (document.querySelectorAll("a.manage_collections_button").length){
document.querySelectorAll("a.manage_collections_button")[0].click()
}
} else if(window.location.href.includes('manage_collections')) {
let saveButton = document.querySelector("button.approve[name='save_collection']");
let checkboxes = document.querySelectorAll("#editcollectiontable2 > tbody > tr > td > p > input[type='checkbox'][name='selected_" + collectionID + "']");
let infoBar = document.querySelector("p.info");
let nextButton = document.querySelector("#next_element_button");
if (infoBar && nextButton) {
nextButton.click();
} else if (checkboxes.length && checkboxes[0].checked === false) {
checkboxes[0].click();
saveButton.click();
} else if(checkboxes.length && checkboxes[0].checked === true) {
// backup for when the save didn't fire
saveButton.click();
}
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment