This repository has been archived by the owner on May 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
141 lines (125 loc) · 3.71 KB
/
index.js
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// used to trigger paste execution
const submitButton = document.getElementById('submitButton')
// used to disable button while getting paste
const infoButton = document.getElementById('infoButton')
// used to clear and change things in the text field
const textField = document.getElementById('textField')
// used to signal errors
const alertText = document.getElementById("alertText")
const allowedChars = "abcdefghijklmnopqrstuvwxyz ,."
let finishedPasteText
attachEventListeners();
function submitButtonFunction() {
clearAlert();
deactivateButtons();
let rawPasteText = getTextFromField();
console.log(rawPasteText)
if (rawPasteText == "") {
setAlert("No Text found");
activateButtons();
return;
} else {
let counter = 0;
[...allowedChars].forEach(char => {
if (rawPasteText.includes(char)) {
counter += 1
}
}
)
if (counter == 0) {
console.log(counter)
setAlert("No Text found after conversion");
activateButtons();
return;
}
}
if (rawPasteText.length > 3200) {
setAlert("Text too long");
activateButtons();
return;
}
clearTextField();
try {
finishedPasteText = convertPaste(rawPasteText)
}
catch (e) {
console.log(e.message);
setAlert("Smth went wrong (JCMS#0557)")
activateButtons();
}
if (finishedPasteText.length > 3200) {
setAlert("Text too long after Conversion");
activateButtons();
return;
}
console.log(finishedPasteText)
try {
let idk = postSearchRequest(finishedPasteText);
// let hex, wall, shelf, volume, page = postSearchRequest(finishedPasteText);
}
catch {
setAlert("smth went wrong (contact info here)")
activateButtons();
}
// try {
// let title = postBookmarkRequest(hex, wall, shelf, volume, page)
// }
// catch {
// setAlert("smth went wrong (contact info here)")
// activateButtons();
// }
// let finalLink = `https://libraryofbabel.info/bookmark.cgi?${title}`
// setTextField(finalLink);
activateButtons();
}
function convertPaste(rawpasteText) {
let mapping = {".in.":"9",".ig.":"8",".ev.":"7",".x.":"6",".iv.":"5",".ou.":"4",".re.":"3",".t.":"2",".n.":"1",".er.":"0",".ex.":"!",".es.":"?",".qu.":'"',".pa.":"§",".do.":"$",".pe.":"%",".a.":"&",".eq.":"=",".fs.":"/",".bs.":"\\",".bo.":"(",".bc.":")",".cbc.":"}",".cbo.":"{",".sbc.":"]",".sbo.":"[",".ca.":"^",".de.":"°",".ls.":"<",".gt.":">",".or.":"|",".se.":";",".co.":":",".mi.":"-",".un.":"_",".ha.":"#",".sq.":"'",".fa.":"´",".fb.":"`",".pl.":"+",".st.":"*",".ti.":"~"};
let result = rawpasteText
for(let key in mapping) {
var value = mapping[key];
console.log(`Replacing ${value} with ${key}`);
result = result.replaceAll(`${value}`,`${key}`)
console.log(result)
}
return result
}
function deactivateButtons() {
submitButton.disabled = true
infoButton.disabled = true
}
function activateButtons() {
submitButton.disabled = false
infoButton.disabled = false
}
function getTextFromField() {
return textField.value
}
function postSearchRequest(term) {
console.log("do the fetch thing here")
var requestOptions = {
method: 'POST',
redirect: 'follow'
};
fetch(`https://www.whateverorigin.org/get?url=https://libraryofbabel.info/search.cgi?find=${term}`, requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
}
function postBookmarkRequest(hex, wall, shelf, volume, page, title = "") {
console.log("do the fetch thing here 2.0")
}
function clearTextField() {
textField.value = ""
}
function setTextField(text) {
textField.value = `${text}`
}
function setAlert(alertMessage) {
alertText.innerText = `${alertMessage}`
}
function clearAlert() {
alertText.innerText = ""
}
function attachEventListeners() {
submitButton.addEventListener('click', submitButtonFunction);
}