NATION

PASSWORD

[Tampermonkey Script] NationStates Card Management Queue

The place to wheel and deal, talk shop, and build up your dream deck!
User avatar
Anozia
Secretary
 
Posts: 34
Founded: Oct 10, 2010
Democratic Socialists

[Tampermonkey Script] NationStates Card Management Queue

Postby Anozia » Sun Oct 27, 2019 8:27 am

What I did before the script:
When opening a loot box, I would junk cards I'm not interested in, and middle-click the Infos button on cards I want to load on their own page to decide what to do.

What was wrong with that:
After selling or gifting or anything on the 1st card page opened in the previous way, other card pages had to be reloaded before use, else they would reload with a security error message, and the attempted action would not have worked.

What I do with the script:
When opening a loot box, I junk cards I'm not interested in, middle-click the Info button for the 1st remaining card after that, then use the "Add to cards queue"
button from the script for the remaining cards.
Then, after doing what I had to do with the card page loaded through a middle-click, I click the "Next element in queue[X]" (where X is the number of elements in queue), that load the page of a card added to queue, removing that card from the queue.

Advantages:
For player, no more unnecessary reload to do, or security error to face.
For server, only send the card page once.

Script code:
Code: Select all
// ==UserScript==
// @name         NationStates Card Management Queue
// @namespace    NS_Cards_Queue_Script
// @version      1.0
// @description  A queue to put the url of cards from packs and load them later from another card
// @author       Anozia
// @match        https://www.nationstates.net/page=deck
// @match        https://www.nationstates.net/page=deck/card=*
// @run-at       document-idle
// @grant        GM.getValue
// @grant        GM.setValue
// @grant        GM.deleteValue
// ==/UserScript==

(async function() {

    var button_elt;
    var div_elt;
    var i;

    if(window.location.href == "https://www.nationstates.net/page=deck") { //deck page, may be lootbox page or another

        var p_elts = document.getElementsByTagName("p");
        var is_on_lootbox_page = false;

        for(i = 0; i < p_elts.length && !is_on_lootbox_page; i++) {
            if(p_elts[i].textContent == "Tap cards to reveal...") {
                is_on_lootbox_page = true;
            }
        }

        if(is_on_lootbox_page) { //lootbox page confirmed

            var card_elts = document.getElementsByClassName("deckcard-info-cardlink");

            for(i = 0; i < card_elts.length; i++) {

                button_elt = document.createElement("button");
                button_elt.textContent = "Add to cards queue";
                button_elt.addEventListener('click',add_in_queue,false);

                div_elt = document.createElement("div");
                div_elt.appendChild(button_elt);

                card_elts[i].parentNode.insertBefore(div_elt,card_elts[i]);

            }

        }

    }
    else { //single card page

        var queue_holder = await GM.getValue("NS_Cards_Queue", null);

        if(queue_holder != null) { //get the existing queue

            queue_holder = JSON.parse(queue_holder);

            //only create the button if the queue is not empty
            if(queue_holder.length != 0) {

                try {

                    var existing_elt = document.getElementById("deck-single-card");

                    button_elt = document.createElement("button");
                    button_elt.textContent = "Next element in queue[" + queue_holder.length + "]";
                    button_elt.addEventListener('click',get_next_element_in_queue,false);

                    div_elt = document.createElement("div");
                    div_elt.style["justify-content"] = "center";
                    div_elt.style["display"] = "flex";

                    div_elt.appendChild(button_elt);

                    existing_elt.parentNode.insertBefore(div_elt,existing_elt);

                }
                catch(exc) {}

            }

        }

    }

    async function get_next_element_in_queue(click_event) {

        click_event.target.removeEventListener('click',get_next_element_in_queue,false);

        try {

            var queue_holder = JSON.parse(await GM.getValue("NS_Cards_Queue", null));

            var queue_element = queue_holder.shift(); //get and remove first element in queue

            if(queue_holder.length != 0) {
                await GM.setValue("NS_Cards_Queue",JSON.stringify(queue_holder)); //store back updated queue
            }
            else {
                await GM.deleteValue("NS_Cards_Queue"); //delete queue storage if empty
            }

            click_event.target.parentNode.parentNode.removeChild(click_event.target.parentNode); //remove the div containing the button

            window.location = queue_element; //go to the page of next element in queue

        }
        catch(exc) { //could happen if queue is emptied from another tab, just remove the button in this case
            click_event.target.parentNode.parentNode.removeChild(click_event.target.parentNode); //remove the div containing the button
        }

    }

    async function add_in_queue(click_event) {

        click_event.target.removeEventListener('click',add_in_queue,false);

        var queue_holder = await GM.getValue("NS_Cards_Queue", null);

        if(queue_holder == null) { //create the new empty queue
            queue_holder = [];
        }
        else { //get the existing queue
            queue_holder = JSON.parse(queue_holder);
        }

        try {
            //add link to card info to queue
            queue_holder.push(click_event.target.parentNode.nextElementSibling.firstElementChild.getAttribute("href")); //button.div.infobutton.link.getAttribute("href")
            click_event.target.textContent = "Card added to queue";
            click_event.target.disabled = true;
        }
        catch(exc) {
            click_event.target.textContent = "Error";
            click_event.target.disabled = true;
        }

        await GM.setValue("NS_Cards_Queue",JSON.stringify(queue_holder)); //store back updated queue

    }

})();


