-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
133 lines (130 loc) · 4.23 KB
/
index.html
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
<!DOCTYPE html>
<html>
<title>turbotex</title>
<head>
<style>
html, body {
overflow-x: hidden;
overflow-y: hidden;
background-color: black;
height: 100%;
width: 100%;
margin: 0;
}
input[type="textbox"] {
width: 100vw;
height: 100%;
min-height: 100%;
box-sizing: border-box;
font-size: 70vh;
border-width: 5vh;
padding: 10vh;
}
:focus {
outline: none;
}
</style>
</head>
<body onload="getP()">
<input autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" type="textbox" id="test" name="turbotex" maxlength="524288" placeholder="">
</body>
<script>
function getP() {
// setup
const urlParams = new URLSearchParams(window.location.search);
const box = document.getElementById("test");
let focused = "inset 0 0 0 3px hsla(0, 0%, 0%, 100%)";
let pattrn = null;
let pport = null;
let lastValue = "";
// send updated value to extension
function update() {
if (pport) {
pport.postMessage(box.value);
}
}
// handle params
if (urlParams.has('color')) {
box.style.color = `${urlParams.get('color')}`;
box.style.borderColor = `${urlParams.get('color')}`;
}
if (urlParams.has('bcolor')) {
box.style.backgroundColor = `${urlParams.get('bcolor')}`;
const rgb = window.getComputedStyle(box).backgroundColor;
const colorArr = rgb.slice(rgb.indexOf("(") + 1, rgb.indexOf(")")).split(", ");
const lum = 0.2126*Number(colorArr[0]) + 0.7152*Number(colorArr[1]) + 0.0722*Number(colorArr[2]);
if (lum < 154) {
focused = "inset 0 0 0 3vh hsla(0, 100%, 100%, 100%)";
}
}
if (urlParams.has('font')) {
box.style.fontFamily = `${decodeURIComponent(urlParams.get('font'))}`;
}
if (urlParams.has('placeholder')) {
box.setAttribute("placeholder", `${decodeURIComponent(urlParams.get('placeholder'))}`);
}
if (urlParams.has('italic')) {
if (Number(urlParams.get('italic')) == 1) {
box.style.fontStyle = "italic";
}
}
if (urlParams.has('bold')) {
if (Number(urlParams.get('bold')) == 1) {
box.style.fontWeight = "bold";
}
}
if (urlParams.has('case')) {
if (Number(urlParams.get('case')) == 1) {
box.style.textTransform = "uppercase";
} else if (Number(urlParams.get('case')) == 0) {
box.style.textTransform = "lowercase";
}
}
if (urlParams.has('max')) {
box.setAttribute('maxlength', Number(urlParams.get('max')));
}
if (urlParams.has('pattern')) {
let pstr = decodeURIComponent(urlParams.get('pattern'));
if (pstr.startsWith("/") && pstr.endsWith("/")) {
pstr = pstr.substring(1, pstr.length - 1);
}
pattrn = new RegExp(pstr, "");
}
if (urlParams.has('value')) {
const paramValue = `${decodeURIComponent(urlParams.get('value'))}`;
if (pattrn === null || pattrn.test(paramValue)) {
box.value = paramValue;
lastValue = paramValue;
}
}
// listeners
function do_on_input(e) {
if (e.target.value.length > box.getAttribute("maxlength")) {
e.target.value = e.target.value.slice(0, box.getAttribute("maxlength"));
}
if (pattrn !== null && !pattrn.test(e.target.value)) {
e.target.value = lastValue;
} else {
lastValue = e.target.value;
}
update();
}
box.addEventListener("input", do_on_input);
box.addEventListener("focus", (e) => {
e.target.style.boxShadow = focused;
});
box.addEventListener("blur", (e) => {
e.target.style.boxShadow = "";
});
// get port from extension
window.addEventListener("message", onMessage);
function onMessage(e) {
if (e.data === "request") {
pport = e.ports[0];
// send initial value to extension
update();
}
}
}
</script>
</html>