Greasy Fork

Greasy Fork is available in English.

bilibili-filter-roll-ads

过滤b站换一换中的广告。(filter bilibili roll ads.)

当前为 2024-11-30 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        bilibili-filter-roll-ads
// @namespace   Violentmonkey Scripts
// @match       https://www.bilibili.com/
// @run-at      document-start
// @grant       none
// @version     1.2
// @author      mesimpler
// @license     MIT
// @description 过滤b站换一换中的广告。(filter bilibili roll ads.)
// ==/UserScript==

const rmcd = "//api.bilibili.com/x/web-interface/wbi/index/top/feed/rcmd";
const feedNum = 12;

window.fetch = new Proxy(window.fetch, {
  apply: function (target, thisArg, argumentsList) {
    const [url, options] = argumentsList;

    // 请求命中
    if (url.includes(rmcd)) {
      const hookUrl = url.replace("ps=10", `ps=${feedNum}`);
      const hookOptions = {
        ...options,
        params: {
          ...options.params,
          ps: feedNum,
        },
      };

      return Reflect.apply(target, thisArg, [hookUrl, hookOptions]).then(
        (response) => {
          return response.json().then((res) => {
            // 过滤广告特征
            res.data.item = res.data.item.filter((video) => video.id !== 0);
            return new Response(JSON.stringify(res), response);
          });
        }
      );
    }

    // 调用原始 fetch
    return Reflect.apply(target, thisArg, argumentsList);
  },
});