-
-
Notifications
You must be signed in to change notification settings - Fork 153
Expand file tree
/
Copy pathbookmarklets.html
More file actions
512 lines (471 loc) · 21.4 KB
/
bookmarklets.html
File metadata and controls
512 lines (471 loc) · 21.4 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
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
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bookmarklets Collection</title>
<style>
* {
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
max-width: 900px;
margin: 0 auto;
padding: 20px;
line-height: 1.6;
color: #333;
background: #fafafa;
}
h1 {
color: #2c5aa0;
border-bottom: 2px solid #2c5aa0;
padding-bottom: 10px;
font-size: 1.8em;
}
h2 {
color: #444;
margin-top: 2em;
}
.intro {
background: #fff;
padding: 20px;
border-radius: 8px;
margin-bottom: 30px;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.bookmarklet-card {
background: #fff;
border-radius: 8px;
padding: 25px;
margin-bottom: 25px;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.bookmarklet-card h3 {
margin-top: 0;
color: #2c5aa0;
font-size: 1.3em;
}
.bookmarklet-card p {
color: #555;
}
.bookmarklet-buttons {
display: flex;
align-items: center;
gap: 12px;
margin: 15px 0;
}
.bookmarklet-link {
display: inline-block;
background: #2c5aa0;
color: white;
padding: 12px 24px;
border-radius: 6px;
text-decoration: none;
font-weight: bold;
font-size: 16px;
cursor: grab;
}
.bookmarklet-link:hover {
background: #1e3d6f;
}
.bookmarklet-link:active {
cursor: grabbing;
}
.copy-btn {
padding: 12px 20px;
background: #666;
color: white;
border: none;
border-radius: 6px;
cursor: pointer;
font-size: 16px;
font-weight: bold;
}
.copy-btn:hover {
background: #555;
}
.feature-list {
background: #f0f5ff;
border-left: 4px solid #2c5aa0;
padding: 15px 20px;
margin: 15px 0;
}
.feature-list ul {
margin: 0;
padding-left: 20px;
}
.feature-list li {
margin: 5px 0;
}
code {
background: #e8e8e8;
padding: 2px 6px;
border-radius: 3px;
font-family: "SF Mono", Monaco, "Cascadia Code", monospace;
font-size: 0.9em;
}
.code-block {
background: #1e1e1e;
color: #d4d4d4;
padding: 15px;
border-radius: 6px;
overflow-x: auto;
font-family: "SF Mono", Monaco, "Cascadia Code", monospace;
font-size: 12px;
line-height: 1.4;
white-space: pre-wrap;
word-break: break-all;
}
details {
margin-top: 15px;
}
details summary {
cursor: pointer;
color: #2c5aa0;
font-weight: bold;
}
.instructions {
background: #f5f5f5;
padding: 20px;
border-radius: 8px;
margin: 20px 0;
}
.instructions h3 {
margin-top: 0;
color: #2c5aa0;
}
.instructions ol {
margin-bottom: 0;
}
.instructions li {
margin: 8px 0;
}
footer {
margin-top: 40px;
padding-top: 20px;
border-top: 1px solid #ddd;
color: #666;
font-size: 14px;
}
</style>
</head>
<body>
<h1>Bookmarklets Collection</h1>
<div class="intro">
<p>A collection of useful bookmarklets for web development and browsing. Drag any bookmarklet button to your bookmarks bar to install, or use the copy button for mobile installation.</p>
</div>
<h2>Installation Instructions</h2>
<div class="instructions">
<h3>Desktop (Chrome / Firefox / Safari)</h3>
<ol>
<li>Make sure your bookmarks bar is visible
<ul>
<li><strong>Chrome:</strong> Press <code>Cmd+Shift+B</code> (Mac) or <code>Ctrl+Shift+B</code> (Windows)</li>
<li><strong>Firefox:</strong> Press <code>Cmd+B</code> (Mac) or <code>Ctrl+B</code> (Windows)</li>
<li><strong>Safari:</strong> View → Show Favorites Bar</li>
</ul>
</li>
<li><strong>Drag</strong> the bookmarklet button to your bookmarks bar</li>
<li>Click the bookmarklet on any page to activate</li>
</ol>
</div>
<div class="instructions">
<h3>Mobile Safari (iPhone/iPad)</h3>
<ol>
<li>Click the <strong>"Copy"</strong> button next to the bookmarklet</li>
<li>Create a new bookmark for any page (Share → Add Bookmark)</li>
<li>Edit the bookmark, delete the URL, and paste the copied code</li>
<li>To use: navigate to a page, open bookmarks, and tap the bookmarklet</li>
</ol>
</div>
<h2>Bookmarklets</h2>
<!-- View Reference Anchors -->
<div class="bookmarklet-card">
<h3>View Reference Anchors</h3>
<p>Reveals all linkable anchor points on a page by adding visible <code>#</code> links to elements with <code>id</code> attributes or <code><a name="..."></code> tags. Perfect for finding hidden reference targets you can link to.</p>
<div class="feature-list">
<strong>Features:</strong>
<ul>
<li>Finds all elements with <code>id</code> attributes</li>
<li>Finds all <code><a name="..."></code> anchor tags</li>
<li>Adds a clickable <code>#</code> link that copies the anchor URL to clipboard</li>
<li>Highlights anchors with a subtle background on hover</li>
<li>Click the <code>#</code> to copy the direct link</li>
</ul>
</div>
<div class="bookmarklet-buttons">
<a class="bookmarklet-link" href="javascript:(function(){if(document.getElementById('__anchor_styles')){return}const style=document.createElement('style');style.id='__anchor_styles';style.textContent=`.__anchor_link{position:relative;text-decoration:none!important;color:#2c5aa0!important;font-weight:bold;font-size:0.9em;margin-right:4px;padding:2px 5px;border-radius:3px;background:rgba(44,90,160,0.1);opacity:0.7;transition:opacity 0.2s,background 0.2s}.__anchor_link:hover{opacity:1;background:rgba(44,90,160,0.2)}.__anchor_added{scroll-margin-top:20px}`;document.head.appendChild(style);const anchors=new Set();document.querySelectorAll('[id]').forEach(el=>{if(el.id&&!el.id.startsWith('__anchor'))anchors.add(el)});document.querySelectorAll('a[name]').forEach(el=>{if(el.getAttribute('name'))anchors.add(el)});let count=0;anchors.forEach(el=>{if(el.querySelector('.__anchor_link'))return;const id=el.id||el.getAttribute('name');if(!id)return;const link=document.createElement('a');link.className='__anchor_link';link.href='#'+id;link.textContent='#';link.title='Click to copy link to #'+id;link.onclick=function(e){e.preventDefault();e.stopPropagation();const url=location.href.split('#')[0]+'#'+id;navigator.clipboard.writeText(url).then(()=>{link.textContent='\u2713';setTimeout(()=>link.textContent='#',1500)}).catch(()=>{prompt('Copy this URL:',url)})};el.classList.add('__anchor_added');if(el.firstChild){el.insertBefore(link,el.firstChild)}else{el.appendChild(link)}count++});alert('Found '+count+' anchor points on this page')})();">View Anchors</a>
<button class="copy-btn" data-target="anchors">Copy</button>
</div>
<details>
<summary>View source code</summary>
<pre class="code-block">(function() {
// Don't add twice
if (document.getElementById('__anchor_styles')) {
return;
}
// Add styles
const style = document.createElement('style');
style.id = '__anchor_styles';
style.textContent = `
.__anchor_link {
position: relative;
text-decoration: none !important;
color: #2c5aa0 !important;
font-weight: bold;
font-size: 0.9em;
margin-right: 4px;
padding: 2px 5px;
border-radius: 3px;
background: rgba(44, 90, 160, 0.1);
opacity: 0.7;
transition: opacity 0.2s, background 0.2s;
}
.__anchor_link:hover {
opacity: 1;
background: rgba(44, 90, 160, 0.2);
}
.__anchor_added {
scroll-margin-top: 20px;
}
`;
document.head.appendChild(style);
// Collect all anchor targets
const anchors = new Set();
// Find all elements with id attribute
document.querySelectorAll('[id]').forEach(el => {
if (el.id && !el.id.startsWith('__anchor')) anchors.add(el);
});
// Find all <a name="..."> elements
document.querySelectorAll('a[name]').forEach(el => {
if (el.getAttribute('name')) anchors.add(el);
});
let count = 0;
anchors.forEach(el => {
// Skip if already processed
if (el.querySelector('.__anchor_link')) return;
const id = el.id || el.getAttribute('name');
if (!id) return;
const link = document.createElement('a');
link.className = '__anchor_link';
link.href = '#' + id;
link.textContent = '#';
link.title = 'Click to copy link to #' + id;
link.onclick = function(e) {
e.preventDefault();
e.stopPropagation();
const url = location.href.split('#')[0] + '#' + id;
navigator.clipboard.writeText(url).then(() => {
link.textContent = '\u2713';
setTimeout(() => link.textContent = '#', 1500);
}).catch(() => {
prompt('Copy this URL:', url);
});
};
el.classList.add('__anchor_added');
// Insert as first child
if (el.firstChild) {
el.insertBefore(link, el.firstChild);
} else {
el.appendChild(link);
}
count++;
});
alert('Found ' + count + ' anchor points on this page');
})();</pre>
</details>
</div>
<!-- View Source -->
<div class="bookmarklet-card">
<h3>View Source</h3>
<p>Opens a modal dialog showing the current page's HTML source (<code>document.documentElement.outerHTML</code>). Includes options to pretty-print the HTML and copy it to your clipboard.</p>
<div class="feature-list">
<strong>Features:</strong>
<ul>
<li>Shows live DOM source (not original page source)</li>
<li><strong>Pretty Print</strong> button formats the HTML with proper indentation</li>
<li><strong>Copy</strong> button copies source to clipboard</li>
<li>Large, resizable modal for easy viewing</li>
<li>Press Escape or click outside to close</li>
</ul>
</div>
<div class="bookmarklet-buttons">
<a class="bookmarklet-link" href="javascript:(function(){if(document.getElementById('__viewsource_modal')){document.getElementById('__viewsource_modal').remove();return}const overlay=document.createElement('div');overlay.id='__viewsource_modal';overlay.innerHTML=`<style>#__viewsource_modal{position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(0,0,0,0.7);z-index:999999;display:flex;align-items:center;justify-content:center;font-family:-apple-system,BlinkMacSystemFont,sans-serif}#__viewsource_box{background:#fff;border-radius:8px;width:90vw;height:85vh;max-width:1200px;display:flex;flex-direction:column;box-shadow:0 4px 20px rgba(0,0,0,0.3)}#__viewsource_header{padding:15px 20px;border-bottom:1px solid #ddd;display:flex;justify-content:space-between;align-items:center}#__viewsource_header h2{margin:0;font-size:18px;color:#333}#__viewsource_buttons{display:flex;gap:10px}#__viewsource_buttons button{padding:8px 16px;border:none;border-radius:4px;cursor:pointer;font-size:14px;font-weight:500}#__viewsource_pretty{background:#2c5aa0;color:#fff}#__viewsource_pretty:hover{background:#1e3d6f}#__viewsource_copy{background:#28a745;color:#fff}#__viewsource_copy:hover{background:#218838}#__viewsource_close{background:#dc3545;color:#fff}#__viewsource_close:hover{background:#c82333}#__viewsource_textarea{flex:1;margin:0;padding:15px;border:none;resize:none;font-family:'SF Mono',Monaco,'Cascadia Code',Consolas,monospace;font-size:13px;line-height:1.5;white-space:pre;overflow:auto}</style><div id='__viewsource_box'><div id='__viewsource_header'><h2>Page Source</h2><div id='__viewsource_buttons'><button id='__viewsource_pretty'>Pretty Print</button><button id='__viewsource_copy'>Copy</button><button id='__viewsource_close'>\u2715 Close</button></div></div><textarea id='__viewsource_textarea' readonly></textarea></div>`;document.body.appendChild(overlay);const textarea=document.getElementById('__viewsource_textarea');const html=document.documentElement.outerHTML;textarea.value=html;document.getElementById('__viewsource_close').onclick=()=>overlay.remove();overlay.onclick=(e)=>{if(e.target===overlay)overlay.remove()};document.addEventListener('keydown',function esc(e){if(e.key==='Escape'){overlay.remove();document.removeEventListener('keydown',esc)}});document.getElementById('__viewsource_copy').onclick=function(){textarea.select();navigator.clipboard.writeText(textarea.value).then(()=>{this.textContent='Copied!';setTimeout(()=>this.textContent='Copy',1500)}).catch(()=>{document.execCommand('copy');this.textContent='Copied!';setTimeout(()=>this.textContent='Copy',1500)})};document.getElementById('__viewsource_pretty').onclick=function(){const raw=textarea.value;let formatted='';let indent=0;const tab=' ';const rawLines=raw.replace(/>\s*</g,'>\n<').split('\n');rawLines.forEach(line=>{line=line.trim();if(!line)return;if(line.match(/^<\//)){ indent=Math.max(0,indent-1)}formatted+=tab.repeat(indent)+line+'\n';if(line.match(/^<[a-z][^>]*[^\/]>$/i)&&!line.match(/^<(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)/i)){indent++}});textarea.value=formatted.trim();this.textContent='Done!';this.disabled=true}})();">View Source</a>
<button class="copy-btn" data-target="source">Copy</button>
</div>
<details>
<summary>View source code</summary>
<pre class="code-block">(function() {
// Toggle off if already open
if (document.getElementById('__viewsource_modal')) {
document.getElementById('__viewsource_modal').remove();
return;
}
// Create modal overlay
const overlay = document.createElement('div');
overlay.id = '__viewsource_modal';
overlay.innerHTML = `
<style>
#__viewsource_modal {
position: fixed;
top: 0; left: 0; right: 0; bottom: 0;
background: rgba(0,0,0,0.7);
z-index: 999999;
display: flex;
align-items: center;
justify-content: center;
font-family: -apple-system, BlinkMacSystemFont, sans-serif;
}
#__viewsource_box {
background: #fff;
border-radius: 8px;
width: 90vw;
height: 85vh;
max-width: 1200px;
display: flex;
flex-direction: column;
box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}
#__viewsource_header {
padding: 15px 20px;
border-bottom: 1px solid #ddd;
display: flex;
justify-content: space-between;
align-items: center;
}
#__viewsource_header h2 {
margin: 0;
font-size: 18px;
color: #333;
}
#__viewsource_buttons {
display: flex;
gap: 10px;
}
#__viewsource_buttons button {
padding: 8px 16px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
font-weight: 500;
}
#__viewsource_pretty { background: #2c5aa0; color: #fff; }
#__viewsource_pretty:hover { background: #1e3d6f; }
#__viewsource_copy { background: #28a745; color: #fff; }
#__viewsource_copy:hover { background: #218838; }
#__viewsource_close { background: #dc3545; color: #fff; }
#__viewsource_close:hover { background: #c82333; }
#__viewsource_textarea {
flex: 1;
margin: 0;
padding: 15px;
border: none;
resize: none;
font-family: 'SF Mono', Monaco, 'Cascadia Code', Consolas, monospace;
font-size: 13px;
line-height: 1.5;
white-space: pre;
overflow: auto;
}
</style>
<div id="__viewsource_box">
<div id="__viewsource_header">
<h2>Page Source</h2>
<div id="__viewsource_buttons">
<button id="__viewsource_pretty">Pretty Print</button>
<button id="__viewsource_copy">Copy</button>
<button id="__viewsource_close">&#10005; Close</button>
</div>
</div>
<textarea id="__viewsource_textarea" readonly></textarea>
</div>
`;
document.body.appendChild(overlay);
const textarea = document.getElementById('__viewsource_textarea');
const html = document.documentElement.outerHTML;
textarea.value = html;
// Close button
document.getElementById('__viewsource_close').onclick = () => overlay.remove();
// Click outside to close
overlay.onclick = (e) => {
if (e.target === overlay) overlay.remove();
};
// Escape key to close
document.addEventListener('keydown', function esc(e) {
if (e.key === 'Escape') {
overlay.remove();
document.removeEventListener('keydown', esc);
}
});
// Copy button
document.getElementById('__viewsource_copy').onclick = function() {
textarea.select();
navigator.clipboard.writeText(textarea.value).then(() => {
this.textContent = 'Copied!';
setTimeout(() => this.textContent = 'Copy', 1500);
}).catch(() => {
document.execCommand('copy');
this.textContent = 'Copied!';
setTimeout(() => this.textContent = 'Copy', 1500);
});
};
// Pretty print button
document.getElementById('__viewsource_pretty').onclick = function() {
const raw = textarea.value;
let formatted = '';
let indent = 0;
const tab = ' ';
// Split by tags while preserving them
const rawLines = raw.replace(/>\s*</g, '>\n<').split('\n');
rawLines.forEach(line => {
line = line.trim();
if (!line) return;
// Decrease indent for closing tags
if (line.match(/^<\//)) {
indent = Math.max(0, indent - 1);
}
formatted += tab.repeat(indent) + line + '\n';
// Increase indent for opening tags (not self-closing, not void)
if (line.match(/^<[a-z][^>]*[^\/]>$/i) &&
!line.match(/^<(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)/i)) {
indent++;
}
});
textarea.value = formatted.trim();
this.textContent = 'Done!';
this.disabled = true;
};
})();</pre>
</details>
</div>
<footer>
<p>Created with Claude. Drag a bookmarklet to your bookmarks bar to install.</p>
</footer>
<script>
// Copy buttons extract code from the adjacent bookmarklet link's href
document.querySelectorAll('.copy-btn').forEach(btn => {
btn.onclick = function() {
const card = this.closest('.bookmarklet-card');
const link = card.querySelector('.bookmarklet-link');
const code = link.getAttribute('href');
navigator.clipboard.writeText(code).then(() => {
this.textContent = 'Copied!';
setTimeout(() => this.textContent = 'Copy', 2000);
}).catch(() => {
// Fallback for older browsers
const textarea = document.createElement('textarea');
textarea.value = code;
document.body.appendChild(textarea);
textarea.select();
document.execCommand('copy');
document.body.removeChild(textarea);
this.textContent = 'Copied!';
setTimeout(() => this.textContent = 'Copy', 2000);
});
};
});
</script>
</body>
</html>