Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name schizophrenia-desktop-notifs (v1.0)
- // @namespace violentmonkey‑fullchan‑x
- // @match https://8chan.moe/*/res/*.html*
- // @match https://8chan.se/*/res/*.html*
- // @version 1.0‑2025‑05‑03
- // @run-at document-start
- // @description Desktop notifs on (You)
- // @author schizo75
- // @grant none
- // ==/UserScript==
- function showNotificationPermissionPrompt() {
- if (document.getElementById('fcx-notif-permission')) return; // already shown
- const box = document.createElement('div');
- box.id = 'fcx-notif-permission';
- box.style.cssText = `
- position: fixed;
- bottom: 20px;
- right: 20px;
- background: #111;
- color: white;
- padding: 12px 16px;
- border-radius: 6px;
- box-shadow: 0 4px 12px rgba(0,0,0,0.3);
- font-family: sans-serif;
- z-index: 9999;
- `;
- box.innerHTML = `
- 🔔 Enable desktop notifications?<br>
- <button id="fcx-enable-notifs" style="
- margin-top: 8px;
- padding: 4px 10px;
- background: #3a82f7;
- color: white;
- border: none;
- border-radius: 4px;
- cursor: pointer;
- ">Enable</button>
- `;
- document.body.appendChild(box);
- document.getElementById('fcx-enable-notifs')?.addEventListener('click', () => {
- Notification.requestPermission().then(permission => {
- if (permission === 'granted') {
- box.remove();
- console.log('[FCX] Notifications enabled.');
- } else {
- box.textContent = '🔕 Notifications disabled.';
- setTimeout(() => box.remove(), 3000);
- }
- });
- });
- }
- (function monitorYouQuotesWithThrottle() {
- const notifiedPostIds = new Set();
- let lastNotificationTime = 0;
- const MIN_INTERVAL_MS = 60 * 1000; // 1 minute
- function sendNotification(postId) {
- const now = Date.now();
- if (now - lastNotificationTime < MIN_INTERVAL_MS) return;
- lastNotificationTime = now;
- new Notification('(You) quoted', {
- body: `Your post was quoted in >>${postId}`,
- tag: `you-${postId}`,
- });
- }
- function handleNewYouQuote(node) {
- const link = node.closest('a.quoteLink.you, a.quotelink.you');
- if (!link) return;
- const postEl = link.closest('[id]');
- if (!postEl) return;
- const postId = postEl.id;
- if (notifiedPostIds.has(postId)) return;
- notifiedPostIds.add(postId);
- if (Notification.permission === 'granted') {
- sendNotification(postId);
- } else if (Notification.permission === 'default') {
- Notification.requestPermission();
- }
- }
- function waitForBodyAndStart() {
- if (!document.body) {
- requestAnimationFrame(waitForBodyAndStart);
- return;
- }
- const observer = new MutationObserver(mutations => {
- for (const mutation of mutations) {
- for (const node of mutation.addedNodes) {
- if (!(node instanceof Element)) continue;
- const youLinks = node.querySelectorAll?.('a.quoteLink.you, a.quotelink.you') || [];
- youLinks.forEach(link => handleNewYouQuote(link));
- if (node.matches?.('a.quoteLink.you, a.quotelink.you')) {
- handleNewYouQuote(node);
- }
- }
- }
- });
- observer.observe(document.body, {
- childList: true,
- subtree: true,
- });
- console.log('[FCX] (You) quote monitor with throttled desktop notifications is active.');
- showNotificationPermissionPrompt();
- }
- waitForBodyAndStart();
- })();
Advertisement
Add Comment
Please, Sign In to add comment