Minimal styling for search page, allow search for a whole deck, allow case-insensitive search

master
trémeur 2 weeks ago
parent af395bc486
commit 424c8a6f76

@ -558,3 +558,7 @@ form * {
span.sorttitle { span.sorttitle {
font-weight: bold; font-weight: bold;
} }
span.searchresults {
font-family: monospace;
}

@ -54,7 +54,7 @@ def searchgen():
os.remove(thefile) os.remove(thefile)
skel.headerwrite(thefile,"search") skel.headerwrite(thefile,"search")
content = open(thefile,"a") content = open(thefile,"a")
content.write("<h1>card search</h1>\n<form>\n <label for=\"cardinput\">Paste a list of cards here:</label>\n <textarea id=\"cardinput\" name=\"cardinput\"></textarea>\n <input type=\"button\" value=\"Search\" onclick=\"searchcards()\">\n</form>\n<p id=\"hpwfound\"></p>\n<p id=\"mpwfound\"></p>\n<p id=\"lpwfound\"></p>\n<p id=\"hptfound\"></p>\n<p id=\"mptfound\"></p>\n<p id=\"lptfound\"></p>\n<p id=\"nothing\"></p>\n<script>\n function searchcards() {\n const hpw = [") content.write("<h1>card search</h1>\n<form>\n <label for=\"cardinput\">Enter a list of cards and/or decks here:</label>\n <textarea id=\"cardinput\" name=\"cardinput\"></textarea>\n <input type=\"button\" value=\"Search\" onclick=\"searchcards()\">\n</form>\n<p id=\"hpwfound\"></p>\n<p id=\"mpwfound\"></p>\n<p id=\"lpwfound\"></p>\n<p id=\"hptfound\"></p>\n<p id=\"mptfound\"></p>\n<p id=\"lptfound\"></p>\n<p id=\"nothing\"></p>\n<script>\n function searchcards() {\n const thecards = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20'];\n const hpw = [")
precomma = False precomma = False
for card in hpw: for card in hpw:
if precomma: if precomma:
@ -96,7 +96,7 @@ def searchgen():
content.write(", ") content.write(", ")
content.write("'" + card + "'") content.write("'" + card + "'")
precomma = True precomma = True
content.write("];\n const searchstring = document.getElementById('cardinput').value;\n const searcharray = searchstring.replaceAll(' ','').split(',');\n const hpwfound = [];\n const mpwfound = [];\n const lpwfound = [];\n const hptfound = [];\n const mptfound = [];\n const lptfound = [];\n for (const element of searcharray) {\n if (hpw.includes(element)) {\n hpwfound.push(element);\n } else if (mpw.includes(element)) {\n mpwfound.push(element);\n } else if (lpw.includes(element)) {\n lpwfound.push(element);\n } else if (hpt.includes(element)) {\n hptfound.push(element);\n } else if (mpt.includes(element)) {\n mptfound.push(element);\n } else if (lpt.includes(element)) {\n lptfound.push(element);\n };\n };\n if ((hpwfound.length) > 0) {\n document.getElementById('hpwfound').innerHTML = '<span class=\"sorttitle\">Wanted (high priority):</span> ' + hpwfound.join(', ');\n } else {\n document.getElementById('hpwfound').innerHTML = '';\n };\n if ((mpwfound.length) > 0) {\n document.getElementById('mpwfound').innerHTML = '<span class=\"sorttitle\">Wanted (medium priority):</span> ' + mpwfound.join(', ');\n } else {\n document.getElementById('mpwfound').innerHTML = '';\n };\n if ((lpwfound.length) > 0) {\n document.getElementById('lpwfound').innerHTML = '<span class=\"sorttitle\">Wanted (low priority):</span> ' + lpwfound.join(', ');\n } else {\n document.getElementById('lpwfound').innerHTML = '';\n };\n if ((hptfound.length) > 0) {\n document.getElementById('hptfound').innerHTML = '<span class=\"sorttitle\">Will trade for <a href=\"/wanted\">high priority cards</a> only:</span> ' + hptfound.join(', ');\n } else {\n document.getElementById('hptfound').innerHTML = '';\n };\n if ((mptfound.length) > 0) {\n document.getElementById('mptfound').innerHTML = '<span class=\"sorttitle\">Will trade for <a href=\"/wanted\">high or medium priority cards</a>:</span> ' + mptfound.join(', ');\n } else {\n document.getElementById('mptfound').innerHTML = '';\n };\n if ((lptfound.length) > 0) {\n document.getElementById('lptfound').innerHTML = '<span class=\"sorttitle\">Will trade for <a href=\"/wanted\">any wanted card</a>:</span> ' + lptfound.join(', ');\n } else {\n document.getElementById('lptfound').innerHTML = '';\n };\n if ((hpwfound.length) + (mpwfound.length) + (lpwfound.length) + (hptfound.length) + (mptfound.length) + (lptfound.length) == 0) {\n document.getElementById('nothing').innerHTML = 'No results';\n } else {\n document.getElementById('nothing').innerHTML = '';\n }\n }\n</script>\n </main>\n </body>\n</html>") content.write("];\n const searchstring = document.getElementById('cardinput').value;\n const searcharray = searchstring.replaceAll(' ','').toLowerCase().split(',');\n const hpwfound = [];\n const mpwfound = [];\n const lpwfound = [];\n const hptfound = [];\n const mptfound = [];\n const lptfound = [];\n for (const element of searcharray) {\n let cardend = element.substring(element.length, element.length - 2);\n if (!(thecards.includes(cardend))) {\n for (const ending of thecards) {\n searcharray.push(element + ending);\n };\n };\n };\n for (const element of searcharray) {\n if (hpw.includes(element)) {\n hpwfound.push(element);\n } else if (mpw.includes(element)) {\n mpwfound.push(element);\n } else if (lpw.includes(element)) {\n lpwfound.push(element);\n } else if (hpt.includes(element)) {\n hptfound.push(element);\n } else if (mpt.includes(element)) {\n mptfound.push(element);\n } else if (lpt.includes(element)) {\n lptfound.push(element);\n };\n };\n if ((hpwfound.length) > 0) {\n document.getElementById('hpwfound').innerHTML = '<span class=\"sorttitle\">Wanted (high priority):</span> <span class=\"searchresults\">' + hpwfound.join(', ') + '</span>';\n } else {\n document.getElementById('hpwfound').innerHTML = '';\n };\n if ((mpwfound.length) > 0) {\n document.getElementById('mpwfound').innerHTML = '<span class=\"sorttitle\">Wanted (medium priority):</span> <span class=\"searchresults\">' + mpwfound.join(', ') + '</span>';\n } else {\n document.getElementById('mpwfound').innerHTML = '';\n };\n if ((lpwfound.length) > 0) {\n document.getElementById('lpwfound').innerHTML = '<span class=\"sorttitle\">Wanted (low priority):</span> <span class=\"searchresults\">' + lpwfound.join(', ') + '</span>';\n } else {\n document.getElementById('lpwfound').innerHTML = '';\n };\n if ((hptfound.length) > 0) {\n document.getElementById('hptfound').innerHTML = '<span class=\"sorttitle\">Will trade out for <a href=\"/wanted\">high priority cards</a> only:</span> <span class=\"searchresults\">' + hptfound.join(', ') + '</span>';\n } else {\n document.getElementById('hptfound').innerHTML = '';\n };\n if ((mptfound.length) > 0) {\n document.getElementById('mptfound').innerHTML = '<span class=\"sorttitle\">Will trade out for <a href=\"/wanted\">high or medium priority cards</a>:</span> <span class=\"searchresults\">' + mptfound.join(', ') + '</span>';\n } else {\n document.getElementById('mptfound').innerHTML = '';\n };\n if ((lptfound.length) > 0) {\n document.getElementById('lptfound').innerHTML = '<span class=\"sorttitle\">Will trade out for <a href=\"/wanted\">any wanted card</a>:</span> <span class=\"searchresults\">' + lptfound.join(', ') + '</span>';\n } else {\n document.getElementById('lptfound').innerHTML = '';\n };\n if ((hpwfound.length) + (mpwfound.length) + (lpwfound.length) + (hptfound.length) + (mptfound.length) + (lptfound.length) == 0) {\n document.getElementById('nothing').innerHTML = 'No results';\n } else {\n document.getElementById('nothing').innerHTML = '';\n }\n }\n</script>\n </main>\n </body>\n</html>")
content.close() content.close()
if __name__ == "__main__": if __name__ == "__main__":

Loading…
Cancel
Save