Skip to content

Instantly share code, notes, and snippets.

@Sitethief
Last active November 14, 2022 20:02
Show Gist options
  • Save Sitethief/1875af79d463084b5891732d36f7367b to your computer and use it in GitHub Desktop.
Save Sitethief/1875af79d463084b5891732d36f7367b to your computer and use it in GitHub Desktop.
Adds cards to a single collection
// ==UserScript==
// @name NSMassCollectionAdd
// @namespace sitethiefs-ns-scripts
// @version 0.2
// @description Adds cards to a single collection
// @author Sitehief of Vylixan
// @match *www.nationstates.net/page=deck
// @match *www.nationstates.net/page=deck*
// @match *www.nationstates.net/*/page=deck*
// @match *www.nationstates.net/*/page=deck
// @grant none
// @require https://craig.global.ssl.fastly.net/js/mousetrap/mousetrap.min.js?a4098
// ==/UserScript==
/*
* Keybinds:
* [v] for add and save / go to next page
*/
(function() {
'use strict';
function noinput_mousetrap(event) {
if (event.target.classList.contains("mousetrap")) {
event.preventDefault();
event.stopPropagation();
}
}
if (window.location.href.includes('collection=')) {
Mousetrap.bind(['v'], function(ev) {
noinput_mousetrap(ev);
let checkboxes = document.querySelectorAll('input:not(:checked):not([name="autologin"])[type="checkbox"]');
if (checkboxes.length) {
let saveButton = document.querySelector("button.approve[name='save_collection']");
checkboxes.forEach(function (checkbox) {
checkbox.click();
});
saveButton.click();
} else if (!checkboxes.length) {
let nextArrows = document.querySelectorAll('a.pagpage-arrow');
let lastArrow = nextArrows[nextArrows.length - 1];
if (lastArrow.innerHTML === '»') {
lastArrow.click();
}
}
});
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment