Instructions on how to quickly search for a specific deck in your deck constructor and load it automatically

If you have a suggestion for the site, create a topic here and telll us about it
Christen57
User avatar
Posts: 2033
Joined: Sun May 07, 2017 10:37 pm
Reputation: 182
Location: New York, United States of America

Instructions on how to quickly search for a specific deck in your deck constructor and load it automatically

Post #1 by Christen57 » Thu Mar 04, 2021 5:38 pm

If you're like me, you may have dozens, if not hundreds, of decks in your deck constructor.

Image

If you have hundreds of decks in your deck constructor like I do, you know how tedious it can get when you are trying to find and access a specific deck but have to scroll through dozens, if not hundreds, of decks until you can get to the one you want, even though duelingbook automatically sorts your decks in alphabetical order.

For example, if I wanted to find my deck titled "custom karakuri" among the hundreds of decks in my deck constructor, I would have to scroll up and down quite a bit, and sometimes I would have to do this multiple times, until I spot it. I can't scroll too slow or I would take forever to get to the deck, but I can't scroll too fast either or I'll end up passing it and then having to scroll back slowly to it.

Image

If only there was a way to just type in the deck's name, hit Enter, and then have it immediately take me to that deck without me having to scroll up and down, back and forth, through hundreds of other decks...

Oh wait! There is, and I've just figured it out!

Image

As you can see, with a little bit of javascript, I can make it so that, instead of having to manually scroll through a bunch of decks to get to the deck I want, I can just click a little bookmark, type in my deck's name, or at least a part of it, then hit Enter, and then, within just 2 seconds, duelingbook will search through every single deck in my deck constructor for the first deck whose name includes whatever I typed, and it will load that deck automatically without me having to do anything else. It doesn't matter if I have a hundred decks or a thousand decks in my deck constructor. Duelingbook will search through all of them in under 2 seconds and take me straight to the first deck it finds that closely matches my search parameter.

Obviously in order for this to work, you need to make sure javascript is enabled/allowed on your browser and on duelingbook, and reload/refresh your page if you have to.

Image

Image

First, create a new bookmark (or edit an already-existing one) and name it whatever you want. I've named mine deck searcher.

Image

In the URL/Address/Location box, whatever it's called on your browser, copy and paste this entire code:

Code: Select all

javascript:var sd = prompt("Enter the name of your deck"); var dc = document.getElementById("decklist_cb"); var ov = dc.childNodes; var pp = ""; var ii; for (ii = 0; ii < ov.length; ii++) {if (ov[ii].innerHTML.includes(sd)) {pp = ii};} if (pp != "") {ov[pp].selected = true; if ("createEvent" in document) {var evt = document.createEvent("HTMLEvents"); evt.initEvent("change", false, true); dc.dispatchEvent(evt);} else dc.fireEvent("change");}undefined;


Save it and go to either your deck constructor or the duel room (this code will work in the deck constructor and the duel room since they both allow you to switch decks).

I will be demonstrating this in the deck constructor and showing you how to properly search for the deck you want.

Image

As you can see, one of the decks I have is named "custom ace attorney".

If I wanted to search for this custom ace attorney deck, first I click on the newly created/edited bookmark to bring up this little window.

Image

There are multiple ways I can tell the code to search for the custom ace attorney deck. I can type in the deck's full name custom ace attorney so it searches for the first deck that has "custom ace attorney" in it's name, or if I don't feel like typing in the full name and instead wish to type in something shorter, I can simply type "attor" and it will still bring up my custom ace attorney deck if "custom ace attorney" is the first deck in my deck constructor that has "attor" in it.

Keep in mind that if, for example, you're trying to search for a specific deck that has "attor" in it's name, but you have multiple decks with "attor" in their names, you may need to make your search parameter more specific to get to the deck you want. For example, you can see in the screenshot that I have a "custom alligator" deck, a "custom allure queen" deck, and a "custom ally of justice" deck. All of these names have "custom all" in them. If I typed "custom all" in my search box, intending to search for the custom alligator deck, I would instead be brought to the custom ally of justice deck. This is because when you have multiple decks that all meet your search parameters, the deck closest to the bottom of your deck list that meets those search parameters will be prioritized over the ones closer to the top of your deck list. In this case, the custom alligator deck is at the top, the custom allure queen deck is in the middle, and the custom ally of justice deck is at the bottom, of those 3 decks. This means that the custom ally of justice deck would come up since it's below the other 2 decks that have "custom all" in their names.

