4chan-page-notifier.user.js
· 1.4 KiB · JavaScript
Raw
// ==UserScript==
// @name 4chan Page 10 Notifier
// @namespace Violentmonkey Scripts
// @match https://boards.4chan.org/*/thread/*
// @grant none
// @version 1.0
// @author Kody
// @icon https://www.google.com/s2/favicons?domain=4chan.org
// @description Notify when the thread gets to page 10.
// ==/UserScript==
(function () {
'use strict'
const lastPage = 10
let curPage
let notified = false
const pageNotify = (page) => {
if (curPage < lastPage || notified) {
return
}
// Send a browser notification
if (window.Notification.permission === 'granted') {
const notification = new window.Notification(
'Last Page Reached', {
body: `The thread has reached page ${page}.`,
icon: 'https://www.google.com/s2/favicons?domain=4chan.org',
}
)
notification.onclick = () => {
window.focus()
notification.close()
}
notified = true
}
curPage = page
}
const pageCountEl = document.getElementById('page-count')
if (pageCountEl) {
let pageCount = pageCountEl.innerText
console.log('Current page:', pageCount)
const observer = new window.MutationObserver(
() => {
pageCount = pageCountEl.innerText
pageNotify(pageCount)
}
)
observer.observe(
pageCountEl,
{
childList: true,
subtree: true,
}
)
}
})()
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 |