滚动条美化

美化网站滚动条样式

// ==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();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址