|
1 | 1 | // ==UserScript== |
2 | 2 | // @name Pornolab Filters |
3 | 3 | // @namespace pornolab-filters |
4 | | -// @version 1.0 |
| 4 | +// @version 1.1 |
5 | 5 | // @author masterofobzene |
6 | | -// @description Persistent client-side blacklist to filter 'topics' (post names) and 'forum' (category) in pornolab |
| 6 | +// @description Persistent client-side blacklist to filter topics (titles) and forums (categories) separately in pornolab |
7 | 7 | // @match *://pornolab.net/forum/tracker.php* |
8 | 8 | // @icon https://pornolab.net/favicon.ico |
9 | 9 | // @grant none |
10 | 10 | // @run-at document-end |
11 | 11 | // @downloadURL https://github.com/masterofobzene/UserScriptRepo/raw/main/NSFW/pornolab_filters.user.js |
12 | 12 | // @updateURL https://github.com/masterofobzene/UserScriptRepo/raw/main/NSFW/pornolab_filters.user.js |
13 | | - |
14 | 13 | // ==/UserScript== |
15 | 14 |
|
16 | 15 | (function () { |
17 | 16 | 'use strict'; |
18 | 17 |
|
19 | | - const STORAGE_KEY = 'pornolab_blacklist_words'; |
| 18 | + const STORAGE_KEY_TITLES = 'pornolab_blacklist_titles'; |
| 19 | + const STORAGE_KEY_FORUMS = 'pornolab_blacklist_forums'; |
20 | 20 |
|
21 | 21 | function waitForTable(cb) { |
22 | 22 | const t = document.querySelector('#tor-tbl'); |
|
32 | 32 | obs.observe(document.body, { childList: true, subtree: true }); |
33 | 33 | } |
34 | 34 |
|
35 | | - function getWords() { |
36 | | - return (localStorage.getItem(STORAGE_KEY) || '') |
| 35 | + function getWords(key) { |
| 36 | + return (localStorage.getItem(key) || '') |
37 | 37 | .toLowerCase() |
38 | 38 | .split(/[\s,]+/) |
39 | 39 | .filter(Boolean); |
40 | 40 | } |
41 | 41 |
|
42 | | - function saveWords(val) { |
43 | | - localStorage.setItem(STORAGE_KEY, val.trim()); |
| 42 | + function saveWords(key, val) { |
| 43 | + localStorage.setItem(key, val.trim()); |
44 | 44 | } |
45 | 45 |
|
46 | 46 | function createUI(table) { |
47 | | - // Prevent duplicate UI |
48 | 47 | if (document.getElementById('pl-blacklist-box')) return; |
49 | 48 |
|
50 | 49 | const box = document.createElement('div'); |
|
56 | 55 | background: #1b1b1b; |
57 | 56 | `; |
58 | 57 |
|
59 | | - box.innerHTML = ` |
60 | | - <div style="font-weight:bold; margin-bottom:6px;"> |
61 | | - Client-side blacklist (persistent): |
62 | | - </div> |
63 | | - `; |
| 58 | + box.innerHTML = `<div style="font-weight:bold; margin-bottom:10px;">Client-side blacklist (persistent):</div>`; |
64 | 59 |
|
65 | | - const input = document.createElement('input'); |
66 | | - input.type = 'text'; |
67 | | - input.style.cssText = ` |
68 | | - width: 100%; |
69 | | - max-width: 700px; |
70 | | - padding: 8px; |
71 | | - font-size: 14px; |
72 | | - `; |
73 | | - input.placeholder = 'word1 word2 word3'; |
| 60 | + // Title input |
| 61 | + const titleLabel = document.createElement('div'); |
| 62 | + titleLabel.textContent = 'Hide titles containing:'; |
| 63 | + titleLabel.style.marginTop = '8px'; |
| 64 | + box.appendChild(titleLabel); |
74 | 65 |
|
75 | | - input.value = localStorage.getItem(STORAGE_KEY) || ''; |
| 66 | + const titleInput = document.createElement('input'); |
| 67 | + titleInput.type = 'text'; |
| 68 | + titleInput.style.cssText = `width: 100%; max-width: 700px; padding: 8px; font-size: 14px;`; |
| 69 | + titleInput.placeholder = 'word1 word2 word3'; |
| 70 | + titleInput.value = localStorage.getItem(STORAGE_KEY_TITLES) || ''; |
76 | 71 |
|
77 | | - input.addEventListener('input', () => { |
78 | | - saveWords(input.value); |
| 72 | + titleInput.addEventListener('input', () => { |
| 73 | + saveWords(STORAGE_KEY_TITLES, titleInput.value); |
| 74 | + applyFilter(table); |
| 75 | + }); |
| 76 | + box.appendChild(titleInput); |
| 77 | + |
| 78 | + // Forum input |
| 79 | + const forumLabel = document.createElement('div'); |
| 80 | + forumLabel.textContent = 'Hide forums containing:'; |
| 81 | + forumLabel.style.marginTop = '12px'; |
| 82 | + box.appendChild(forumLabel); |
| 83 | + |
| 84 | + const forumInput = document.createElement('input'); |
| 85 | + forumInput.type = 'text'; |
| 86 | + forumInput.style.cssText = `width: 100%; max-width: 700px; padding: 8px; font-size: 14px;`; |
| 87 | + forumInput.placeholder = 'word1 word2 word3'; |
| 88 | + forumInput.value = localStorage.getItem(STORAGE_KEY_FORUMS) || ''; |
| 89 | + |
| 90 | + forumInput.addEventListener('input', () => { |
| 91 | + saveWords(STORAGE_KEY_FORUMS, forumInput.value); |
79 | 92 | applyFilter(table); |
80 | 93 | }); |
| 94 | + box.appendChild(forumInput); |
81 | 95 |
|
82 | | - box.appendChild(input); |
83 | 96 | table.parentNode.insertBefore(box, table); |
84 | 97 | } |
85 | 98 |
|
86 | 99 | function applyFilter(table) { |
87 | | - const words = getWords(); |
| 100 | + const titleWords = getWords(STORAGE_KEY_TITLES); |
| 101 | + const forumWords = getWords(STORAGE_KEY_FORUMS); |
88 | 102 |
|
89 | | - table.querySelectorAll('tbody > tr').forEach(row => { |
90 | | - if (!row.cells || row.cells.length < 4) { |
91 | | - row.style.display = ''; |
92 | | - return; |
93 | | - } |
| 103 | + table.querySelectorAll('tbody > tr').forEach(row => { |
| 104 | + if (!row.cells || row.cells.length < 4) { |
| 105 | + row.style.display = ''; |
| 106 | + return; |
| 107 | + } |
94 | 108 |
|
95 | | - // CORRECT columns |
96 | | - const forumCell = row.cells[2]; |
97 | | - const topicCell = row.cells[3]; |
| 109 | + const forumCell = row.cells[2]; |
| 110 | + const topicCell = row.cells[3]; |
98 | 111 |
|
99 | | - const forumText = forumCell.textContent || ''; |
100 | | - const topicText = topicCell.textContent || ''; |
| 112 | + const forumText = (forumCell.textContent || '').toLowerCase(); |
| 113 | + const topicText = (topicCell.textContent || '').toLowerCase(); |
101 | 114 |
|
102 | | - const combined = (forumText + ' ' + topicText).toLowerCase(); |
| 115 | + const hideByForum = forumWords.some(w => forumText.includes(w)); |
| 116 | + const hideByTitle = titleWords.some(w => topicText.includes(w)); |
103 | 117 |
|
104 | | - row.style.display = words.some(w => combined.includes(w)) |
105 | | - ? 'none' |
106 | | - : ''; |
107 | | - }); |
| 118 | + row.style.display = (hideByForum || hideByTitle) ? 'none' : ''; |
| 119 | + }); |
108 | 120 | } |
109 | 121 |
|
110 | 122 | function attachTableObserver(table) { |
|
0 commit comments