-
-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathmanageNotifications.js
More file actions
93 lines (77 loc) · 3.1 KB
/
Copy pathmanageNotifications.js
File metadata and controls
93 lines (77 loc) · 3.1 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
// Copyright (c) 2024-2026 nich (@nichxbt). Licensed under the Apache License, Version 2.0.
// scripts/manageNotifications.js
// Browser console script to scrape and manage X/Twitter notifications
// Paste in DevTools console on x.com/notifications
// by nichxbt
(() => {
const sleep = (ms) => new Promise(r => setTimeout(r, ms));
const CONFIG = {
maxNotifications: 100,
exportFormat: 'json', // 'json' or 'csv'
};
const run = async () => {
console.log('🔔 XActions Notification Scraper');
console.log('================================');
const notifications = [];
let scrollAttempts = 0;
while (notifications.length < CONFIG.maxNotifications && scrollAttempts < 30) {
document.querySelectorAll('[data-testid="cellInnerDiv"]').forEach(cell => {
const text = cell.textContent?.trim() || '';
if (!text || text.length < 5) return;
const links = Array.from(cell.querySelectorAll('a')).map(a => ({
text: a.textContent?.trim(),
href: a.href,
}));
const time = cell.querySelector('time')?.getAttribute('datetime') || '';
// Classify notification type
let type = 'other';
const lower = text.toLowerCase();
if (lower.includes('liked your')) type = 'like';
else if (lower.includes('replied')) type = 'reply';
else if (lower.includes('mentioned')) type = 'mention';
else if (lower.includes('followed you')) type = 'follow';
else if (lower.includes('retweeted') || lower.includes('reposted')) type = 'repost';
else if (lower.includes('quote')) type = 'quote';
const id = text.substring(0, 80) + time;
if (!notifications.find(n => (n.text.substring(0, 80) + n.time) === id)) {
notifications.push({
type,
text: text.substring(0, 200),
time,
links: links.slice(0, 3),
});
}
});
window.scrollBy(0, 800);
await sleep(1500);
scrollAttempts++;
if (scrollAttempts % 5 === 0) {
console.log(` 📥 Scraped ${notifications.length} notifications...`);
}
}
// Summary
const typeCounts = {};
notifications.forEach(n => {
typeCounts[n.type] = (typeCounts[n.type] || 0) + 1;
});
console.log(`\n📊 Notification summary (${notifications.length} total):`);
Object.entries(typeCounts).sort((a, b) => b[1] - a[1]).forEach(([type, count]) => {
const emoji = { like: '❤️', reply: '💬', mention: '@', follow: '👤', repost: '🔁', quote: '💭', other: '📌' };
console.log(` ${emoji[type] || '📌'} ${type}: ${count}`);
});
const result = {
notifications: notifications.slice(0, CONFIG.maxNotifications),
summary: typeCounts,
scrapedAt: new Date().toISOString(),
};
console.log('\n📦 Full JSON:');
console.log(JSON.stringify(result, null, 2));
try {
await navigator.clipboard.writeText(JSON.stringify(result, null, 2));
console.log('\n✅ Copied to clipboard!');
} catch (e) {
console.log('\n⚠️ Could not copy to clipboard.');
}
};
run();
})();