「蜜柑计划」列表过滤(简繁/画质)

过滤蜜柑计划列表,按照简繁/画质过滤

目前为 2022-07-16 提交的版本。查看 最新版本

// ==UserScript==
// @name         「蜜柑计划」列表过滤(简繁/画质)
// @namespace    https://www.wdssmq.com/
// @version      0.1
// @author       沉冰浮水
// @description  过滤蜜柑计划列表,按照简繁/画质过滤
// @license      MIT
// @null         ----------------------------
// @contributionURL    https://github.com/wdssmq#%E4%BA%8C%E7%BB%B4%E7%A0%81
// @contributionAmount 5.93
// @null         ----------------------------
// @link         https://github.com/wdssmq/userscript
// @link         https://afdian.net/@wdssmq
// @link         https://gf.qytechs.cn/zh-CN/users/6865-wdssmq
// @null         ----------------------------
// @noframes
// @match        https://mikanani.me/Home/Bangumi/*
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_registerMenuCommand
// @grant        GM_unregisterMenuCommand
// @grant        GM_setClipboard
// ==/UserScript==

/* jshint esversion: 6 */

(function () {
  'use strict';

  const gm_name = "Mikan_Proj";

  // ---------------------------------------------------
  const _log = (...args) => console.log(`[${gm_name}]\n`, ...args);
  function $na(e) {
    return document.querySelectorAll(e);
  }

  const _config = {
    data: {},
    dataOpt: {
      size: ["720", "1080"],
      subtitle: ["tc", "sc"]
    },
    optToggle: (opt, ret = false) => {
      const dataOpt = _config.dataOpt;
      const oldVal = _config.data[opt];
      const newVal = oldVal === dataOpt[opt][0] ? dataOpt[opt][1] : dataOpt[opt][0];
      if (ret) {
        return newVal;
      }
      _config.data[opt] = newVal;
      GM_setValue("config", _config.data);
    },
    menuCommand: () => {
      const _this = _config;
      for (const key in _this.data) {
        if (Object.hasOwnProperty.call(_this.data, key)) {
          const newValue = _this.optToggle(key, true);
          _log(`${key} ${newValue}`);
          GM_registerMenuCommand(`切换至 ${newValue}`,
            () => {
              _this.optToggle(key);
              // 刷新页面
              window.location.reload();
            }
          );
        }
      }
    },
    load: () => {
      _config.data = GM_getValue("config", {
        size: "1080",
        subtitle: "sc"
      });
      _config.menuCommand();
    },
  };

  _config.load();

  const _filter_map = {
    "tc": ["big5", "繁日双语", "繁体内嵌"],
    "sc": ["gb", "简日双语"],
    "720": ["720"],
    "1080": ["1080"],
  };

  const fnGenFilter = (opt) => {
    const filter = {};
    const string = JSON.stringify(opt);
    if (string.includes("720")) {
      filter["size"] = _filter_map["1080"];
    }
    if (string.includes("1080")) {
      filter["size"] = _filter_map["720"];
    }
    if (string.includes("tc")) {
      filter["subtitle"] = _filter_map["sc"];
    }
    if (string.includes("sc")) {
      filter["subtitle"] = _filter_map["tc"];
    }
    return filter;
  };

  const _filter = fnGenFilter(_config.data);
  _log(_filter);

  // 过滤含有指定字符的节点
  function fnFilter(text, filter) {
    let bolBlock = false;
    for (const key in filter) {
      if (Object.hasOwnProperty.call(filter, key)) {
        const element = filter[key];
        for (let i = 0; i < element.length; i++) {
          // _log(element[i], text, text.includes(element[i]));
          if (text.includes(element[i])) {
            bolBlock = true;
            break;
          }
        }
      }
    }
    return bolBlock;
  }

  // 遍历 nodeList
  function fnEachNodeList(nodeList, fn) {
    // 倒序遍历
    for (let i = nodeList.length - 1; i >= 0; i--) {
      fn(nodeList[i], i);
    }
  }

  // 添加批量复制磁力链接功能
  function fnAddBatchCopy($th, magnetList) {
    const $btn = document.createElement("button");
    $btn.innerText = "批量复制";
    $btn.addEventListener("click", () => {
      const magnetStr = magnetList.join("\n");
      GM_setClipboard(magnetStr);
      $btn.innerText = "复制成功";
      _log(`已复制 ${magnetStr}`);
    }, false);
    // appendChild 2 elements
    $th.appendChild($btn);
  }


  // main
  function fnMain() {
    const $listTr = $na("table tr");
    _log($listTr.length);
    let $curTh = null;
    // let $lstTh = null;
    let magnetList = [];
    fnEachNodeList($listTr, ($tr, i) => {
      if ($tr.innerText.includes("番组名")) {
        $curTh = $tr.querySelector("th");
        // $lstTh = $curTh;
        _log($curTh);
        fnAddBatchCopy($curTh, magnetList);
        magnetList = [];
        // return;
      }
      const $curA = $tr.querySelector(".magnet-link-wrap");
      const $curB = $tr.querySelector(".js-magnet");
      if (!$curA) {
        return;
      }
      const curText = $curA.innerText.toLowerCase();
      // data-clipboard-text
      const magnet = $curB.getAttribute("data-clipboard-text");
      if (fnFilter(curText, _filter)) {
        _log(`${curText} ${magnet}`);
        $tr.remove();
      } else {
        magnetList.push(magnet);
      }
      // _log(`${i} ${curText}`);
    });
  }

  // 自动展开更多
  function fnAutoExpand() {
    const $listBtn = $na(".js-expand-episode");
    fnEachNodeList($listBtn, ($btn, i) => {
      $btn.click();
    });
    setTimeout(() => {
      fnMain();
    }, 3000);
  }
  fnAutoExpand();

  // fnElChange($n(".central-container"),
  //   () => {
  //     fnMain();
  //   }
  // )

})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址