Technicalities:
-The GM methods are used, because other methods of storage would not work with Firefox 69 in permanent privacy mode.
-The queue only store urls that aren't tied to a nation.
-When the last card is taken out of the queue, the queue is removed from storage.The idea would be to prevent the data to be written to disk.No idea if that's what really happen.

I don't really like web programming or javascript, but I hope I still managed to make something that can be useful to some.

User avatar
Destructive Government Economic System
Minister
 
Posts: 3225
Founded: Jun 15, 2017
Corporate Police State

Postby Destructive Government Economic System » Sun Dec 15, 2019 7:40 pm

This is actually a good tool.

However, the inconvenience of using this is the fact that the queue only applies to opening packs.

Therefore, after very slightly tweaking the code, the script now works on your nation's deck page as well:

Code: Select all
// ==UserScript==
// @name         NationStates Card Management Queue For Deck Page AND Opening Packs
// @namespace    NS_Cards_Queue_Script
// @version      1.0
// @description  A queue to put the url of cards from packs and load them later from another card
// @author       Anozia
// @match        https://www.nationstates.net/page=deck
// @match        https://www.nationstates.net/page=deck/card=*
// @run-at       document-idle
// @grant        GM.getValue
// @grant        GM.setValue
// @grant        GM.deleteValue
// ==/UserScript==

(async function() {

    var button_elt;
    var div_elt;
    var i;

    if(window.location.href == "https://www.nationstates.net/page=deck") { //deck page, may be lootbox page or another

        var p_elts = document.getElementsByTagName("p");
        var is_on_deck_page = true;

        for(i = 0; i < p_elts.length && !is_on_deck_page; i++) {
            if(p_elts[i].textContent == "Tap cards to reveal...") {
                is_on_deck_page = false;
            }
        }

        if(is_on_deck_page) { //deck page confirmed

            var card_elts = document.getElementsByClassName("deckcard-info-cardlink");

            for(i = 0; i < card_elts.length; i++) {

                button_elt = document.createElement("button");
                button_elt.textContent = "Add to cards queue";
                button_elt.addEventListener('click',add_in_queue,false);

                div_elt = document.createElement("div");
                div_elt.appendChild(button_elt);

                card_elts[i].parentNode.insertBefore(div_elt,card_elts[i]);

            }

        }

    }
    else { //single card page

        var queue_holder = await GM.getValue("NS_Cards_Queue", null);

        if(queue_holder != null) { //get the existing queue

            queue_holder = JSON.parse(queue_holder);

            //only create the button if the queue is not empty
            if(queue_holder.length != 0) {

                try {

                    var existing_elt = document.getElementById("deck-single-card");

                    button_elt = document.createElement("button");
                    button_elt.textContent = "Next element in queue[" + queue_holder.length + "]";
                    button_elt.addEventListener('click',get_next_element_in_queue,false);

                    div_elt = document.createElement("div");
                    div_elt.style["justify-content"] = "center";
                    div_elt.style["display"] = "flex";

                    div_elt.appendChild(button_elt);

                    existing_elt.parentNode.insertBefore(div_elt,existing_elt);

                }
                catch(exc) {}

            }

        }

    }

    async function get_next_element_in_queue(click_event) {

        click_event.target.removeEventListener('click',get_next_element_in_queue,false);

        try {

            var queue_holder = JSON.parse(await GM.getValue("NS_Cards_Queue", null));

            var queue_element = queue_holder.shift(); //get and remove first element in queue

            if(queue_holder.length != 0) {
                await GM.setValue("NS_Cards_Queue",JSON.stringify(queue_holder)); //store back updated queue
            }
            else {
                await GM.deleteValue("NS_Cards_Queue"); //delete queue storage if empty
            }

            click_event.target.parentNode.parentNode.removeChild(click_event.target.parentNode); //remove the div containing the button

            window.location = queue_element; //go to the page of next element in queue

        }
        catch(exc) { //could happen if queue is emptied from another tab, just remove the button in this case
            click_event.target.parentNode.parentNode.removeChild(click_event.target.parentNode); //remove the div containing the button
        }

    }

    async function add_in_queue(click_event) {

        click_event.target.removeEventListener('click',add_in_queue,false);

        var queue_holder = await GM.getValue("NS_Cards_Queue", null);

        if(queue_holder == null) { //create the new empty queue
            queue_holder = [];
        }
        else { //get the existing queue
            queue_holder = JSON.parse(queue_holder);
        }

        try {
            //add link to card info to queue
            queue_holder.push(click_event.target.parentNode.nextElementSibling.firstElementChild.getAttribute("href")); //button.div.infobutton.link.getAttribute("href")
            click_event.target.textContent = "Card added to queue";
            click_event.target.disabled = true;
        }
        catch(exc) {
            click_event.target.textContent = "Error";
            click_event.target.disabled = true;
        }

        await GM.setValue("NS_Cards_Queue",JSON.stringify(queue_holder)); //store back updated queue

    }

})();


If you click on any (already-existing) cards on your deck page, you should be able to add them to the queue, along with the cards you added from opening packs. This is particularly useful when you're trying to sell a bunch of cards in a short amount of time.

As an example, here is me adding 2 cards to the queue. The first added one came from a recently-opened pack:

Image


... while the second one comes from a card that's been laying around in my deck page:

Image


After adding them, I go to a random card and do whatever with it. The 2 queued cards should then display after pulling up the random card's page:

Image


Click the "next element in queue" button to go the cards you added in queue:

Image
Image


(The queue button is removed once you get to the very last card in said queue.)




As the OP mentioned, you will need to use the Tampermonkey extension to get this working. After installing Tampermonkey, click on the extension's icon, go to "create a new script", copy and paste the code provided, and save the file. The script should automatically work after saving, and you will be free to disable it at any time by clicking the extension icon, going to "dashboard", and turning off the script.

Hope this helps anyone.
"All I wish is to see the world burn."
-The Great Uniter and Beast of the DGES
(By the way, the DGES is a servant to DEAREST LEADER of Psychotic Dictatorships.)
Just your typical guy who wants to have fun. Don't take this nation seriously,
ever.
I DO NOT use NS stats!
Keshiland literally wrote:I would give it a no. A country that lies about how free, or how great, or how humanitarian it is can never be developed. Example, NK lies and says they are democratic and are not, the US lies and says we are free yet we incarcerate millions for a medical plant. See we are basically a larger more populated North Korea.


