aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorInigoGutierrez <inigogf.95@gmail.com>2019-01-04 02:35:22 +0100
committerInigoGutierrez <inigogf.95@gmail.com>2019-01-04 02:35:22 +0100
commit991054675e7a1b2f1525e606a489560b64bdbdc5 (patch)
tree6e7994603373426dcf1efcdd841a5f44ce3a0b72 /js
downloadmainpage-991054675e7a1b2f1525e606a489560b64bdbdc5.tar.gz
mainpage-991054675e7a1b2f1525e606a489560b64bdbdc5.zip
Created the repo.
Diffstat (limited to 'js')
-rw-r--r--js/script.js75
1 files changed, 75 insertions, 0 deletions
diff --git a/js/script.js b/js/script.js
new file mode 100644
index 0000000..523d26b
--- /dev/null
+++ b/js/script.js
@@ -0,0 +1,75 @@
+var codes = new Array();
+var urls = new Array();
+var hints = new Array();
+
+function createSearchQMs(file) {
+ let rawFile = new XMLHttpRequest();
+ rawFile.open("GET", file, false);
+ rawFile.onreadystatechange = function ()
+ {
+ if(rawFile.readyState === 4)
+ {
+ if(rawFile.status === 200 || rawFile.status == 0)
+ {
+ let allText = rawFile.responseText;
+ myFunc(allText);
+ }
+ }
+ }
+ rawFile.send(null);
+}
+
+function myFunc(text) {
+ let lines = text.split('\n');
+ for (let i=0; i < lines.length - 1; i++) { // -1 to avoid extra undefined line
+ let parts = lines[i].split('\'');
+ codes[i] = parts[1];
+ urls[i] = parts[3];
+ hints[i] = parts[4].split('#')[1];
+ let qms = document.getElementById("qms");
+ let newP = document.createElement("p");
+ newP.id = "p" + i;
+ let newInput = document.createElement("input");
+ newInput.id = "code" + i;
+ newInput.type = "button";
+ newInput.value = codes[i];
+ newInput.onclick = function() {createInput(i)};
+ newP.appendChild(newInput);
+ qms.appendChild(newP);
+ }
+}
+
+function createInput(id) {
+ // Delete all search boxes
+ let sbs = document.getElementsByClassName("sb");
+ for (let i = 0; i < sbs.length; i++) {
+ sbs[i].parentNode.removeChild(sbs[i]);
+ }
+ // Clean big blue p bg
+ let psbs = document.getElementsByClassName("psb");
+ for (let i = 0; i < psbs.length; i++) {
+ psbs[i].classList.remove("psb");
+ }
+ // Create corresponding search box
+ let par = document.getElementById("p"+id);
+ par.className = "psb";
+ let sb = document.createElement("input");
+ sb.id = "sb" + id;
+ sb.className = "sb";
+ sb.type = "text";
+ sb.placeholder = hints[id];
+ sb.onkeydown = function() {
+ if (event.keyCode === 13) {
+ search(id);
+ }
+ };
+ par.appendChild(sb);
+ // Focus the search box
+ document.getElementById("sb"+id).focus();
+}
+
+function search(id) {
+ let sb = document.getElementById("sb"+id);
+ url = urls[id].replace("{}", sb.value);
+ window.location.assign(url);
+}