Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name AutoAdmit User Hider
- // @namespace http://tampermonkey.net/
- // @version 2.0
- // @description Hide threads and posts from specific users on AutoAdmit
- // @match *://www.autoadmit.com/*
- // @match *://autoadmit.com/*
- // @match *://www.xoxohth.com/*
- // @match *://xoxohth.com/*
- // @grant none
- // ==/UserScript==
- (function() {
- 'use strict';
- // ============ CONFIGURATION ============
- const BLOCKED_USERS = [
- 'https://i.imgur.com/3so5uWV.jpeg'
- // Add more usernames here
- ];
- const FETCH_DELAY_MS = 500; // Delay between requests to avoid rate limiting
- const CACHE_EXPIRY_DAYS = 1; // How long to cache thread author data
- // ========================================
- const CACHE_KEY = 'autoadmit_thread_authors';
- const CACHE_TIME_KEY = 'autoadmit_cache_times';
- // Load cached data
- function getCache() {
- try {
- return JSON.parse(localStorage.getItem(CACHE_KEY) || '{}');
- } catch {
- return {};
- }
- }
- function getCacheTimes() {
- try {
- return JSON.parse(localStorage.getItem(CACHE_TIME_KEY) || '{}');
- } catch {
- return {};
- }
- }
- function saveCache(cache) {
- localStorage.setItem(CACHE_KEY, JSON.stringify(cache));
- }
- function saveCacheTimes(times) {
- localStorage.setItem(CACHE_TIME_KEY, JSON.stringify(times));
- }
- function isCacheExpired(threadId) {
- const times = getCacheTimes();
- if (!times[threadId]) return true;
- const expiryMs = CACHE_EXPIRY_DAYS * 24 * 60 * 60 * 1000;
- return (Date.now() - times[threadId]) > expiryMs;
- }
- function escapeRegex(string) {
- return string.replace(/[.*+?^${}()|[\]\\\/]/g, '\\$&');
- }
- function isBlockedUser(username) {
- if (!username) return false;
- const lowerUsername = username.toLowerCase().trim();
- return BLOCKED_USERS.some(blocked =>
- lowerUsername === blocked.toLowerCase().trim()
- );
- }
- // Fetch a thread page and extract the OP's username
- async function fetchThreadAuthor(threadId) {
- try {
- const response = await fetch(`/thread.php?thread_id=${threadId}&forum_id=2`);
- const html = await response.text();
- // Parse the HTML to find the first author
- const parser = new DOMParser();
- const doc = parser.parseFromString(html, 'text/html');
- // Find first post table (width=700, not indented)
- const tables = doc.querySelectorAll('table[width="700"]');
- for (const table of tables) {
- // Check if this is a top-level post (no indentation td)
- const firstTd = table.querySelector('td:first-child');
- if (firstTd && firstTd.querySelector('img[src*="blank.gif"]')) {
- continue; // This is a reply (indented)
- }
- // Extract author from this table
- const tableHtml = table.innerHTML;
- const authorMatch = tableHtml.match(/<b>Author:<\/b>(?: |\s)*(?:<[^>]*>)*\s*([^<]+)/i);
- if (authorMatch) {
- return authorMatch[1].trim();
- }
- }
- return null;
- } catch (error) {
- console.error(`Error fetching thread ${threadId}:`, error);
- return null;
- }
- }
- // Get all thread IDs from the main page
- function getThreadIds() {
- const threadIds = [];
- const links = document.querySelectorAll('a[href*="thread_id="]');
- links.forEach(link => {
- const match = link.href.match(/thread_id=(\d+)/);
- if (match) {
- threadIds.push({
- id: match[1],
- row: link.closest('tr')
- });
- }
- });
- // Remove duplicates
- const seen = new Set();
- return threadIds.filter(item => {
- if (seen.has(item.id)) return false;
- seen.add(item.id);
- return true;
- });
- }
- // Hide a thread row
- function hideThreadRow(row) {
- if (row) {
- row.style.display = 'none';
- }
- }
- // Process threads on main page
- async function processMainPage() {
- const threads = getThreadIds();
- const cache = getCache();
- const cacheTimes = getCacheTimes();
- let fetchCount = 0;
- const toFetch = [];
- // First pass: hide already-cached blocked threads, identify what needs fetching
- for (const thread of threads) {
- if (cache[thread.id] && !isCacheExpired(thread.id)) {
- if (isBlockedUser(cache[thread.id])) {
- hideThreadRow(thread.row);
- }
- } else {
- toFetch.push(thread);
- }
- }
- // Show status
- let statusEl = document.getElementById('aa-hider-status');
- if (!statusEl && toFetch.length > 0) {
- statusEl = document.createElement('div');
- statusEl.id = 'aa-hider-status';
- statusEl.style.cssText = 'position:fixed;top:10px;right:10px;background:#333;color:#fff;padding:10px;border-radius:5px;z-index:9999;font-size:12px;';
- document.body.appendChild(statusEl);
- }
- // Fetch unknown threads
- for (let i = 0; i < toFetch.length; i++) {
- const thread = toFetch[i];
- if (statusEl) {
- statusEl.textContent = `Scanning threads: ${i + 1}/${toFetch.length}`;
- }
- const author = await fetchThreadAuthor(thread.id);
- if (author) {
- cache[thread.id] = author;
- cacheTimes[thread.id] = Date.now();
- // Save immediately after each fetch
- saveCache(cache);
- saveCacheTimes(cacheTimes);
- if (isBlockedUser(author)) {
- hideThreadRow(thread.row);
- }
- }
- // Delay between requests
- if (i < toFetch.length - 1) {
- await new Promise(resolve => setTimeout(resolve, FETCH_DELAY_MS));
- }
- }
- // Remove status
- if (statusEl) {
- statusEl.textContent = 'Done!';
- setTimeout(() => statusEl.remove(), 2000);
- }
- }
- // Hide posts within thread pages
- function hidePostsInThread() {
- const tables = document.querySelectorAll('table[width="700"]');
- tables.forEach(table => {
- const tableHtml = table.innerHTML;
- for (const blockedUser of BLOCKED_USERS) {
- const authorPattern = new RegExp(
- `<b>Author:<\\/b>(?: |\\s)*(?:<[^>]*>)*\\s*${escapeRegex(blockedUser)}`,
- 'i'
- );
- if (authorPattern.test(tableHtml)) {
- table.style.display = 'none';
- let prev = table.previousElementSibling;
- while (prev && (prev.tagName === 'BR' || prev.tagName === 'A' || prev.tagName === 'P')) {
- prev.style.display = 'none';
- prev = prev.previousElementSibling;
- }
- break;
- }
- }
- });
- // Hide from thread summary at top
- const summaryTds = document.querySelectorAll('table[cellpadding="0"][cellspacing="0"] td');
- summaryTds.forEach(td => {
- for (const blockedUser of BLOCKED_USERS) {
- if (td.textContent.includes(blockedUser)) {
- let parent = td.parentElement;
- if (parent) parent.style.display = 'none';
- }
- }
- });
- }
- // Determine if we're on main page or thread page
- function isMainPage() {
- return window.location.pathname.includes('main.php') ||
- (window.location.pathname === '/' && !window.location.search.includes('thread_id'));
- }
- function isThreadPage() {
- return window.location.search.includes('thread_id') ||
- window.location.pathname.includes('thread.php');
- }
- // Main execution
- if (isMainPage()) {
- processMainPage();
- }
- if (isThreadPage()) {
- hidePostsInThread();
- }
- // Also run on pages that might be both (like forum listings)
- if (!isMainPage() && !isThreadPage()) {
- // Try both approaches
- hidePostsInThread();
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment