-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZenDivider.html
More file actions
145 lines (119 loc) · 5.67 KB
/
Copy pathZenDivider.html
File metadata and controls
145 lines (119 loc) · 5.67 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
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
142
143
144
145
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="height=device-height">
<meta charset="utf-8">
<title>ZenDivider...</title>
<style>
#titleInput {
width: 100%;
height: 55vh;
position: fixed;
top: 42%;
text-align: center;
resize: none;
border: none;
outline: none;
box-shadow: none;
background-color: transparent;
font-size: xxx-large;
font-weight: bold;
}
.text {
font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, 'Helvetica Neue', system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
.text {
color: white;
}
}
body {
background-color: #f7f7f7;
}
@media (prefers-color-scheme: dark) {
body {
background-color: #333333;
}
}
</style>
<link rel="icon" type="image/png" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAAAANSURBVChTY2AYBSAAAAEIAAGpU3sNAAAAAElFTkSuQmCC">
</head>
<body>
<textarea id="titleInput" class="text" aria-label="Title input text box" autocomplete="off" autocapitalize="words" autocorrect="on" spellcheck="false" autofocus="true" placeholder="Type here to rename the title of this tab"></textarea>
</body>
<script>
const appName = "ZenDivider"
const appVersion = "202506_1.1"
const appAbout = appName + " by BarnMTB, Licensed under CC BY-NC-SA 4.0, Version " + appVersion + ", https://github.com/BarnMTB/ZenDivider"
const defaultTitle = appName
const targetTextBox = document.getElementById('titleInput'); // Target textbox that contains input, locate by ID
//-----------------------------------------------Grab Query from URL
function grabTextQuery() {
var url = window.location.href; // Get the full URL of the current page
var parsedUrl = new URL(url); // Create a URL object to parse the URL
var queryParams = parsedUrl.searchParams; // Get the search parameters from the URL
// Get the value of the 'text' query parameter
var textValue = queryParams.get('text');
console.log("Recieved Text Query: " + textValue); // Print the value of the 'text' query parameter
targetTextBox.value = textValue; // Set the text value in the target textbox to the query
renameTabTitleCommit();
removeEmptyTextQuery();
}
//-----------------------------------------------Monitor text change
targetTextBox.addEventListener('input', function () {
renameTabTitleCommit();
updateTextQueryCommit();
//appInfoRevealCheck();
});
//-----------------------------------------------Change tab's title
function renameTabTitle(input) {
if (typeof input != 'string') { throw new Error("Invalid input: Expected a string."); };
if (input == "") { document.title = defaultTitle }
else if (input != null) { document.title = input }
else { document.title = defaultTitle };
}
function renameTabTitleCommit() {
renameTabTitle(targetTextBox.value);
}
grabTextQuery();
//-----------------------------------------------Remove empty query from URL
function removeEmptyTextQuery() {
const url = new URL(window.location.href);
const textParam = url.searchParams.get("text");
if (textParam === "") {
url.searchParams.delete("text");
window.history.replaceState({}, document.title, url.toString());
}
}
//-----------------------------------------------Update Query from URL
function updateTextQuery(input) {
const url = new URL(window.location.href); // Get the current URL
url.searchParams.set("text", input); // Modify the query parameter "text"
window.history.replaceState(null, "", url); // Update the browser's address bar without reloading the page
}
function updateTextQueryCommit() {
removeEmptyTextQuery();
updateTextQuery(targetTextBox.value);
}
//-----------------------------------------------Click anywhere to start typing
/*
document.addEventListener("click", function () {
targetTextBox.focus();
});
*/
//-----------------------------------------------Unfocuses when pressing Esc or Enter
targetTextBox.addEventListener("keydown", function (event) {
if (event.key === "Enter" || event.key === "Escape") {
appInfoRevealCheck();
targetTextBox.blur();
updateTextQueryCommit();
}
});
//-----------------------------------------------Show App Info
function appInfoRevealCheck() {
if (targetTextBox.value.toLowerCase() === (appName + ":about").toLowerCase() || targetTextBox.value.toLowerCase() === (appName + ":info").toLowerCase()) {
targetTextBox.value = appAbout;
}
}
</script>
</html>