Last active 1753457066

kody's Avatar kody revised this gist 1753457061. Go to revision

1 file changed, 2 insertions, 2 deletions

4chan-page-notifier.user.js

@@ -4,7 +4,7 @@
4 4 // @match https://boards.4chan.org/*/thread/*
5 5 // @run-at document-end
6 6 // @grant none
7 - // @version 1.2.1
7 + // @version 1.2.2
8 8 // @author Kody
9 9 // @description Notify when the thread gets to page 10.
10 10 // @icon https://www.google.com/s2/favicons?domain=4chan.org
@@ -42,7 +42,7 @@
42 42 }
43 43
44 44 // Send a browser notification
45 - const subject = document.querySelector('.subject')?.innerHTML || 'Last Page Reached'
45 + const subject = document.querySelector('.subject')?.innerText || 'Last Page Reached'
46 46 if (window.Notification.permission === 'granted') {
47 47 const notification = new window.Notification(
48 48 subject,

kody's Avatar kody revised this gist 1753454358. Go to revision

1 file changed, 2 insertions, 2 deletions

4chan-page-notifier.user.js

@@ -4,7 +4,7 @@
4 4 // @match https://boards.4chan.org/*/thread/*
5 5 // @run-at document-end
6 6 // @grant none
7 - // @version 1.2.0
7 + // @version 1.2.1
8 8 // @author Kody
9 9 // @description Notify when the thread gets to page 10.
10 10 // @icon https://www.google.com/s2/favicons?domain=4chan.org
@@ -42,7 +42,7 @@
42 42 }
43 43
44 44 // Send a browser notification
45 - const subject = document.querySelector('.subject').innerHTML || 'Last Page Reached'
45 + const subject = document.querySelector('.subject')?.innerHTML || 'Last Page Reached'
46 46 if (window.Notification.permission === 'granted') {
47 47 const notification = new window.Notification(
48 48 subject,

kody's Avatar kody revised this gist 1753454278. Go to revision

1 file changed, 6 insertions, 3 deletions

4chan-page-notifier.user.js

@@ -4,7 +4,7 @@
4 4 // @match https://boards.4chan.org/*/thread/*
5 5 // @run-at document-end
6 6 // @grant none
7 - // @version 1.1.0
7 + // @version 1.2.0
8 8 // @author Kody
9 9 // @description Notify when the thread gets to page 10.
10 10 // @icon https://www.google.com/s2/favicons?domain=4chan.org
@@ -14,14 +14,15 @@
14 14 (function () {
15 15 'use strict'
16 16
17 - const lastPage = 10
18 17 let pageCountEl
18 + const lastPage = 10
19 19 let notified = false
20 20
21 21 const pageNotify = () => {
22 22 // Extract the current page number from the text
23 23 // but be careful that it might be 10(x)
24 24 const currPage = parseInt(pageCountEl.innerText.split('(')[0]?.trim(), 10)
25 + console.log('Current page:', currPage)
25 26
26 27 // Check if it's a valid number and greater than 0
27 28 if (isNaN(currPage) || currPage < 1) {
@@ -41,9 +42,11 @@
41 42 }
42 43
43 44 // Send a browser notification
45 + const subject = document.querySelector('.subject').innerHTML || 'Last Page Reached'
44 46 if (window.Notification.permission === 'granted') {
45 47 const notification = new window.Notification(
46 - 'Last Page Reached', {
48 + subject,
49 + {
47 50 body: `The thread has reached page ${currPage}.`,
48 51 icon: 'https://www.google.com/s2/favicons?domain=4chan.org',
49 52 }

kody's Avatar kody revised this gist 1753385541. Go to revision

1 file changed, 1 insertion, 1 deletion

4chan-page-notifier.user.js

@@ -14,8 +14,8 @@
14 14 (function () {
15 15 'use strict'
16 16
17 - let pageCountEl
18 17 const lastPage = 10
18 + let pageCountEl
19 19 let notified = false
20 20
21 21 const pageNotify = () => {

kody's Avatar kody revised this gist 1753385478. Go to revision

1 file changed, 44 insertions, 27 deletions

4chan-page-notifier.user.js

@@ -1,24 +1,42 @@
1 1 // ==UserScript==
2 2 // @name 4chan Page 10 Notifier
3 - // @namespace Violentmonkey Scripts
3 + // @namespace moe.rita.4chanPage10Notifier
4 4 // @match https://boards.4chan.org/*/thread/*
5 + // @run-at document-end
5 6 // @grant none
6 - // @version 1.0
7 + // @version 1.1.0
7 8 // @author Kody
8 - // @icon https://www.google.com/s2/favicons?domain=4chan.org
9 9 // @description Notify when the thread gets to page 10.
10 + // @icon https://www.google.com/s2/favicons?domain=4chan.org
11 + // @downloadURL https://gist.rita.moe/kody/c3cd33a8d923423c9045ad738ec302ba/raw/HEAD/4chan-page-notifier.user.js
10 12 // ==/UserScript==
11 13
12 14 (function () {
13 15 'use strict'
14 16
17 + let pageCountEl
15 18 const lastPage = 10
16 -
17 - let curPage
18 19 let notified = false
19 20
20 - const pageNotify = (page) => {
21 - if (curPage < lastPage || notified) {
21 + const pageNotify = () => {
22 + // Extract the current page number from the text
23 + // but be careful that it might be 10(x)
24 + const currPage = parseInt(pageCountEl.innerText.split('(')[0]?.trim(), 10)
25 +
26 + // Check if it's a valid number and greater than 0
27 + if (isNaN(currPage) || currPage < 1) {
28 + console.warn('Invalid page number:', currPage)
29 + return
30 + }
31 +
32 + // Reset notification state if page is less than 10
33 + if (currPage < lastPage && notified) {
34 + notified = false
35 + return
36 + }
37 +
38 + // Skip if already notified or current page is less than the last page
39 + if (currPage < lastPage || notified) {
22 40 return
23 41 }
24 42
@@ -26,7 +44,7 @@
26 44 if (window.Notification.permission === 'granted') {
27 45 const notification = new window.Notification(
28 46 'Last Page Reached', {
29 - body: `The thread has reached page ${page}.`,
47 + body: `The thread has reached page ${currPage}.`,
30 48 icon: 'https://www.google.com/s2/favicons?domain=4chan.org',
31 49 }
32 50 )
@@ -37,27 +55,26 @@
37 55
38 56 notified = true
39 57 }
40 -
41 - curPage = page
42 58 }
43 59
44 - const pageCountEl = document.getElementById('page-count')
45 - if (pageCountEl) {
46 - let pageCount = pageCountEl.innerText
47 - console.log('Current page:', pageCount)
60 + const setupObserver = () => {
61 + pageCountEl = document.getElementById('page-count')
48 62
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 - )
63 + if (pageCountEl) {
64 + const observer = new window.MutationObserver(pageNotify)
65 + observer.observe(
66 + pageCountEl,
67 + {
68 + childList: true,
69 + subtree: true,
70 + characterData: true,
71 + }
72 + )
73 + } else {
74 + console.error('Could not find element with ID "page-count"')
75 + }
62 76 }
77 +
78 + // Wait 3 seconds before setting up the observer
79 + setTimeout(setupObserver, 3000)
63 80 })()

kody's Avatar kody revised this gist 1753384023. Go to revision

1 file changed, 63 insertions

4chan-page-notifier.user.js(file created)

@@ -0,0 +1,63 @@
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 + })()
Newer Older