Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Мелкобуква нахуй с двачей
- // @namespace 2ch-lowercase-filter
- // @match *://2ch.su/*
- // @grant none
- // ==/UserScript==
- (function () {
- 'use strict';
- const badPostIds = new Set();
- function getPostId(post) {
- return post.id ? post.id.replace(/\D/g, '') : null;
- }
- function getRealLines(node) {
- const walker = document.createTreeWalker(
- node,
- NodeFilter.SHOW_TEXT,
- null
- );
- const lines = [];
- let n;
- while ((n = walker.nextNode())) {
- const parts = n.nodeValue.split('\n');
- for (let p of parts) {
- const t = p.trim();
- if (t) lines.push(t);
- }
- }
- return lines;
- }
- function collapseHide(post) {
- post.style.height = "0px";
- post.style.overflow = "hidden";
- post.style.opacity = "0";
- post.style.margin = "0";
- post.style.padding = "0";
- post.style.border = "0";
- }
- function processPosts() {
- // ===== PASS 1 — классификация =====
- document.querySelectorAll('.post').forEach(post => {
- if (post.dataset.lowercaseChecked) return;
- const msg = post.querySelector('.post__message');
- if (!msg) return;
- const fullText = msg.textContent || '';
- // ---- OP override ----
- const opMatches = fullText.match(/>>\d+\s*\(OP\)/g);
- if (opMatches && opMatches.length >= 2) {
- post.style.outline = '3px solid #00cc66';
- post.style.background = 'rgba(0,255,120,0.10)';
- msg.style.color = '#33dd88';
- post.dataset.filterState = "good";
- post.dataset.lowercaseChecked = "1";
- return;
- }
- const lines = getRealLines(msg);
- const filtered = lines.filter(l =>
- !l.startsWith('>') && !l.startsWith('>>')
- );
- if (filtered.length) {
- const firstChar = filtered[0].charAt(0);
- if (/[а-яё]/.test(firstChar)) {
- const id = getPostId(post);
- if (id) badPostIds.add(id);
- collapseHide(post);
- post.dataset.filterState = "bad";
- }
- }
- post.dataset.lowercaseChecked = "1";
- });
- // ===== PASS 2 — красим ссылки =====
- document.querySelectorAll('a').forEach(a => {
- const m = a.textContent.match(/^>>(\d+)$/);
- if (!m) return;
- if (badPostIds.has(m[1])) {
- a.style.color = "#ff4444";
- }
- });
- // ===== PASS 3 — чистим reply =====
- document.querySelectorAll('.post').forEach(post => {
- const boxes = post.querySelectorAll(
- '.post__replies, .reflinks, .post__refmap, .post__replymap'
- );
- boxes.forEach(box => {
- box.querySelectorAll('a').forEach(a => {
- const m = a.textContent.match(/>>(\d+)/);
- if (m && badPostIds.has(m[1])) {
- a.remove();
- }
- });
- });
- });
- }
- processPosts();
- const observer = new MutationObserver(processPosts);
- observer.observe(document.body, { childList: true, subtree: true });
- })();
Advertisement
Add Comment
Please, Sign In to add comment