Greasy Fork

Greasy Fork is available in English.

滚动条美化

美化网站滚动条样式

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        滚动条美化
// @description 美化网站滚动条样式
// @namespace   Violentmonkey Scripts
// @match       *://*/*
// @exclude     *://127.0.0.1*
// @exclude     *://localhost*
// @grant       none
// @version     1.4.0
// @author      -
// @description 2022/10/1 21:54:49
// @grant        GM_registerMenuCommand
// @grant        GM_unregisterMenuCommand
// @grant        GM_getValue
// @grant        GM_setValue
// @license MIT
// @run-at      document-body
// ==/UserScript==

const styleSheet = document.createElement('style');
styleSheet.id = 'beautify-scrollbar';
document.head.appendChild(styleSheet);

const powerList = GM_getValue('powerList') || [];

const setDefaultStyle = (init = true) => {
  styleSheet.textContent = `
    body {
      overflow-y: overlay !important;
    }

    body::-webkit-scrollbar {
      width: 10px;
    }

    body::-webkit-scrollbar-thumb {
      background-color: #d9d9d9;
      border-radius: 9999em;
    }
  `;
  if (!init) {
    for (const index in powerList) {
      if (powerList[index] === window.location.host.toString()) {
        powerList.splice(index, 1);
        GM_setValue('powerList', powerList);
        break;
      }
    }
  }
};

const enablePowerMode = (host = null) => {
  styleSheet.textContent += `
    html {
      overflow-y: overlay !important;
    }
  `;
  if (host) {
    powerList.push(host);
    GM_setValue('powerList', powerList);
  }
};

const hasPowerList = () => {
  const host = window.location.host;
  return powerList.includes(host);
};

let enableId;
// 添加油猴设置菜单
function addUserSetting() {
  enableId = GM_registerMenuCommand(`该网站${hasPowerList() ? '关闭' : '开启'}强力模式`, () => {
    hasPowerList() ? setDefaultStyle(false) : enablePowerMode(window.location.host);
    GM_unregisterMenuCommand(enableId);//删除菜单
    addUserSetting(); // 重新注册脚本菜单
  });
}

function init() {
  setDefaultStyle();
  hasPowerList() && enablePowerMode();
  addUserSetting();
}

init();