-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterface.js
More file actions
100 lines (82 loc) · 2.31 KB
/
Copy pathinterface.js
File metadata and controls
100 lines (82 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
function displayList(array) {
if (array.length < 1 && isLoaded) {
array = ["Ready to use! Input any two lowercase letters!"];
} else if (array.length < 1 && !isLoaded) {
array = [""];
}
// Get a container element
var listContainer = document.getElementsByClassName('list')[0];
// Clear it
listContainer.innerHTML = '';
// Make the list
var listElement = document.createElement('ul');
// Add it to the page
listContainer.appendChild(listElement);
// Set up a loop that goes through the items in listItems one at a time
for (var i = 0; i < array.length; ++i) {
// create an item for each one
var listItem = document.createElement('li');
// Add the item text
listItem.innerHTML = array[i];
// Add listItem to the listElement
listElement.appendChild(listItem);
}
}
function listToArray(input) {
var result = [];
input.split("\n").forEach(element => {
result.push(element);
});
return result;
}
function getText(type = "extrashort") {
let url = "";
switch (type) {
case "long":
url = 'https://raw.githubusercontent.com/dwyl/english-words/master/words_alpha.txt';
displayList(["Loading 370k dictionary..."]);
break;
case "short":
url = 'https://raw.githubusercontent.com/ciamkr/English-words-list/master/OfficialCrosswords';
displayList(["Loading 114k dictionary..."]);
break;
default:
url = 'https://raw.githubusercontent.com/ciamkr/English-words-list/master/OfficialCrosswordsDelta';
displayList(["Loading 4k dictionary..."]);
break;
}
function reqListener() {
isLoaded = true;
document.getElementById('blockTop').style = "";
displayList([]);
var array = listToArray(this.responseText);
console.log(array.length)
dummyBranches(array);
}
var oReq = new XMLHttpRequest();
oReq.addEventListener("load", reqListener);
oReq.open("GET", url);
oReq.send();
}
// ========
// for local use only
function readSingleFile() {
var input = document.createElement('input');
input.type = 'file';
input.onchange = e => {
var file = e.target.files[0];
if (!file) {
return;
}
var reader = new FileReader();
reader.onload = function (e) {
document.getElementById('blockTop').style = "";
displayList([]);
var array = listToArray(e.target.result);
console.log(array.length)
dummyBranches(array);
};
reader.readAsText(file);
};
input.click();
}