If I wanted to load the custom alligator deck specifically, I would have to be more specific in my search, such as typing "custom alli" instead of just "custom all". If I wanted to load the custom allure queen deck specifically, I would have to be more specific, such as typing "custom allu" instead of just "custom all". Alternatively, I can just type "allu" to search for the custom allure queen deck since it's faster to type than "custom allu" and since "custom allure queen" is currently my only deck with "allu" in the name, and I could type just "alli" when searching for the custom alligator deck since it's faster to type than "custom alli" and since "custom alligator" is currently my only deck with "alli" in the name.

Another thing to keep in mind is that, if you click OK or hit Enter but you leave the search bar blank, you will be taken to the very bottom deck of your deck list by default. This is because when searching through your deck list, the code starts at the very bottom and works it's way up, so if the code is made to search for the very first deck it can find, it will find the bottom one first and go with that.

Here's the code also working in the duel room.

Image

This code was tested on Google Chrome, Vivaldi, and Firefox. If you want to understand how the code works, here's a summary of how the code works. I will break the code down and explain each part of it in a way that's easy to understand.

First, we need to understand how duelingbook normally loads decks in your deck constructor.

Each user on duelingbook is assigned their own HTML <select> tag with the ID "decklist_cb". These <select> tags are basically folders that are responsible for storing decks but can be clicked on to bring up a list that the user can scroll through to select and load the deck they want.

Image

Image

Image

You can read more about HTML <select> tags here. https://www.w3schools.com/tags/tag_select.asp
In fact, this w3schools website is where I learned and practiced much of my coding that I use for duelingbook.

Now here's how my javascript code works, allowing you to search for a specific deck and go straight to it simply by typing in it's name.

javascript: - All javascript bookmark commands must begin with "javascript:" so that the browser recognizes it as a javascript command and can attempt to execute it.

var sd = prompt("Enter the name of your deck"); - This is the part of the code that brings up the little menu when the bookmark is clicked, allowing the user to type in the full or partial name of the deck they want to search.

var dc = document.getElementById("decklist_cb"); var ov = dc.childNodes; - This part of the code simply searches duelingbook for the "decklist_cb" tag (the folder that stores your decks) and all of it's children (the decks themselves).

var pp = ""; var ii; for (ii = 0; ii < ov.length; ii++) {if (ov[ii].innerHTML.includes(sd)) {pp = ii};} - This is the part of the code responsible for checking all of the decklist_cb tag's children (the decks), starting from the deck at the bottom of the list, working it's way to the deck at the very top of the list, and comparing each deck's innerHTML value (the deck's name) with what you typed in the search box. It then returns the first deck it finds, whose name contains what you typed, if there is any, and if there is, the "var pp" thing, which is the "pp" variable I used for this code, will change from a blank "" to whatever deck the code found that closely matched the search parameter.

if (pp != "") - This little part of the code checks if the previous part of code successfully found a deck that closely matches your search parameter. If it didn't, that "pp" variable will remain blank and the code will be stopped from continuing further. If it did, it moves on to the next part of the code, which is...

{ov[pp].selected = true; if ("createEvent" in document) {var evt = document.createEvent("HTMLEvents"); evt.initEvent("change", false, true); dc.dispatchEvent(evt);} else dc.fireEvent("change");} - The part of the code that gives duelingbook the name of the deck and tells duelingbook to automatically select that deck and load it.

undefined; - This part of the code is only necessary on browsers such as Firefox. It helps prevent those kinds of browsers from closing or crashing duelingbook when the bookmark is clicked.

Hopefully xteven can make searching for decks an actual official feature of duelingbook, especially since it would help those like myself who have hundreds of decks and often switch between those decks, allowing us to get to our decks faster without having to manually scroll up and down for them.

robinatk
User avatar
Posts: 91
Joined: Sun Mar 19, 2017 12:08 am
Reputation: 6