ALSO, READ THIS!

User avatar
9003
Chargé d'Affaires
 
Posts: 384
Founded: Oct 25, 2012
Father Knows Best State

Postby 9003 » Thu Dec 19, 2019 8:51 am

Love this! thank you super much

One idea/suggestion/how could I do it on my own :P

this works great for farming and listing every card and processing on the puppets. but I still have to re add them all to it when I am on my main. Is there a way for it to save a list temporarily or more permanently in a file. Even if it just prints each link in the terminal?
proud member of PETZ people for the Ethical Treatment of Zombies

Active member of The cards market place discord

User avatar
Ter Voland
Secretary
 
Posts: 35
Founded: Feb 14, 2018
Capitalist Paradise

Postby Ter Voland » Thu Dec 19, 2019 10:02 am

Finally tried this. Thank you Anozia and DGES. It's really useful. :)

User avatar
Recuecn
Diplomat
 
Posts: 736
Founded: Feb 02, 2015
Liberal Democratic Socialists

Postby Recuecn » Thu Dec 19, 2019 10:03 am

Thanks for this! I was just thinking about this before this thread got bumped and this is going to come in super useful.

I'd also be interested in the update 9003 requested, since why not, but I'm not sure it would be as useful for me in particular since I know for a fact I don't sell nearly as many cards to myself as he does lol. If you're just selling cards that happen to have bids on them or even gifting to yourself then you don't need a way to find those cards back as badly.
rəswɛsən

User avatar
Recuecn
Diplomat
 
Posts: 736
Founded: Feb 02, 2015
Liberal Democratic Socialists

Postby Recuecn » Fri Dec 20, 2019 1:39 am

One feature that would make this even better would be if it worked with the new deck filters. It doesn't for me I think that's because the url starts off as "nationstates.net/nation=cahds_20/page=deck" with the nation name in there, rather than just "nationstates.net/page=deck"

I assume (I hope, at least!) that this is a pretty easy fix and can be done with wildcards, but I don't know/remember enough about coding to fix it myself. Could this feature be added please?
rəswɛsən

User avatar
Anozia
Secretary
 
Posts: 34
Founded: Oct 10, 2010
Democratic Socialists

Postby Anozia » Sun Mar 29, 2020 1:17 am

I'm afraid I can't help much on requested features, as they often require a list rather than a queue, so it should not be build on this exact system to begin with.
For those interested, I will show my latest version of my script, that got side-tracked but may be informative:
Code: Select all
// ==UserScript==
// @name         NationStates Card Management Queue
// @namespace    NS_Cards_Queue_Script
// @version      1.1
// @description  A queue to put the url of cards from packs and load them later from another card
// @author       Anozia
// @match        https://www.nationstates.net/*
// @run-at       document-idle
// @grant        GM.getValue
// @grant        GM.setValue
// @grant        GM.deleteValue
// ==/UserScript==

