-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
674 lines (615 loc) · 22.9 KB
/
Copy pathindex.html
File metadata and controls
674 lines (615 loc) · 22.9 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
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>Bookmarklets</title>
<link rel="stylesheet" href="https://cdn.simplecss.org/simple.min.css"/>
<style>
.bml {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 50px;
border: 1px dashed;
margin: 1em 0;
}
</style><meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body><header><h1 id="bookmarklets">Bookmarklets</h1></header>
<p>A collection of my bookmarklets to automate various things in the browser</p>
<p>You can view them at <a href="https://punchagan.github.io/bookmarklets">punchagan.github.io/bookmarklets</a></p>
<h4>Installation</h4>
<ul>
<li>Drag and drop the bookmarklet link to your bookmarks toolbar</li>
<li>If your bookmarklet toolbar is hidden, use <code>Ctrl+Shift+B</code> (on Firefox & Chrome) to make it visible</li>
<li>On Firefox, you could also right click on the link and click "Bookmark Link"</li>
</ul>
<div class="bookmarklet"><h3 id="better-website">Better Website</h3>
<p>Use rules from http://bettermotherfuckingwebsite.com to make websites more readable</p>
<a class="bml"
href="javascript: void (function () {
var style = document.createElement("style");
document.head.appendChild(style);
var sheet = style.sheet;
sheet.insertRule(
"body{ margin:40px auto; max-width:650px; line-height:1.6; font-size:18px; color:#444; padding:0 10px; }"
);
sheet.insertRule("h1,h2,h3{ line-height:1.2 }");
})();"
>Better Website
</a>
</div>
<div class="bookmarklet"><h3 id="elfeed-capture">Elfeed Capture</h3>
<p>Create a new elfeed entry from a website using an org-capture protocol</p>
<a class="bml"
href="javascript: void (function () {
const url_element =
document.querySelector('link[type="application/rss+xml"]') ||
document.querySelector('link[type="application/atom+xml"]') ||
location;
const url = url_element.href;
location.href =
"org-protocol://capture://L/" +
encodeURIComponent(url) +
"/" +
encodeURIComponent(document.title);
})();"
>Elfeed Capture
</a>
</div>
<div class="bookmarklet"><h3 id="fitbit-csv">Fitbit Csv</h3>
<p>Fetch the data used in the Fitbit Dashboard graphs as a CSV.</p>
<p>The bookmarklet is no longer functional since Fitbit removed the <a href="https://support.google.com/fitbit?p=dashboard-app">Activities
Dashboard</a></p>
<a class="bml"
href="javascript: void (async function () {
const getDatesBetween = (startDate, endDate) => {
const dateArray = [];
let currentDate = new Date(startDate);
const end = new Date(endDate);
while (currentDate <= end) {
dateArray.push(currentDate.toISOString().split("T")[0]);
currentDate.setDate(currentDate.getDate() + 1);
}
return dateArray;
};
const fetchDataByDay = async (date) => {
const ts = new Date().getTime();
const url = `${baseUrl}?userId=${userId}&dateFrom=${date}&dateTo=${date}&ts=${ts}&type=intradaySteps&dataVersion=3&apiFormat=json`;
const response = await fetch(url, {
credentials: "include",
headers: {
"User-Agent":
"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:127.0) Gecko/20100101 Firefox/127.0",
Accept: "*/*",
"Accept-Language": "en-US,en;q=0.5",
"X-Requested-With": "XMLHttpRequest",
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-origin",
},
referrer: "https://www.fitbit.com/activities",
method: "GET",
mode: "cors",
});
const data = await response.json();
return data?.graph?.dataSets?.activity?.dataPoints;
};
const downloadCSV = (dataArray, name) => {
const csvContent = dataArray
.map((item, index) => {
const values = Object.values(item);
return (
(index === 0 ? Object.keys(item).join(",") + "\n" : "") +
values.join(",")
);
})
.join("\n");
const blob = new Blob([csvContent], { type: "text/csv;charset=utf-8;" });
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.setAttribute("href", url);
link.setAttribute("download", name);
link.style.visibility = "hidden";
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
};
const userId = document.querySelector("body.fb-body").dataset.userId;
const userName =
document.querySelector("body.fb-body")?.dataset?.userName || "user";
const startDate = window.prompt("Enter START date (YYYY-mm-dd)");
const endDate = window.prompt("Enter END date (YYYY-mm-dd)");
const baseUrl = "https://www.fitbit.com/graph/getNewGraphData";
const dates = getDatesBetween(startDate, endDate);
window.alert(`Fetching data from ${startDate} to ${endDate} for ${userName}`);
const results = Array.flatten(
await Promise.all(dates.map((d) => fetchDataByDay(d))),
);
const cleanedName = userName.replaceAll(" ", "-").replace(".", "");
const csvName = `${cleanedName}-${startDate}.csv`;
console.log(results);
downloadCSV(results, csvName);
})();"
>Fitbit Csv
</a>
</div>
<div class="bookmarklet"><h3 id="kindle-highlights">Kindle Highlights</h3>
<p>More Readable Kindle Highlights, downloadable as Markdown or Org files</p>
<h4>Usage:</h4>
<ol>
<li>Visit https://read.amazon.com/notebook</li>
<li>Navigate to the required book</li>
<li>Use the bookmarklet</li>
<li>Profit!</li>
</ol>
<a class="bml"
href="javascript: void (function () {
const highlights_markdown = () => {
const markdown = "";
for (let i = 0; i < highlights.length; i++) {
markdown += "> " + highlights[i] + "\n\n";
const note = notes[i];
if (note !== "") {
markdown += note + "\n\n";
}
}
return markdown;
};
const highlights_orgmode = () => {
const orgmode = "";
for (let i = 0; i < highlights.length; i++) {
orgmode += "#+BEGIN_QUOTE\n";
orgmode += highlights[i] + "\n";
orgmode += "#+END_QUOTE\n\n";
const note = notes[i];
if (note !== "") {
orgmode += note + "\n\n";
}
}
return orgmode;
};
const add_download_links = () => {
const parent = $(".kp-notebook-bookcover-container").parent();
add_download_link(parent, "markdown");
add_download_link(parent, "x-org");
};
const add_download_link = (parent, mimetype) => {
const a = $("<a />");
let blob, url, name;
if (mimetype == "markdown") {
a.text("Download Markdown");
blob = new Blob([highlights_markdown()], { type: "text/markdown" });
name = "kindle-highlights.md";
} else if (mimetype == "x-org") {
a.text("Download Org-Mode");
blob = new Blob([highlights_orgmode()], { type: "text/markdown" });
name = "kindle-highlights.org";
}
url = window.URL.createObjectURL(blob);
a.addClass("a-row").appendTo(parent).attr("href", url).attr("download", name);
};
const make_readable = () => {
$("#library").hide();
$(".kp-notebook-metadata").hide();
$("h3.kp-notebook-metadata").show().parent().toggleClass("a-span5");
$(".kp-notebook-bookcover-container").hide();
$(".a-declarative").hide();
$(".kp-notebook-row-separator").css("border-bottom", "none");
$("#annotations").css("float", "none").css("max-width", "800px").css("margin", "auto");
$(".a-scroller").css("overflow", "inherit");
$(".a-size-small").hide();
};
make_readable();
const highlights = $(".kp-notebook-row-separator")
.find("#highlight")
.map(function (idx, x) {
return $(x).text();
});
const notes = $(".kp-notebook-row-separator")
.find("#note")
.map(function (idx, x) {
return $(x).text();
});
add_download_links();
})();"
>Kindle Highlights
</a>
</div>
<div class="bookmarklet"><h3 id="rudolph">Rudolph</h3>
<p>Rudolph helps organize Secret Santa ...</p>
<ol>
<li>Setup a Google spreadsheet with "Name" & "Whatsapp Name" columns with all
participants. The sheet name should be participants. Make the sheet
downloadable by everyone with URL.</li>
<li>Optionally, add an "Avoid Kiddos" column with a comma-separated list of
participants to avoid assigning as kiddos to a person.</li>
<li>In any tab, maybe the bookmarklets site tab, run the bookmarklet to fetch
all participants.</li>
<li>Copy the participants to Clipboard by clicking the new button.</li>
<li>In the WhatsApp Web tab, close any open chats.</li>
<li>Run the bookmarklet again and copy the participants JSON into the prompt.</li>
<li>Profit!</li>
</ol>
<a class="bml"
href="javascript:(async () => {
const sendEnter = async (element) => {
const enterEvent = new KeyboardEvent("keydown", {
bubbles: true,
cancelable: true,
key: "Enter",
code: "Enter",
});
element.dispatchEvent(enterEvent);
await new Promise(function (r) {
setTimeout(r, 2000);
});
};
const sendMessage = async (santaId, santa, kiddo) => {
console.log(`Sending message to ${santa}!!`);
const searchBox = document.querySelector(
"div[contenteditable='true'][data-tab='3']",
);
searchBox.focus();
document.execCommand("insertText", false, santaId);
await new Promise(function (r) {
setTimeout(r, 5000);
});
await sendEnter(searchBox);
const filler = `🎁 ${" ".repeat(50)} 🎁\n`;
const message = `Hi *${santa}*,\n\n\nYou are the Secret Santa for ...\n
${filler.repeat(10)}
🔽${" ".repeat(15)} Scroll down ${" ".repeat(15)}🔽\n
${filler.repeat(10)}\n\n
*${kiddo}*!\n\n
🎅🎁 Please keep it a secret and make it special!\n\n
Powered by Rudolph, a Bookmarklet: https://punchagan.github.io/bookmarklets/#rudolph`;
document.execCommand("insertText", false, message);
await new Promise(function (r) {
setTimeout(r, 500);
});
const sendButton = document.querySelector("button[aria-label='Send']");
sendButton.click();
await new Promise(function (r) {
setTimeout(r, 500);
});
document.querySelector('#main div[title="Menu"]')?.click();
await new Promise(function (r) {
setTimeout(r, 200);
});
document.querySelector('div[aria-label="Close chat"]')?.click();
await new Promise(function (r) {
setTimeout(r, 200);
});
document.querySelector('div[aria-label="Back"]')?.click();
document.querySelector("#side")?.click();
};
const fetchParticipants = async () => {
const sheetId = prompt(
"Enter the Google Spreadsheet ID containing participants:",
);
if (!sheetId) return alert("No spreadsheet ID provided.");
console.log(`Sheet: ${sheetId}`);
const url = `https://opensheet.elk.sh/${sheetId}/participants`;
let participants;
try {
const response = await fetch(url);
participants = await response.json();
} catch (error) {
return alert(
"Failed to fetch participant data. Ensure the spreadsheet ID is correct.",
);
}
if (!participants || participants.length < 2) {
return alert(
"Not enough participants found. Ensure the spreadsheet has at least two participants.",
);
}
const clipboardButton = document.createElement("button");
clipboardButton.textContent = "Copy Participants to Clipboard";
clipboardButton.style.position = "fixed";
clipboardButton.style.top = "10px";
clipboardButton.style.right = "10px";
clipboardButton.style.zIndex = "1000";
clipboardButton.addEventListener("click", async () => {
try {
await navigator.clipboard.writeText(JSON.stringify(participants));
alert(
"Participants copied to clipboard. Open WhatsApp Web and run the script again.",
);
} catch (err) {
alert(`Failed to copy to clipboard: ${err.message}`);
}
document.body.removeChild(clipboardButton);
});
document.body.appendChild(clipboardButton);
};
const generateShuffledAssignments = async (participants) => {
let shuffled = [...participants].sort();
for (let i = 0; i < participants.length * 50; i++) {
shuffled = [...shuffled].sort(() => Math.random() - 0.5);
}
const assignments = shuffled.map((participant, i) => {
return {
santa: participant["Name"],
santaId: participant["WhatsApp Name"],
kiddo: shuffled[(i + 1) % shuffled.length]["Name"],
};
});
return assignments.sort(() => Math.random() - 0.5);
};
const generateAssignmentsWithConstraints = (participants) => {
const assignments = [];
const usedKiddos = new Set();
const validKiddo = (santa, kiddo) => {
return (
!santa["Avoid Kiddos"]?.includes(kiddo.Name) && kiddo.Name !== santa.Name
);
};
const findValidKiddo = (santa, availableKiddos) => {
for (const kiddo of availableKiddos) {
if (validKiddo(santa, kiddo)) {
return kiddo;
}
}
return null;
};
const assignSanta = (index) => {
if (index >= participants.length) {
return true;
}
const santa = participants[index];
const availableKiddos = participants.filter((p) => !usedKiddos.has(p.Name));
const shuffledKiddos = [...availableKiddos].sort(() => Math.random() - 0.5);
for (const kiddo of shuffledKiddos) {
if (validKiddo(santa, kiddo)) {
assignments.push({
santa: santa.Name,
santaId: santa["WhatsApp Name"],
kiddo: kiddo.Name,
});
usedKiddos.add(kiddo.Name);
if (assignSanta(index + 1)) {
return true;
}
assignments.pop();
usedKiddos.delete(kiddo.Name);
}
}
return false;
};
if (!assignSanta(0)) {
throw new Error(
"Unsolvable constraints: Unable to generate valid assignments.",
);
}
return assignments;
};
const generateAssignments = (participants) => {
useConstraints = participants.some((p) => p["Avoid Kiddos"]);
console.log(`Using constraints: ${useConstraints}`);
return useConstraints
? generateAssignmentsWithConstraints(participants)
: generateShuffledAssignments(participants);
};
const main = async () => {
if (!window.location.href.includes("web.whatsapp.com")) {
await fetchParticipants();
} else {
const participantsJSON = prompt(
"Enter the assignments after fetching them on a different tab; WhatsApp Web tab doesn't allow fetching data.",
);
const participants = JSON.parse(participantsJSON);
participants.map((p) => {
p["Avoid Kiddos"] = p["Avoid Kiddos"]?.split(",").map((k) => k.trim());
});
const assignments = generateAssignments(participants);
for (const assignment of assignments) {
await sendMessage(assignment.santaId, assignment.santa, assignment.kiddo);
await new Promise(function (r) {
setTimeout(r, 1000);
});
}
}
};
if (typeof module !== "undefined" && module.exports) {
module.exports = { generateAssignments };
}
main()})();"
>Rudolph
</a>
</div>
<div class="bookmarklet">
<h3 id="save-momentum-quotes">Save Momentum Quotes</h3>
<p>Save Momentum Quotes as a JSON file</p>
<a class="bml"
href="javascript: void (function () {
if (
window.location.protocol !== "moz-extension:" ||
window.location.pathname !== "/dashboard.html"
) {
alert("To download Momentum Quotes, run the bookmarklet in a new empty tab!");
return;
}
let quotes = Object.entries(localStorage)
.filter(([key, value]) => key.indexOf("momentum-quote-") > -1)
.reduce((acc, [_, value]) => [...acc, JSON.parse(value)], [])
.map(({ _id, forDate, body, source, is_favorite, twitter }) => ({
_id,
forDate,
body,
source,
is_favorite,
twitter,
}));
let data = [JSON.stringify(quotes, undefined, 2)],
blob = new Blob(data, { type: "text/json" }),
a = document.createElement("a");
a.download = "momentum-quotes.json";
a.href = window.URL.createObjectURL(blob);
a.click();
})();"
>Save Momentum Quotes
</a>
</div>
<div class="bookmarklet">
<h3 id="ultimate-central-roster-save-links">
Ultimate Central Roster Save Links
</h3>
<p>Download profile links from a roster as a CSV</p>
<h4>Usage:</h4>
<p>Navigate to the roster page and click the bookmarklet</p>
<a class="bml"
href="javascript: void (function() {
const getName = () => {
const URLparts = location.pathname.split("/");
const n = URLparts.length - 1;
return URLparts[n] === "roster" ? URLparts[n - 1] : URLparts[n];
};
const data = Array.from(document.querySelectorAll(".media-item-tile"))
.map(x => `"${x.querySelector("h3").textContent}",${x.href}`)
.join("\n");
const blob = new Blob([data], { type: "text/csv" });
const a = document.createElement("a");
a.download = `${getName()}.csv`;
a.href = window.URL.createObjectURL(blob);
a.click();
})();"
>Ultimate Central Roster Save Links
</a>
</div>
<div class="bookmarklet"><h3 id="whatsapp-diff">Whatsapp Diff</h3>
<p>Compare and find the difference between two WhatsApp groups</p>
<h4>Usage</h4>
<ol>
<li>
<p>Visit https://web.whatsapp.com/</p>
</li>
<li>
<p>Navigate to the first group, wait until the member information is
populated (in the group heading) and click the bookmarklet.</p>
</li>
<li>
<p>Navigate to the second group, wait until the member information is
populated and click the bookmarklet.</p>
</li>
</ol>
<a class="bml"
href="javascript: void (function () {
const groupInfo = () => {
const elements = document.querySelectorAll("#main span[title]");
const name = elements[0].textContent;
const subtitle = elements[1].textContent;
if (
subtitle === "click here for group info" ||
subtitle.includes("is typing")
) {
return { name, members: [] };
}
const members = subtitle.replace(/ /g, "").split(",");
return { name, members };
};
const diff = function (a, b) {
const missing = a.members.filter((name) => !b.members.includes(name));
const msg = `List of people in ${a.name} but not in ${b.name}`;
const names = missing.join("\n");
const count = `${missing.length} people`;
alert(`${msg}\n${names}\n${count}`);
};
if (window.location.hostname !== "web.whatsapp.com") {
alert("Make sure that the current tab is the WhatsApp Web tab.");
return;
}
const group = groupInfo();
if (group.members.length === 0) {
alert("Could not get members info. Wait until the member list shows up in the group heading");
} else if (!window.firstGroup) {
window.firstGroup = group;
alert(`Captured info for first group\nName: ${group.name}\nMembers: ${group.members.length}`);
} else {
const { firstGroup } = window;
delete window.firstGroup;
diff(group, firstGroup);
diff(firstGroup, group);
}
})();"
>Whatsapp Diff
</a>
</div>
<div class="bookmarklet"><h3 id="whatsapp-sum-diff">Whatsapp Sum Diff</h3>
<p>Find the difference between combination of two groups (A & B) and another
group (C)</p>
<h4>Usage</h4>
<ol>
<li>
<p>Visit https://web.whatsapp.com/</p>
</li>
<li>
<p>Navigate to group A in WhatsApp Web, wait until the member information is
populated (in the group heading) and click the bookmarklet.</p>
</li>
<li>
<p>Navigate to group B, wait until the member information is populated (in
the group heading) and click the bookmarklet.</p>
</li>
<li>
<p>Finally, Navigate to group C, wait until the member information is
populated and click the bookmarklet.</p>
</li>
</ol>
<a class="bml"
href="javascript: void (function () {
const groupInfo = () => {
const elements = document.querySelectorAll("#main span[title]");
const name = elements[0].textContent;
const subtitle = elements[1].textContent;
if (
subtitle === "click here for group info" ||
subtitle.includes("is typing")
) {
return { name, members: [] };
}
const members = subtitle.replace(/ /g, "").split(",");
return { name, members };
};
const diff = function (a, b) {
const missing = a.members.filter((name) => !b.members.includes(name));
const msg = `List of people in ${a.name} but not in ${b.name}`;
const names = missing.join("\n");
const count = `${missing.length} people`;
alert(`${msg}\n${names}\n${count}`);
};
if (window.location.hostname !== "web.whatsapp.com") {
alert("Make sure that the current tab is the WhatsApp Web tab.");
return;
}
const group = groupInfo();
if (group.members.length === 0) {
alert("Could not get members info. Wait until the member list shows up in the group heading");
} else if (!window.groupA) {
window.groupA = group;
alert(`Captured info for group A\nName: ${group.name}\nMembers: ${group.members.length}`);
} else if (!window.groupB) {
window.groupB = group;
alert(`Captured info for group B\nName: ${group.name}\nMembers: ${group.members.length}`);
} else {
const { groupA, groupB } = window;
delete window.groupA;
delete window.groupB;
const combinedGroup = {
name: `${groupA.name} & ${groupB.name}`,
members: groupA.members.concat(groupB),
};
diff(group, combinedGroup);
diff(combinedGroup, group);
}
})();"
>Whatsapp Sum Diff
</a>
</div>
<footer><p>Last updated: 2026-02-04T16:13:27-00:00</p>
<p>Source: <a href="https://github.com/punchagan/bookmarklets">GitHub</a>
</p>
</footer>
</body>
</html>