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.
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!
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.
First, create a new bookmark (or edit an already-existing one) and name it whatever you want. I've named mine deck searcher.
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.
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.
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.
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.
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.