Last active 1753457066

Revision 3a819845b5ee4d873b14da51990b3cb79d697f06

4chan-page-notifier.user.js Raw
1// ==UserScript==
2// @name 4chan Page 10 Notifier
3// @namespace Violentmonkey Scripts
4// @match https://boards.4chan.org/*/thread/*
5// @grant none
6// @version 1.0
7// @author Kody
8// @icon https://www.google.com/s2/favicons?domain=4chan.org
9// @description Notify when the thread gets to page 10.
10// ==/UserScript==
11
12(function () {
13 'use strict'
14
15 const lastPage = 10
16
17 let curPage
18 let notified = false
19
20 const pageNotify = (page) => {
21 if (curPage < lastPage || notified) {
22 return
23 }
24
25 // Send a browser notification
26 if (window.Notification.permission === 'granted') {
27 const notification = new window.Notification(
28 'Last Page Reached', {
29 body: `The thread has reached page ${page}.`,
30 icon: 'https://www.google.com/s2/favicons?domain=4chan.org',
31 }
32 )
33 notification.onclick = () => {
34 window.focus()
35 notification.close()
36 }
37
38 notified = true
39 }
40
41 curPage = page
42 }
43
44 const pageCountEl = document.getElementById('page-count')
45 if (pageCountEl) {
46 let pageCount = pageCountEl.innerText
47 console.log('Current page:', pageCount)
48
49 const observer = new window.MutationObserver(
50 () => {
51 pageCount = pageCountEl.innerText
52 pageNotify(pageCount)
53 }
54 )
55 observer.observe(
56 pageCountEl,
57 {
58 childList: true,
59 subtree: true,
60 }
61 )
62 }
63})()
64