-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4chan-linkify-greentext.user.js
More file actions
31 lines (31 loc) · 1.21 KB
/
Copy path4chan-linkify-greentext.user.js
File metadata and controls
31 lines (31 loc) · 1.21 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
// ==UserScript==
// @name 4chan Linkify Greentext
// @version 1.2
// @include http://boards.4chan.org/*
// @include https://boards.4chan.org/*
// @include http://www.4chan.org/*
// @include https://www.4chan.org/*
// @grant none
// @run-at document-start
// ==/UserScript==
document.onreadystatechange = function () {
if (document.readyState === "interactive") {
document.querySelectorAll('span.quote').forEach(quoteSpan => {
const post = quoteSpan.parentNode;
const previousThreadUrl = post.querySelector('a[href*="thread"]');
let threadId = null;
if (previousThreadUrl) {
const threadMatch = previousThreadUrl.href.match(/thread\/(\d{9})/);
if (threadMatch) threadId = threadMatch[1];
}
const quoteIds = quoteSpan.textContent.match(/(?<!>)>(\d{9})/g);
if (quoteIds) {
quoteSpan.outerHTML = quoteIds.map(id => {
const postId = id.slice(1);
const linkUrl = threadId ? `/g/thread/${threadId}#p${postId}` : `#p${postId}`;
return `<a href="${linkUrl}" class="quotelink">>>${postId}</a>`;
}).join(' ');
}
});
}
};