(async function() {

    var button_elt;
    var div_elt;
    var i;
    var cards_button_top;

    try {
        if(!cards_button_top) {
            let queue_holder = JSON.parse(await GM.getValue("NS_Cards_Queue", null));
            cards_button_top = document.createElement("div");
            cards_button_top.setAttribute('class',"bel");
            if(queue_holder !== null && queue_holder.length > 0) {
                cards_button_top.innerHTML = "<div class=\"belcontent\"><a href=\"/page=deck\" class=\"bellink\"><i class=\"icon-cards\"></i>CARDS</a><div class=\"notificationnumber refreshable\" style=\"background-color:green\">" + queue_holder.length + "</div></div>";
            }
            else {
                cards_button_top.innerHTML = "<div class=\"belcontent\"><a href=\"/page=deck\" class=\"bellink\"><i class=\"icon-cards\"></i>CARDS</a></div>";
            }
        }

        (document.getElementsByClassName("belspacer belspacermain")[0]).before(cards_button_top);

    }
    catch(exc) {}

    if(window.location.href == "https://www.nationstates.net/page=deck") { //deck page, may be lootbox page or another

        var p_elts = document.getElementsByTagName("p");
        var is_on_lootbox_page = false;

        for(i = 0; i < p_elts.length && !is_on_lootbox_page; i++) {
            if(p_elts[i].textContent == "Tap cards to reveal...") {
                is_on_lootbox_page = true;
            }
        }

        if(is_on_lootbox_page) { //lootbox page confirmed

            var card_elts = document.getElementsByClassName("deckcard-info-cardlink");

            for(i = 0; i < card_elts.length; i++) {

                button_elt = document.createElement("button");
                button_elt.textContent = "Add to cards queue";
                button_elt.addEventListener('click',add_in_queue,false);

                div_elt = document.createElement("div");
                div_elt.appendChild(button_elt);

                card_elts[i].parentNode.insertBefore(div_elt,card_elts[i]);

            }

        }

    }
    else
    if(window.location.href.startsWith("https://www.nationstates.net/page=deck/card=")) { //single card page

        let queue_holder = await GM.getValue("NS_Cards_Queue", null);

        if(queue_holder != null) { //get the existing queue

            queue_holder = JSON.parse(queue_holder);

            //only create the button if the queue is not empty
            if(queue_holder.length != 0) {

                try {

                    var existing_elt = document.getElementById("deck-single-card");

                    button_elt = document.createElement("button");
                    button_elt.textContent = "Next element in queue[" + queue_holder.length + "]";
                    button_elt.addEventListener('click',get_next_element_in_queue,false);

                    div_elt = document.createElement("div");
                    div_elt.style["justify-content"] = "center";
                    div_elt.style["display"] = "flex";

                    div_elt.appendChild(button_elt);

                    existing_elt.parentNode.insertBefore(div_elt,existing_elt);

                }
                catch(exc) {}

            }

        }

    }

    let cards_flags = document.getElementsByClassName("deckcard-flag");

    for(i = 0; i < cards_flags.length; i++) {
        cards_flags[i].addEventListener("click",toggleCardTitle,false);
    }

    function toggleCardTitle(event) {
        let card_title_element = event.target.parentNode.getElementsByClassName("deckcard-title");
        if(card_title_element.length != 0) {
            if(card_title_element[0].style.visibility == "hidden") {
                card_title_element[0].style.visibility = "visible";
            }
            else {
                card_title_element[0].style.visibility = "hidden";
            }
        }
    }

    async function get_next_element_in_queue(click_event) {

        click_event.target.removeEventListener('click',get_next_element_in_queue,false);

        try {

            let queue_holder = JSON.parse(await GM.getValue("NS_Cards_Queue", null));

            let queue_element = queue_holder.shift(); //get and remove first element in queue

            if(queue_holder.length != 0) {
                await GM.setValue("NS_Cards_Queue",JSON.stringify(queue_holder)); //store back updated queue
            }
            else {
                await GM.deleteValue("NS_Cards_Queue"); //delete queue storage if empty
            }

            click_event.target.parentNode.parentNode.removeChild(click_event.target.parentNode); //remove the div containing the button

            window.location = queue_element; //go to the page of next element in queue

        }
        catch(exc) { //could happen if queue is emptied from another tab, just remove the button in this case
            click_event.target.parentNode.parentNode.removeChild(click_event.target.parentNode); //remove the div containing the button
        }

    }

    async function add_in_queue(click_event) {

        click_event.target.removeEventListener('click',add_in_queue,false);

        let queue_holder = await GM.getValue("NS_Cards_Queue", null);

        if(queue_holder == null) { //create the new empty queue
            queue_holder = [];
        }
        else { //get the existing queue
            queue_holder = JSON.parse(queue_holder);
        }

        try {
            //add link to card info to queue
            queue_holder.push(click_event.target.parentNode.nextElementSibling.firstElementChild.getAttribute("href")); //button.div.infobutton.link.getAttribute("href")
            click_event.target.textContent = "Card added to queue";
            click_event.target.disabled = true;
        }
        catch(exc) {
            click_event.target.textContent = "Error";
            click_event.target.disabled = true;
        }

        await GM.setValue("NS_Cards_Queue",JSON.stringify(queue_holder)); //store back updated queue

    }

})();


Features:
-A new card button appearing at top of screen to quickly go to the main cards page from anywhere
-When there are cards in the queue, a green indicator appear on that button (I needed that to not leave cards in a queue before leaving a nation :p )
-A different approach (not "match" at top of script) to recognize which page I'm on (may be useful for some requests) in the code.
-A completely unrelated feature to be able to click the upper part of a flag of a season 2 card (where the cursor doesn't turn into a hand) to toggle the
visibility of the nation name (to fully enjoy the flag design :) )
Last edited by Anozia on Sun Mar 29, 2020 1:19 am, edited 1 time in total.

User avatar
Recuecn
Diplomat
 
Posts: 736
Founded: Feb 02, 2015
Liberal Democratic Socialists

Postby Recuecn » Wed Apr 08, 2020 3:53 am

First off, let me say that I love the new features Anozia. I'd been thinking just recently, before you posted the update, that it would be nice sometimes to be able to see the whole card and hide the info on top, and I'm already finding the new button at the top of the screen super handy.

However, I also found that I'd been spoiled by DGES' version where the script could run on the deck page too. Often I open packs all at once and go back to sort through the cards later, so it wasn't really worth giving up on the deck page functionality for the cool new bells and whistles. Also, I find that the best way for me to quickly identify which cards might be worth selling if by looking at the value page. So I asked DGES if it might be possible to combine the deck page functionality of his version with Anozia's latest upgrades, and maybe even add some new features. As always, DGES was incredibly gracious and looked into it for me, but in the end suggested running both scripts at once and, although he did find a way to make the script work on deck pages other than the first (which it didn't before), couldn't figure out all the new capabilities I wanted—which was fair, I was asking for quite a few things. So I turned to Racoda and "commissioned" a new version of the script to combine DGES' deck page feature with all of Anozia's features, plus the new features I wanted. Below is the result. All my thanks to Racoda, Anozia, and DGES for this. It's really nice of all of them to share their time and effort with the community in this way. I've done none of the actual coding here.

Code: Select all
// ==UserScript==
// @namespace    NS_Cards_Queue_Script
// @name         Anozia feat. RCSA & DGES - Reçu's Feature Requests
// @version      1.1
// @description  A queue to put the url of cards from packs and load them later from another card
// @author       Anozia
// @contributors Racoda and DGES
// @match        https://www.nationstates.net/*
// @run-at       document-idle
// @grant        GM.getValue
// @grant        GM.setValue
// @grant        GM.deleteValue
// ==/UserScript==

(async function() {

    var button_elt;
    var div_elt;
    var i;
    var cards_button_top;

    try {
        if(!cards_button_top) {
            let queue_holder = JSON.parse(await GM.getValue("NS_Cards_Queue", null));
            cards_button_top = document.createElement("div");
            cards_button_top.setAttribute('class',"bel");
            if(queue_holder !== null && queue_holder.length > 0) {
                cards_button_top.innerHTML = "<div class=\"belcontent\"><a href=\"/page=deck\" class=\"bellink\"><i class=\"icon-cards\"></i>CARDS</a><div class=\"notificationnumber refreshable\" style=\"background-color:green\">" + queue_holder.length + "</div></div>";
            }
            else {
                cards_button_top.innerHTML = "<div class=\"belcontent\"><a href=\"/page=deck\" class=\"bellink\"><i class=\"icon-cards\"></i>CARDS</a></div>";
            }
        }

        (document.getElementsByClassName("belspacer belspacermain")[0]).before(cards_button_top);

    }
    catch(exc) {}

    if(window.location.href.startsWith("https://www.nationstates.net/page=deck/card=")) { //single card page

        let queue_holder = await GM.getValue("NS_Cards_Queue", null);

        if(queue_holder != null) { //get the existing queue

            queue_holder = JSON.parse(queue_holder);

            //only create the button if the queue is not empty
            if(queue_holder.length != 0) {

                try {

                    var existing_elt = document.getElementById("deck-single-card");

                    button_elt = document.createElement("button");
                    button_elt.textContent = "Next element in queue[" + queue_holder.length + "]";
                    button_elt.addEventListener('click',get_next_element_in_queue,false);

                    div_elt = document.createElement("div");
                    div_elt.style["justify-content"] = "center";
                    div_elt.style["display"] = "flex";

                    div_elt.appendChild(button_elt);

                    existing_elt.parentNode.insertBefore(div_elt,existing_elt);

                }
                catch(exc) {}

            }

        }

    }
    else
    if(window.location.href.startsWith("https://www.nationstates.net/page=deck")
     ||window.location.href.match(/https:\/\/www\.nationstates\.net\/(nation|container)=[A-Za-z0-9_-]+\/page=deck/)) { //deck page, may be lootbox page or another
        if (window.location.href.includes("/value_deck=1")) {
            var card_link_elts = document.getElementsByClassName("cardnameblock");
            for(i = 0; i < card_link_elts.length; i++) {
                button_elt = document.createElement("button");
                button_elt.textContent = "Add to cards queue";
                button_elt.addEventListener('click',add_in_queue_valdeck,false);
                button_elt.classList.add("deckcard-token");
                card_link_elts[i].parentNode.insertBefore(button_elt,card_link_elts[i]);
            }

        } else {
            var p_elts = document.getElementsByTagName("p");
            var is_on_lootbox_page = false;

            for(i = 0; i < p_elts.length && !is_on_lootbox_page; i++) {
                if(p_elts[i].textContent == "Tap cards to reveal...") {
                    is_on_lootbox_page = true;
                }
            }

            // Unneeded condition
            // if(is_on_lootbox_page) { //lootbox page confirmed

                var card_elts = document.getElementsByClassName("deckcard-info-cardlink");

                for(i = 0; i < card_elts.length; i++) {

                    button_elt = document.createElement("button");
                    button_elt.textContent = "Add to cards queue";
                    button_elt.addEventListener('click',add_in_queue,false);

                    div_elt = document.createElement("div");
                    div_elt.appendChild(button_elt);

                    card_elts[i].parentNode.insertBefore(div_elt,card_elts[i]);

                }

            // }
        }

    }

    let cards_flags = document.getElementsByClassName("deckcard-flag");

    for(i = 0; i < cards_flags.length; i++) {
        cards_flags[i].addEventListener("click",toggleCardTitle,false);
    }

    function toggleCardTitle(event) {
        let card_title_element = event.target.parentNode.getElementsByClassName("deckcard-title");
        if(card_title_element.length != 0) {
            if(card_title_element[0].style.visibility == "hidden") {
                card_title_element[0].style.visibility = "visible";
            }
            else {
                card_title_element[0].style.visibility = "hidden";
            }
        }
    }

    async function get_next_element_in_queue(click_event) {

        click_event.target.removeEventListener('click',get_next_element_in_queue,false);

        try {

            let queue_holder = JSON.parse(await GM.getValue("NS_Cards_Queue", null));

            let queue_element = queue_holder.shift(); //get and remove first element in queue

            if(queue_holder.length != 0) {
                await GM.setValue("NS_Cards_Queue",JSON.stringify(queue_holder)); //store back updated queue
            }
            else {
                await GM.deleteValue("NS_Cards_Queue"); //delete queue storage if empty
            }

            click_event.target.parentNode.parentNode.removeChild(click_event.target.parentNode); //remove the div containing the button

            window.location = queue_element; //go to the page of next element in queue

        }
        catch(exc) { //could happen if queue is emptied from another tab, just remove the button in this case
            click_event.target.parentNode.parentNode.removeChild(click_event.target.parentNode); //remove the div containing the button
        }

    }

    async function add_in_queue_valdeck(click_event) {

        click_event.target.removeEventListener('click',add_in_queue,false);

        let queue_holder = await GM.getValue("NS_Cards_Queue", null);

        if(queue_holder == null) { //create the new empty queue
            queue_holder = [];
        }
        else { //get the existing queue
            queue_holder = JSON.parse(queue_holder);
        }

        try {
            //add link to card info to queue
            queue_holder.push(click_event.target.nextElementSibling.getAttribute("href")); //button.div.infobutton.link.getAttribute("href")
            click_event.target.textContent = "Card added to queue";
            click_event.target.disabled = true;
        }
        catch(exc) {
            click_event.target.textContent = "Error";
            click_event.target.disabled = true;
        }

        await GM.setValue("NS_Cards_Queue",JSON.stringify(queue_holder)); //store back updated queue

    }


    async function add_in_queue(click_event) {

        click_event.target.removeEventListener('click',add_in_queue,false);

        let queue_holder = await GM.getValue("NS_Cards_Queue", null);

        if(queue_holder == null) { //create the new empty queue
            queue_holder = [];
        }
        else { //get the existing queue
            queue_holder = JSON.parse(queue_holder);
        }

        try {
            //add link to card info to queue
            queue_holder.push(click_event.target.parentNode.nextElementSibling.firstElementChild.getAttribute("href")); //button.div.infobutton.link.getAttribute("href")
            click_event.target.textContent = "Card added to queue";
            click_event.target.disabled = true;
        }
        catch(exc) {
            click_event.target.textContent = "Error";
            click_event.target.disabled = true;
        }

        await GM.setValue("NS_Cards_Queue",JSON.stringify(queue_holder)); //store back updated queue

    }

})();

Features:
  • Shortcut to deck page at top of screen
  • Card processing queue
  • Icon to show how many cards are in queue
  • Hide (and unhide) card info to view flag
  • Works when opening packs
  • Works on deck page
  • Works on value page
  • Works with deck filters
  • Works on all pages of deck
  • Works with firefox containers
  • Any combination of the above
rəswɛsən

User avatar
Destructive Government Economic System
Minister
 
Posts: 3225
Founded: Jun 15, 2017
Corporate Police State

Postby Destructive Government Economic System » Wed Apr 08, 2020 8:31 am

Beautiful. Absolutely beautiful.

Now we're getting somewhere! Definitely something many players will try using now o.0

Anozia, Resu, and Racoda, thanks for all of your help; y'all have really worked to bring out the potential of this tool 8)
"All I wish is to see the world burn."
-The Great Uniter and Beast of the DGES
(By the way, the DGES is a servant to DEAREST LEADER of Psychotic Dictatorships.)
Just your typical guy who wants to have fun. Don't take this nation seriously,
ever.
I DO NOT use NS stats!
Keshiland literally wrote:I would give it a no. A country that lies about how free, or how great, or how humanitarian it is can never be developed. Example, NK lies and says they are democratic and are not, the US lies and says we are free yet we incarcerate millions for a medical plant. See we are basically a larger more populated North Korea.


ALSO, READ THIS!


Advertisement

Remove ads

Return to Trading Cards

Who is online

Users browsing this forum: Destructive Government Economic System

Advertisement

Remove ads