绿色纯净版CSDN-持续更新

绿色纯净版CSDN-持续更新,现支持🔥免登录复制🔥沉浸式阅读🆕登录自动展开评论,并添加到页面底部

目前為 2024-01-16 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         绿色纯净版CSDN-持续更新
// @namespace    CSDNGreen
// @version      0.0.53
// @description  绿色纯净版CSDN-持续更新,现支持🔥免登录复制🔥沉浸式阅读🆕登录自动展开评论,并添加到页面底部
// @author       LiuHangShu
// @include      *://*.csdn.net/*
// @license      AGPL-3.0-or-later
// @note         24-1-11 0.0.51 jq-err
// @note         24-1-15 0.0.52 沉浸式阅读
// @note         24-1-15 0.0.53 登录情况下默认展开所有评论,并添加到页面底部
// ==/UserScript==

const version = "0.0.53";

class CSDNGreen {
  constructor() {
    this.rmMap = new Map();
  }

  main() {
    this.copy();
    this.fullScreen();
    this.greenMode();
    this.clean();
    this.comment();
    console.log("正在运行");
  }

  push(element) {
    if (Array.isArray(element)) {
      element.forEach((item) => {
        const name = item.attr("class") || item.attr("id");
        if (!this.rmMap.has(name)) {
          this.rmMap.set(name, item);
        }
      });
      return;
    }
    const name = element.attr("class") || element.attr("id");
    if (!this.rmMap.has(name)) {
      this.rmMap.set(name, element);
    }
  }

  copy() {
    try {
      if (typeof $ == "undefined") {
        console.log("jQuery is not loaded");
        return;
      }
      // 免登录复制
      $(".hljs-button").removeClass("signin");
      $(".hljs-button").addClass("{2}");
      $(".hljs-button").attr("data-title", "免登录复制");
      $(".hljs-button").attr(
        "onclick",
        "hljs.copyCode(event);setTimeout(function(){$('.hljs-button').attr('data-title', '免登录复制');},3500);"
      );
      $("#content_views").unbind("copy");
      // 去除剪贴板劫持
      $("code").attr("onclick", "mdcp.copyCode(event)");
      try {
        Object.defineProperty(window, "articleType", {
          value: 0,
          writable: false,
          configurable: false,
        });
      } catch (err) {}
      try {
        unsafeWindow.csdn.copyright.init("", "", "");
      } catch (_err) {}
      console.log("copy fn run success");
    } catch (err) {
      $$("*").forEach((item) => {
        item.oncopy = (e) => e.stopPropagation();
      });
      console.log("copy fn run error");
    }
  }

  fullScreen() {
    $(".blog_container_aside").remove();
    $("main").css("width", "100%");
    $(".csdn-side-toolbar").remove();
    console.log("fullScreen fn run success");
  }

  greenMode() {
    // 登录
    const loginModal = $(".passport-login-container");
    // 红包
    const redpackModal = $("#csdn-redpack");
    const iframe = $("iframe");
    const toolBarBox = $(".more-toolbox-new");
    const blogHuaweiyunAdvert = $("#blogHuaweiyunAdvert");
    const blogColumnPayAdvert = $("#blogColumnPayAdvert");
    const recommendNps = $("#recommendNps");
    const recommendBox = $(".recommend-box");
    const articleInfoBox = $(".article-info-box");
    const adverts1 = $(".J_adv");
    const adverts2 = $(".feed-fix-box");
    this.push([
      loginModal,
      redpackModal,
      iframe,
      toolBarBox,
      blogHuaweiyunAdvert,
      blogColumnPayAdvert,
      adverts1,
      adverts2,
      recommendNps,
      recommendBox,
      articleInfoBox,
    ]);
  }

  comment() {
    // 登录默认展开评论
    if ($(".toolbar-btn-loginfun").text() != "登录") {
      const list = $(".comment-list-container");
      const comment = $("#pcCommentBox");
      comment.append(list);

      // 加载所有评论
      let timer = setInterval(function () {
        const childrenComment = $("#lookGoodComment");
        if (
          childrenComment.css("display") &&
          childrenComment.css("display") != "none"
        ) {
          childrenComment.click();
        } else {
          clearInterval(timer);
        }
      }, 1000);

      setTimeout(() => {
        // 打开所有子评论
        $(".second-look-more").each((idx, _) => {
          _ && _.click();
        });
      }, 10000);
    }
  }

  clean() {
    // console.log(this.rmMap, this.rmMap.size, "this.rmMap.length");
    if (this.rmMap.size) {
      let t = this;
      let timer = setInterval(function () {
        const clear = !t.rmMap.size;
        if (clear) {
          clearInterval(timer);
        }
        for (const [key, value] of t.rmMap) {
          if (value) {
            value.remove();
            t.rmMap.delete(key);
          }
        }
      }, 500);
    }
  }
}

(function () {
  "use strict";
  const csdnGreen = new CSDNGreen();
  setTimeout(function () {
    csdnGreen.main();
  }, 500);
})();