selection-black

1/6/2024, 10:02:43 PM

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

Advertisement:

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

Advertisement:

// ==UserScript==
// @name        selection-black
// @namespace   Violentmonkey Scripts
// @match       *://*/*
// @grant       none
// @version     0.0.1
// @author      -
// @description 1/6/2024, 10:02:43 PM
// @license GPLv2
// ==/UserScript==

// 创建一个新的 style 元素
var style = document.createElement('style');

// 设置 CSS 规则
// 注意:这里使用了 ES6 模板字符串来保持 CSS 规则的格式,也可以使用普通的字符串连接
var css = `::selection {
            color: #fafafa;
            background: #0a0a0a;
          }`

// 为了兼容不同的浏览器,需要检查一下是否存在某些 DOM 方法
if (style.styleSheet) {
  // 这是给 IE 的老版本使用的
  style.styleSheet.cssText = css;
} else {
  // 其他大部分浏览器
  style.appendChild(document.createTextNode(css));
}

// 将 style 元素添加到 head 中
document.head.appendChild(style);