-
Notifications
You must be signed in to change notification settings - Fork 13
/
main.html
260 lines (225 loc) · 8.04 KB
/
main.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>BlobeBM</title>
<style>
@import url('https://fonts.googleapis.com/css2?family=Varela+Round&display=swap');
body {
font-family: sans-serif;
margin: 0;
padding: 0;
overflow: hidden;
}
.header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px;
background-color: black;
color: white;
}
#logo-container {
display: flex;
align-items: center;
}
#logo {
max-width: 100px;
max-height: 50px;
margin-right: 10px;
}
#itemListText {
font-size: 18px;
font-family: 'Varela Round', sans-serif;
}
#itemInputContainer {
display: flex;
flex-direction: column;
align-items: center;
}
#newItemInput {
width: calc(100% + 590px);
padding: 5px;
border-radius: 5px;
margin-left: -600px;
}
@media (max-width: 769px) {
#newItemInput {
width: auto;
margin-left: 0;
}
}
.item-list-container {
max-height: calc(100vh - 75px);
overflow-y: auto;
}
.item-list {
list-style: none;
margin: 0;
padding: 0;
}
.item {
display: flex;
margin-bottom: 10px;
border: 1px solid #ccc;
padding: 10px;
}
.item-button {
background-color: #007bff;
color: white;
padding: 5px 10px;
border: none;
cursor: pointer;
}
.remove-button {
background-color: #dc3545;
color: white;
padding: 5px 10px;
border: none;
cursor: pointer;
margin-left: 10px;
}
.edit-display-button, .edit-item-button {
background-color: #ffc107;
color: white;
padding: 5px 10px;
border: none;
cursor: pointer;
margin-left: 5px;
}
#addItemButton {
background-color: #008000;
color: white;
padding: 5px 10px;
border: none;
cursor: pointer;
}
.overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(255, 255, 255, 0.8);
display: none;
justify-content: center;
align-items: center;
z-index: 999;
}
</style>
</head>
<body>
<div class="header">
<div id="logo-container">
<img id="logo" src="https://blobby-boi.github.io/URLRedirector/favicon.ico" alt="Logo">
<span id="itemListText">BlobeBM: Bookmarklet Runner</span>
</div>
<div id="itemInputContainer">
<input type="text" id="newItemInput" placeholder="Enter the bookmarklet here">
<button id="addItemButton">Add Bookmarklet</button>
</div>
</div>
<div class="overlay" id="overlay"></div>
<div class="item-list-container">
<ul id="itemList" class="item-list"></ul>
</div>
<script>
document.addEventListener('DOMContentLoaded', () => {
let updatedItemText;
const itemList = document.getElementById('itemList');
const newItemInput = document.getElementById('newItemInput');
const addButton = document.getElementById('addItemButton');
const overlay = document.getElementById('overlay');
addButton.addEventListener('click', () => {
const displayValue = prompt('How do you want the bookmarklet to be called?');
if (displayValue === null) {
return;
}
const itemValue = newItemInput.value.trim();
if (!itemValue) {
return;
}
addItemToList(displayValue, itemValue);
saveItemsToLocalStorage();
newItemInput.value = '';
});
function addItemToList(displayValue, itemValue) {
const newItem = document.createElement('li');
newItem.className = 'item';
const itemButton = document.createElement('button');
itemButton.className = 'item-button';
itemButton.textContent = displayValue;
itemButton.title = itemValue;
itemButton.addEventListener('click', () => {
const selectedItemValue = itemButton.title;
runScript(selectedItemValue);
});
const removeButton = document.createElement('button');
removeButton.className = 'remove-button';
removeButton.textContent = 'Remove';
removeButton.addEventListener('click', () => {
itemList.removeChild(newItem);
saveItemsToLocalStorage();
});
const editDisplayButton = document.createElement('button');
editDisplayButton.className = 'edit-display-button';
editDisplayButton.textContent = 'Edit Name';
editDisplayButton.addEventListener('click', () => {
const newDisplayValue = prompt('Enter the new name:', itemButton.textContent);
if (newDisplayValue !== null) {
itemButton.textContent = newDisplayValue;
saveItemsToLocalStorage();
}
});
const editItemButton = document.createElement('button');
editItemButton.className = 'edit-item-button';
editItemButton.textContent = 'Edit Bookmarklet';
editItemButton.addEventListener('click', () => {
const newItemValue = prompt('Enter the new bookmarklet code:', itemButton.title);
if (newItemValue !== null) {
itemButton.title = newItemValue;
saveItemsToLocalStorage();
}
});
newItem.appendChild(itemButton);
newItem.appendChild(removeButton);
newItem.appendChild(editDisplayButton);
newItem.appendChild(editItemButton);
itemList.appendChild(newItem);
}
function saveItemsToLocalStorage() {
const items = Array.from(document.querySelectorAll('.item-button')).map(button => {
return {
display: button.textContent,
item: button.title,
};
});
localStorage.setItem('items', JSON.stringify(items));
}
function runScript(selectedItemValue) {
overlay.style.display = 'flex';
function removeOverlay() {
overlay.style.display = 'none';
}
setTimeout(() => {
try {
eval(selectedItemValue);
} catch (error) {
console.error('Error executing script:', error);
alert('An error occured while executing the bookmarklet. Try double checking the code of the bookmarklet.');
}
removeOverlay();
}, 500);
}
const storedItems = localStorage.getItem('items');
if (storedItems) {
const parsedItems = JSON.parse(storedItems);
parsedItems.forEach(item => {
addItemToList(item.display, item.item);
});
}
});
</script>
</body>
</html>