-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.html
441 lines (394 loc) · 17.4 KB
/
ui.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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tag Setter</title>
<style>
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');
body {
font-family: 'Inter', sans-serif;
padding: 10px;
background-color: #ffff;
color: #121315;
}
h4 {
margin-bottom: 15px;
}
label {
font-size: 12px;
}
.input-container {
display: flex;
justify-content: space-between;
align-items: center;
gap: 10px;
margin-bottom: 10px;
padding-bottom: 8px;
padding-top: 8px;
}
button {
width: 48%; /* Adjusted to 48% to fit side by side with some spacing */
padding: 8px;
padding-top: 16px;
padding-bottom: 16px;
margin-top: 5px;
background-color: #333;
color: #fff;
border: none;
border-radius: 4px;
cursor: pointer;
transition: background-color 0.2s;
}
button:hover {
background-color: #555;
}
/* Set the width of the "Enter Emoji" input to be smaller */
.small-input {
width: 30%;
border-radius: 4px;
border: 1px solid #ccc;
background-color: #fff;
}
/* Set the width of the "Enter Tag Text" input to be larger */
.large-input {
width: 70%;
border-radius: 4px;
border: 1px solid #ccc;
background-color: #fff;
}
select {
width: 100%;
padding: 8px;
border: 1px solid #ccc;
border-radius: 4px;
}
.section-header {
display: flex;
justify-content: space-between;
align-items: center;
cursor: pointer;
padding-left: 0px;
padding-right: 8px;
padding-bottom: 8px;
padding-top: 8px;
}
.section-content {
overflow: hidden;
transition: max-height 0.2s ease-out;
max-height: 0px;
}
.expanded {
max-height: 500px;
}
/* Chevron down icon */
.chevron {
border-style: solid;
border-width: 2px 2px 0 0;
content: ' ';
display: inline-block;
height: 12px;
position: relative;
transform: rotate(135deg); /* default state points downwards */
width: 12px;
transition: transform 0.2s;
}
#presets {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="12" height="8" viewBox="0 0 12 8"><path fill="none" stroke="%23333" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M1 1l5 5 5-5"/></svg>') no-repeat 95% center;
background-color: #fff;
padding-right: 30px;
}
#newTagPresets {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="12" height="8" viewBox="0 0 12 8"><path fill="none" stroke="%23333" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M1 1l5 5 5-5"/></svg>') no-repeat 95% center;
background-color: #fff;
padding-right: 30px;
}
#customDropdownIcon {
display: none;
}
/* Apply padding to all input elements except the color picker input */
input:not(.color-picker-input) {
padding: 8px;
}
/* Style for the sliding toggle switch */
.toggle-switch {
position: relative;
width: 40px; /* Adjust the width as needed */
height: 20px; /* Adjust the height as needed */
background-color: #000;
border-radius: 24px; /* Half of the height for a round appearance */
cursor: pointer;
overflow: hidden;
}
.toggle-input {
position: absolute; /* Make the checkbox cover the toggle */
width: 100%;
height: 100%;
opacity: 0; /* Hide the checkbox */
cursor: pointer; /* Make it clickable */
z-index: 2; /* Put it above the label */
}
.toggle-label {
position: absolute;
top: 0;
left: 0;
width: 50%; /* Half the width of the switch */
height: 100%;
background-color: #fff;
border-radius: 50%;
transition: transform 0.2s;
transform: translateX(0); /* Start with the switch turned off */
z-index: 1; /* Keep it below the checkbox */
}
.toggle-input:checked + .toggle-label {
transform: translateX(100%); /* Move the label to the right when checked */
}
/* Style for the fixed dialog box */
.dialog-box {
background-color: #f5f5f7;
border-radius: 4px;
padding: 16px;
margin-bottom: 20px;
font-size: 12px;
color: #555555;
text-align: center;
line-height: 2;
}
</style>
</head>
<body>
<!-- Fixed dialog box at the top -->
<div id="dialog-box" class="dialog-box">
By default, Marq will run on the page name. <br/> Select anything to run it on that specific selection.
</div>
<!-- Start of Presets Section -->
<div id="presets-section" style="display: none;">
<div class="section-header" onclick="toggleSection('presets')">
<h4>Presets</h4>
<div class="chevron"></div>
</div>
<div class="section-content" id="presets-content">
<div class="presets-container">
<select id="presets">
<option value="" disabled selected>No presets available</option>
</select>
<!-- Adjusted buttons to sit side by side -->
<div class="input-container">
<button id="deletePreset">Delete Preset</button>
<button id="applyPreset">Apply Preset</button>
</div>
</div>
</div>
</div>
<!-- End of Presets Section -->
<!-- Start of "Add a new tag" section -->
<div>
<div class="section-header" onclick="toggleSection('newTag')">
<h4>Add a new tag</h4>
<div class="chevron"></div>
</div>
<div class="section-content" id="newTag-content">
<div>
<div class="input-container">
<!-- Dropdown for emoji selection -->
<select id="newTagPresets" class="small-input">
<option value=" ">No emoji</option>
<option value="✅">✅ Tick</option>
<option value="❌">❌ Cross</option>
<option value="🟡">🟡 Yellow</option>
<option value="🚀">🚀 Rocket</option>
<option value="🧠">🧠 Brain</option>
<option value="📋">📋 Note</option>
<option value="🛠️">🛠️ Tool</option>
<option value="🏁">🏁 Finish</option>
</select>
<input type="text" id="tagText" placeholder="Enter the text for the tag" class="large-input">
</div>
<div class="input-container">
<label>Do you want to add a color to the selection?</label>
<div class="toggle-switch">
<input type="checkbox" id="useColorCheckbox" class="toggle-input">
<label for="useColorCheckbox" class="toggle-label"></label>
</div>
</div>
</div>
<div class="input-container" id="colorPickerContainer" style="display: none;">
<label style="margin-right: 10px;">Pick a color</label>
<input type="color" id="tagColor" class="color-picker-input">
</div>
<div class="input-container">
<button id="savePreset">Save Preset</button>
<button id="setTag">Apply</button>
</div>
</div>
</div>
<!-- End of "Add a new tag" section -->
<script>
// Function to toggle the visibility of the "Presets" section.
function togglePresetsSection(presetsAvailable) {
const presetsSection = document.getElementById('presets-section');
if (presetsAvailable) {
// If presets are available, show the "Presets" section.
presetsSection.style.display = 'block';
} else {
// If presets are not available, hide the "Presets" section.
presetsSection.style.display = 'none';
}
}
// Initialize the dropdown with "No presets available" option
const presetDropdown = document.getElementById('presets');
presetDropdown.innerHTML = '<option value="" disabled selected>No presets available</option>';
// Function to update the presets dropdown and toggle the "Presets" section
function updatePresetsDropdownAndSection(presets) {
const presetsSection = document.getElementById('presets-section');
const presetDropdown = document.getElementById('presets');
if (presets.length === 0) {
// If there are no presets, hide the "Presets" section
presetsSection.style.display = 'none';
// Clear the preset dropdown
presetDropdown.innerHTML = '<option value="" disabled selected>No presets available</option>';
} else {
// If there are presets, show the "Presets" section
presetsSection.style.display = 'block';
// Populate the preset dropdown with presets
presetDropdown.innerHTML = '';
presets.forEach(preset => {
const option = document.createElement('option');
option.value = preset;
option.text = preset; // Use the full preset string
presetDropdown.add(option);
});
}
}
// Function to set a tag
document.getElementById('setTag').onclick = function () {
const text = document.getElementById('tagText').value || null;
// Getting the selected emoji from the dropdown
const emojiDropdown = document.getElementById('newTagPresets'); // Updated ID here
const selectedEmoji = emojiDropdown.options[emojiDropdown.selectedIndex].value;
const emoji = selectedEmoji || null;
const useColor = document.getElementById('useColorCheckbox').checked;
let color = null;
if (useColor) {
color = document.getElementById('tagColor').value || null;
}
parent.postMessage({ pluginMessage: { type: 'set-tag', text, emoji, color } }, '*');
};
// Function to save a preset
document.getElementById('savePreset').onclick = function () {
const text = document.getElementById('tagText').value || null;
// Getting the selected emoji from the dropdown
const emojiDropdown = document.getElementById('newTagPresets'); // Updated ID here
const selectedEmoji = emojiDropdown.options[emojiDropdown.selectedIndex].value;
const emoji = selectedEmoji || null;
const colorInput = document.getElementById('tagColor');
const isNoColorSelected = colorInput.getAttribute('data-no-color') === 'true';
const color = isNoColorSelected ? "" : colorInput.value || null;
// Check if both text and emoji are null
if (text === null && emoji === null) {
alert('Please provide at least one value (text or emoji) to save as a preset.');
} else {
parent.postMessage({ pluginMessage: { type: 'save-preset', text, emoji, color } }, '*');
}
};
// Function to apply a preset
document.getElementById('applyPreset').onclick = function () {
const presetValue = document.getElementById('presets').value;
if (presetValue) {
const [emoji, text, color] = presetValue.split('|');
parent.postMessage({ pluginMessage: { type: 'set-tag', emoji, text, color } }, '*');
}
};
// Function to delete a preset
document.getElementById('deletePreset').onclick = function () {
const presetValue = document.getElementById('presets').value;
if (presetValue) {
parent.postMessage({ pluginMessage: { type: 'delete-preset', preset: presetValue } }, '*');
}
};
// Listener for color checkbox
document.getElementById('useColorCheckbox').onchange = function () {
const isChecked = this.checked;
const colorPickerContainer = document.getElementById('colorPickerContainer');
if (isChecked) {
colorPickerContainer.style.display = 'block';
} else {
colorPickerContainer.style.display = 'none';
}
};
// Listener for receiving messages from the plugin
window.onmessage = function (event) {
const { type, presets } = event.data.pluginMessage;
if (type === 'update-presets') {
const presetDropdown = document.getElementById('presets');
presetDropdown.innerHTML = ''; // Clear current options
// Populate the preset dropdown with presets
presets.forEach(preset => {
const [emoji, text, color] = preset.split('|');
const option = document.createElement('option');
option.value = preset;
option.text = `${emoji} ${text} (${color})`;
presetDropdown.add(option);
});
// Toggle the visibility of the "Presets" section based on presets availability
togglePresetsSection(presets.length > 0);
} else if (type === 'selectionChange') {
let count = event.data.pluginMessage.count;
if (count == 0) {
document.getElementById('dialog-box').textContent = ` By default, Marq will run on the page name. Select anything to run it on that specific selection.`;
} else if (count == 1) {
document.getElementById('dialog-box').textContent = `Marq will be applied to ${count} selections.`;
} else {
document.getElementById('dialog-box').textContent = `Marq will be applied to ${count} selections.`;
}
}
};
// Request stored presets when the UI is loaded
parent.postMessage({ pluginMessage: { type: 'get-presets' } }, '*');
// Function to toggle sections
function toggleSection(section) {
// List of all sections
const sections = ['presets', 'newTag'];
sections.forEach(s => {
const content = document.getElementById(s + '-content');
const chevron = content.previousElementSibling.querySelector('.chevron');
const applyButton = document.getElementById('setTag');
const savePresetButton = document.getElementById('savePreset');
if (s === section) { // If it's the clicked section
if (content.classList.contains('expanded')) {
content.classList.remove('expanded');
chevron.style.transform = "rotate(135deg)"; // Pointing downwards for collapsed
// Hide buttons when collapsing "Add a new tag" section
if (s === 'newTag') {
applyButton.style.display = 'none';
savePresetButton.style.display = 'none';
}
} else {
content.classList.add('expanded');
chevron.style.transform = "rotate(-45deg)"; // Pointing upwards for expanded
// Show buttons when expanding "Add a new tag" section
if (s === 'newTag') {
applyButton.style.display = 'block';
savePresetButton.style.display = 'block';
}
}
} else { // For all other sections
content.classList.remove('expanded');
chevron.style.transform = "rotate(135deg)"; // Pointing downwards for collapsed
// Hide buttons when collapsing other sections
if (s === 'newTag') {
applyButton.style.display = 'none';
savePresetButton.style.display = 'none';
}
}
});
}
</script>
</body>
</html>