becoder

2024/1/23 15:25:23

目前為 2024-11-04 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        becoder
// @namespace   Violentmonkey Scripts
// @match       https://www.becoder.com.cn/*
// @grant       none
// @version     1.5
// @author      EarthMessenger
// @description 2024/1/23 15:25:23
// @license MIT
// ==/UserScript==

(() => {
  const fixRightClick = () => {
    window.oncontextmenu = null;
    document.oncontextmenu = null;
  };

  const fixPDF = () => {
    const iframes = document.querySelectorAll("iframe");
    const pat =
      /https:\/\/www\.becoder\.com\.cn\/js\/pdf\/web\/viewer\.html\?file=(\S*)/gm;
    for (const oldPdf of iframes) {
      const res = pat.exec(oldPdf.src);
      if (res == null) continue;
      const url = res[1];
      fetch(url)
        .then((resp) => resp.blob())
        .then((blob) => blob.slice(0, blob.size, "application/pdf"))
        .then((blob) => {
          const newPdf = document.createElement("iframe");
          newPdf.src = URL.createObjectURL(blob);
          newPdf.width = oldPdf.width;
          newPdf.height = oldPdf.height;
          const parent = oldPdf.parentNode;
          parent.replaceChild(newPdf, oldPdf);
        });
    }
  };

  const fixHomePage = () => {
    if (window.location.pathname !== "/index") return;

    const mainDiv = document.querySelector("div.main > div");
    mainDiv.children[0].classList.replace("eleven", "sixteen");

    mainDiv.removeChild(mainDiv.children[1]); // 右欄

    const column = mainDiv.children[0];
    column.removeChild(column.children[4]); // 提交次數統計圖
    column.removeChild(column.children[0]); // AI 頭圖
  };

  const redirectHomePage = () => {
    if (window.location.pathname === "/") {
      window.location.replace(new URL("/index", location.href).toString());
    }
  };

  fixRightClick();
  fixPDF();
  fixHomePage();
  redirectHomePage();
})();