-
Notifications
You must be signed in to change notification settings - Fork 0
/
unicheck_console.js
42 lines (38 loc) · 1.71 KB
/
unicheck_console.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
let Unicheck = {
Get: {
Result: function(content) {
let length = content.length;
console.log(`Copied message is "${content}", length is ${length}`);
return [content, length]
},
byElement: function(id) {
let text = document.getElementById(id).innerText;
return Unicheck.Get.Result(text);
},
bySelection: function() {
if (document.getSelection().toString.length > 0) {
let text = document.getSelection().toString();
return Unicheck.Get.Result(text);
} else { console.error("There is no selection to copy content from it, dude."); return false; }
}
},
Read: function (content, pos) {
let simple = content.codePointAt(pos);
let reverse = String.fromCodePoint(simple);
let hex = content.codePointAt(pos).toString(16);
let output = "\\u" + "0000".substring(0, 4 - hex.length) + hex;
return [simple, reverse, output];
},
SingleChar: function (id, pos, mode) {
let content = (mode === "selection") ? Unicheck.Get.bySelection() : Unicheck.Get.byElement(id);
let result = Unicheck.Read(content[0], pos);
console.log(`>> POSITION ${pos} SYMBOL "${result[1]}" || CHARACTER CODE IS ${result[2]} (simple: ${result[0]})`);
},
AllChars: function (id, mode) {
let content = (mode) ? Unicheck.Get.bySelection() : Unicheck.Get.byElement(id);
for (let i = 0; i < content[1]; i++) {
let result = Unicheck.Read(content[0], i);
console.log(`>> POSITION ${i} SYMBOL "${result[1]}" || CHARACTER CODE IS ${result[2]} (simple: ${result[0]})`);
}
}
}