小贝家园文章过滤

不显示不感兴趣的文章

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         小贝家园文章过滤
// @namespace    http://KzFbBg.net/
// @version      1.1
// @description  不显示不感兴趣的文章
// @author       LeifengXia
// @match        http://ispankhome.com/*
// @require      https://code.jquery.com/jquery-3.6.0.min.js
// @icon         https://www.google.com/s2/favicons?domain=csdn.net
// @grant GM_log
// @grant unsafeWindow
// ==/UserScript==

(function () {
  "use strict";

  // Your code here...
  const KEY = "filterd-articles";
  function getFilteredArticles() {
    let filtered = window.localStorage.getItem(KEY);
    if (filtered) {
      console.log("filtered", filtered);
      return JSON.parse(filtered);
    } else {
      return [];
    }
  }
  const filteredArticles = getFilteredArticles();

  function createButton(articleId) {
    return (
      '<button type="button" onclick=window.notInterestedIn("' +
      articleId +
      '")>不感兴趣</button>'
    );
  }

  unsafeWindow.notInterestedIn = function (articleId) {
    console.log("you are not interested in " + articleId + ".");
    $("#" + articleId).remove();
    filteredArticles.push(articleId);
    window.localStorage.setItem(KEY, JSON.stringify(filteredArticles));
  };

  $(document).ready(function () {
    let articleRoot = $("#threadlisttableid");
    let articles = articleRoot.children();
    articles.each((i, e) => {
      let ele = $(e);
      let id = String(ele.attr("id"));
      if (id.indexOf("normalthread") !== -1) {
        if ($.inArray(id, filteredArticles) >= 0) {
          $("#" + id).remove();
        } else {
          ele.find(".common").append(createButton(id));
        }
      }
    });
  });
})();