forked from DavidBevi/separator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
168 lines (155 loc) · 4.57 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>‎</title>
<style>
* {
background-color: #202020;
color: white;
font-family: Arial, sans-serif;
}
#container {
width: fit-content;
margin: 0 auto;
padding: 8pt;
display: flex;
justify-content: center;
border: 2pt solid #444444;
border-radius: 12pt;
}
.col {
margin: 0pt 2pt;
display: flex;
flex-direction: column;
}
#FavWrapper {
overflow: hidden;
margin: 0 auto;
width: 24pt;
height: 24pt;
border: 0;
}
#FavColor {
padding: 0;
width: 180%;
height: 180%;
margin: -25%;
border: 0pt;
}
#FavClear, #PageClear {
color: #888888;
cursor: pointer;
border: 0pt;
}
#PageTitle {
font-size: 18pt;
border: 0;
height: 24pt;
padding: 0pt 4pt;
outline: none;
}
#PageClear {
text-align: left;
}
</style>
</head>
<body>
<div id="container">
<div class="col">
<div id="FavWrapper">
<input type="color" id="FavColor">
</div>
<button id="FavClear">Clear</button>
</div>
<div class="col">
<input type="text" id="PageTitle" placeholder="Title">
<button id="PageClear">Clear title</button>
</div>
</div>
<script>
window.addEventListener('load', function() {
// Function to set favicon
function setFavicon(color) {
var canvas = document.createElement('canvas');
canvas.width = 16;
canvas.height = 16;
var ctx = canvas.getContext('2d');
ctx.fillStyle = color;
ctx.fillRect(0, 0, 16, 16);
var link = document.createElement('link');
var oldLink = document.getElementById('favicon');
link.id = 'favicon';
link.rel = 'shortcut icon';
link.href = canvas.toDataURL('image/png');
if (oldLink) {
document.head.removeChild(oldLink);
}
document.head.appendChild(link);
}
// Function to set FavColor from query parameter
function setFavColorFromQuery() {
var urlParams = new URLSearchParams(window.location.search);
var colorParam = urlParams.get('color');
if (!colorParam || colorParam === 'transparent') {
document.getElementById('FavColor').value = '';
setFavicon('transparent');
} else {
document.getElementById('FavColor').value = '#' + colorParam;
setFavicon('#' + colorParam);
}
}
// Function to set PageTitle from query parameter
function setPageTitleFromQuery() {
var urlParams = new URLSearchParams(window.location.search);
var titleParam = urlParams.get('title');
if (titleParam) {
document.getElementById('PageTitle').value = titleParam;
document.title = titleParam;
}
}
// Set FavColor and PageTitle from query parameters
setFavColorFromQuery();
setPageTitleFromQuery();
// Get elements
var pageTitleInput = document.getElementById('PageTitle');
var favColorInput = document.getElementById('FavColor');
var favClearBtn = document.getElementById('FavClear');
var pageClearBtn = document.getElementById('PageClear');
// Event listeners
pageTitleInput.addEventListener('input', function() {
var title = pageTitleInput.value.trim();
if (title === '') {
document.title = '\u200E';
} else {
document.title = title;
}
var urlParams = new URLSearchParams(window.location.search);
urlParams.set('title', title);
history.replaceState(null, '', window.location.pathname + '?' + urlParams.toString());
});
favColorInput.addEventListener('input', function() {
var color = favColorInput.value.slice(1); // Remove #
setFavicon(favColorInput.value);
var urlParams = new URLSearchParams(window.location.search);
urlParams.set('color', color);
history.replaceState(null, '', window.location.pathname + '?' + urlParams.toString());
});
favClearBtn.addEventListener('click', function() {
setFavColorFromQuery();
var urlParams = new URLSearchParams(window.location.search);
urlParams.delete('color');
history.replaceState(null, '', window.location.pathname + '?' + urlParams.toString());
});
pageClearBtn.addEventListener('click', function() {
document.getElementById('PageTitle').value = '';
document.title = '\u200E';
var urlParams = new URLSearchParams(window.location.search);
urlParams.set('title', '');
history.replaceState(null, '', window.location.pathname + '?' + urlParams.toString());
});
});
</script>
</body>
</html>