tampermonkey 油猴脚本 博客园美化


前言

因为许多博客园都用了自己的美化主题,每次看不同的博客园,加载时快时慢,后来使用简洁模式,但是排版并不是很友好,于是自己写了个油猴脚本,重新排了一下版,调整了字体,去除了一些不必要的内容.

代码

// ==UserScript==
// @name         博客园美化
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  博客园美化
// @author       xiaosongzhuo
// @include    *.cnblogs.com/*
// @lastmodified  2020-01-23
// @note    2022年1月22日
// @license    GPL-3.0-only
// ==/UserScript==

(function () {
  "use strict";

  $("#blogTitle").remove();
  $("#blog-calendar").remove();
  $("#bannerbar").remove();
  $("#ad_text_under_commentbox").remove();
  $("#cnblogs_ch").remove();

  $("#opt_under_post").remove();
  $("#cnblogs_c2").remove();
  $("#rightmenu").remove();
  $("#under_post_card2").remove();
  $("#HistoryToday").remove();

  $("#footer").remove();
  // 侧边栏设置到左边
  $("#sideBar").css({
    left: "0",
  });

  // 设置内容位置
  $("#mainContent").css({
    marginRight: "0px",
    marginLeft: "330px",
    borderLeft: "2px solid grey",
  });
  // 设置正文内容的下边距
  $("#cnblogs_post_body").css({
    marginBottom: "100px",
    fontSize: "17px",
  });
  // 设置h1标题的分割线
  $("#cnblogs_post_body > hr").css({
    border: "2px solid black",
  });
  // 设置目录递进
  $("#cnblogs_post_body > h1").css({
    fontSize: "30px",
    outline: "dashed",
    color: "red",
    marginTop: "30px",
    marginBottom: "30px",
  });
  $("#cnblogs_post_body > h2").css({
    fontSize: "25px",
    outline: "dashed",
    color: "orange",
    marginTop: "30px",
    marginBottom: "30px",
  });
  $("#cnblogs_post_body > h3").css({
    fontSize: "20px",
    outline: "dashed",
    color: "#c8c802",
    marginTop: "30px",
    marginBottom: "30px",
  });
  $("#cnblogs_post_body > h4").css({
    fontSize: "15px",
    outline: "dashed",
    color: "green",
    marginTop: "30px",
    marginBottom: "30px",
  });
  $("#cnblogs_post_body > h5").css({
    fontSize: "10px",
    outline: "dashed",
    color: "blue",
    marginTop: "30px",
    marginBottom: "30px",
  });
  $("#cnblogs_post_body > h6").css({
    fontSize: "5px",
    outline: "dashed",
    color: "purple",
    marginTop: "30px",
    marginBottom: "30px",
  });

  // 设置标题字体的大小
  $("#topics > div.post > h1").css({
    marginBottom: "30px",
    fontSize: "30px",
  });
  // 设置返回顶部的按钮
  $("#comment_nav > a:nth-child(4)").css({
    position: "fixed",
    border: "1px solid red",
    top: "0px",
    right: "0px",
    backgroundColor: "rgb(230 1 19 / 50%)",
  });

  // 设置目录按钮的位置
  $("#topics > div.post > h1 > button").css({
    position: "absolute",
    left: "0px",
  });

  // 点击显示目录按钮
  const content = $("#topics > div.post > h1 > button");
  if (content) {
    // 点击目录按钮,弹出目录
    content[0].click();
  }
})();

const sleep = (time) => {
  var startTime = new Date().getTime() + parseInt(time, 10);
  while (new Date().getTime() < startTime) {}
};