Full Ignore bitcointalk users

Ignore quotes from users you already ignore on the forum

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Full Ignore bitcointalk users
// @version      0.1
// @description  Ignore quotes from users you already ignore on the forum
// @author       TryNinja
// @match        https://bitcointalk.org/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=bitcointalk.org
// @grant GM_setValue
// @grant GM_getValue

// @namespace https://greasyfork.org/users/1070272
// ==/UserScript==

(async function () {
	'use strict';

	let list;

	const isLogged = document.querySelector('#hellomember') !== null;
	if (!isLogged) return;

	const getCachedList = () => {
		const cached = GM_getValue('ignoreListCache');
		if (cached) {
			const parsed = JSON.parse(cached);
			const cacheDate = new Date(parsed.date);
			const oneHourAgo = new Date(Date.now() - 60 * 60 * 1000);

			if (cacheDate > oneHourAgo) {
				return parsed;
			}
		}
		return null;
	};

	const setCachedList = (list) => {
		return GM_setValue('ignoreListCache', JSON.stringify({ list, date: new Date().toISOString() }));
	};

	const fetchIgnoreList = async () => {
		const res = await fetch('https://bitcointalk.org/index.php?action=profile;sa=ignprefs');
		const html = await res.text();
		const parser = new DOMParser();
		const page = parser.parseFromString(html, 'text/html');
		const ignoreListTextArea = page.querySelector('#ign_ignore_list');
		const ignoreListUsers = ignoreListTextArea?.textContent?.split('\n');
		return ignoreListUsers;
	};

	const cached = getCachedList();
	if (cached) {
		list = cached.list;
	} else {
    console.log('No cached ignore list, fetching now...')
		list = await fetchIgnoreList();
		setCachedList(list);    
	}

	console.log('ignore list', { list });

  const quoteHeaders = document.querySelectorAll('.post .quoteheader')

  for (const quoteHeader of quoteHeaders) {
    const quoteBody = quoteHeader.nextElementSibling
    const authorMatch = quoteHeader.getHTML().match(/Quote from: (.*) on/)
    if (authorMatch && authorMatch[1]) {
      if (list.includes(authorMatch[1]) && quoteBody) {
        quoteBody.innerHTML = 'USER IS IGNORED'
      }
    }
  }
})();