Post #2 by robinatk » Thu Mar 04, 2021 9:22 pm

This is actually genius why is no one picking it up

Christen57
User avatar
Posts: 2033
Joined: Sun May 07, 2017 10:37 pm
Reputation: 182
Location: New York, United States of America

Post #3 by Christen57 » Thu Mar 04, 2021 9:40 pm

robinatk wrote:This is actually genius why is no one picking it up


I guess you can be the first one to pick it up!

SamLi
Posts: 10
Joined: Tue Aug 27, 2019 11:41 pm
Reputation: 0

Post #4 by SamLi » Thu Mar 04, 2021 10:05 pm

imagine reading this

DuskWill
User avatar
Posts: 199
Joined: Wed Mar 01, 2017 9:27 am
Reputation: 29
Location: Brasil

Post #5 by DuskWill » Fri Mar 05, 2021 2:18 am

Awesome discovery, Christen57, as usual.
This is...
Image
I saw the strategy I need!

Jedx_EX
User avatar
Posts: 276
Joined: Tue Aug 18, 2020 4:18 pm
Reputation: 7
Location: Earth
Mood:

Post #6 by Jedx_EX » Sat Mar 06, 2021 2:17 pm

robinatk wrote:This is actually genius why is no one picking it up


I myself never have over a dozen decks in Duelingbook, but I believe there are people that uses alot, so this is a nice bookmark code to have.

Christen57
User avatar
Posts: 2033
Joined: Sun May 07, 2017 10:37 pm
Reputation: 182
Location: New York, United States of America

Post #7 by Christen57 » Sun Mar 07, 2021 10:00 pm

Jedx_EX wrote:
robinatk wrote:This is actually genius why is no one picking it up


I myself never have over a dozen decks in Duelingbook, but I believe there are people that uses alot, so this is a nice bookmark code to have.


Obviously if you have less than a few dozen decks you won't need this, but if you have at least several hundred decks like I do, this would come in handy.

Jedx_EX
User avatar
Posts: 276
Joined: Tue Aug 18, 2020 4:18 pm
Reputation: 7
Location: Earth
Mood:

Post #8 by Jedx_EX » Mon Mar 08, 2021 12:28 am

Quite an astonishing amount I should say.

Christen57
User avatar
Posts: 2033
Joined: Sun May 07, 2017 10:37 pm
Reputation: 182
Location: New York, United States of America

Post #9 by Christen57 » Wed Mar 10, 2021 8:50 pm

I updated my code to fix an error causing it to not be able to search for and automatically load the very top or very bottom deck of the decklist:

Code: Select all

javascript:var sd = prompt("Enter the name of your deck"); var dc = document.getElementById("decklist_cb"); var ov = dc.children; var pp = ""; var ii; for (ii = 0; ii < ov.length; ii++) {if (ov[ii].innerHTML.includes(sd)) {pp = ii};} ov[pp].selected = true; if ("createEvent" in document) {var evt = document.createEvent("HTMLEvents"); evt.initEvent("change", false, true); dc.dispatchEvent(evt);} else dc.fireEvent("change"); undefined;

Christen57
User avatar
Posts: 2033
Joined: Sun May 07, 2017 10:37 pm
Reputation: 182
Location: New York, United States of America

Post #10 by Christen57 » Sun Aug 20, 2023 4:29 pm

Updated my code just to make it more tidy and readable and to prevent any future conflicts where duelingbook tries to declare any of the same variables as my code.

Code: Select all

javascript:{let WhatToSearchFor = prompt("Enter the name of your deck");
let dc = document.getElementById("decklist_cb");
let Decks = dc.children;
let DeckNameMatch = "";
   for (let ii = 0; ii < Decks.length; ii++) {
      if (Decks[ii].innerHTML.includes(WhatToSearchFor)) {
         DeckNameMatch = ii;
      }
   }
Decks[DeckNameMatch].selected = true;
   if ("createEvent" in document) {
      let evt = document.createEvent("HTMLEvents");
      evt.initEvent("change", false, true);
      dc.dispatchEvent(evt);
   }
   else dc.fireEvent("change");
}


Return to “Suggestions”

Who is online

Users browsing this forum: No registered users and 140 guests