以前有个能调色板选页面颜色的没找到,用deepseek写的只有暗黑模式能用 ,也不是太满意 现在用的iris护眼 最好有个youhou脚本
win+ctrl+c即可
这是我自用的,也是ai写的。具体介绍见@description
// ==UserScript==
// @name Better Page Dimmer
// @description 自动调低浅色网页的亮度,读取背景色后自动设置。载入时读取一次,载入完成后再读取一次。如果有页面读取失败,可手动调整:Ctrl+Alt+0 开启 / 关闭功能,Ctrl+Alt+R 重置全部设置,Ctrl+Alt+=/- 调高 / 降低亮度。所有手动调整偏好会储存在本地,浏览器重启后也能用。
// @version 7
// @include *
// @author hanzy
// GM_getValue
// GM_setValue
// GM_deleteValue
// GM_listValues
// ==/UserScript==
(function() {if(window.top != window.self) return;
var checkDelay = 3000;
var dim = document.createElement("div");
dim.setAttribute("id", "pageDimmer");
dim.style = "display: none; opacity: 0.8; background: #000; width: 100%; height: 100%; position: fixed; top: 0px; left: 0px; z-index: 10000; pointer-events: none;";
document.body.appendChild(dim);
var initialZIndex = dim.style.zIndex;
var maxZIndex = initialZIndex;
if(document.getElementsByTagName('video').length) {
var elem = document.getElementsByTagName('video')[0];
while(elem = elem.parentElement) {
var style = window.getComputedStyle(elem);
var zidx = style.getPropertyValue('z-index');
if(parseInt(zidx)) maxZIndex = parseInt(zidx);
}
if(maxZIndex == initialZIndex) document.getElementsByTagName('video')[0].style.zIndex = initialZIndex;
}
var toast = document.createElement("div");
toast.setAttribute("id", "pageDimmerToast");
toast.style = "display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background: rgba(0,0,0,0.75); color: #fff; font: bold 18px sans-serif; padding: 8px 16px; border-radius: 6px; z-index: 10002; pointer-events: none; transition: opacity 0.3s; white-space: pre; text-align: center;";
document.body.appendChild(toast);
var toastTimer = null;
function showToast(msg) {
toast.textContent = msg;
toast.style.display = 'block';
toast.style.opacity = '1';
if(toastTimer) clearTimeout(toastTimer);
toastTimer = setTimeout(function() {
toast.style.opacity = '0';
setTimeout(function() { toast.style.display = 'none'; }, 300);
}, 1000);
}
var modalOverlay = document.createElement("div");
modalOverlay.style = "display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.6); z-index: 10003;";
document.body.appendChild(modalOverlay);
var modalBox = document.createElement("div");
modalBox.style = "display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background: #1a1a1a; color: #eee; font: 15px sans-serif; border: 1px solid #555; border-radius: 8px; z-index: 10004; min-width: 300px; overflow: hidden;";
document.body.appendChild(modalBox);
var modalTitle = document.createElement("div");
modalTitle.style = "background: #2a2a2a; color: #fff; font: bold 14px sans-serif; padding: 10px 16px; border-bottom: 1px solid #555;";
modalTitle.textContent = "Better Page Dimmer";
modalBox.appendChild(modalTitle);
var modalMsg = document.createElement("div");
modalMsg.style = "padding: 16px;";
modalBox.appendChild(modalMsg);
var modalButtons = document.createElement("div");
modalButtons.style = "display: flex; justify-content: flex-end; gap: 8px; padding: 10px 16px; border-top: 1px solid #555;";
modalBox.appendChild(modalButtons);
function showModal(msg, buttons) {
modalMsg.textContent = msg;
modalButtons.innerHTML = '';
buttons.forEach(function(btn) {
var b = document.createElement("button");
b.textContent = btn.label;
b.style = "padding: 6px 16px; border-radius: 4px; border: 1px solid #555; background: #2a2a2a; color: #eee; cursor: pointer; font: 14px sans-serif;";
b.onmouseover = function() { b.style.background = '#3a3a3a'; };
b.onmouseout = function() { b.style.background = '#2a2a2a'; };
b.onclick = function() {
modalOverlay.style.display = 'none';
modalBox.style.display = 'none';
btn.action();
};
modalButtons.appendChild(b);
});
modalOverlay.style.display = 'block';
modalBox.style.display = 'block';
}
modalOverlay.onclick = function() {
modalOverlay.style.display = 'none';
modalBox.style.display = 'none';
};
function isPageDark() {
var meta = document.querySelector('meta[name="color-scheme"]');
if(meta && /dark/.test(meta.content)) return true;
var els = [document.documentElement, document.body];
for(var i = 0; i < els.length; i++) {
var cs = window.getComputedStyle(els[i]).colorScheme;
if(cs && /dark/.test(cs)) return true;
}
for(var i = 0; i < els.length; i++) {
var bg = window.getComputedStyle(els[i]).backgroundColor;
var m = bg.match(/\d+/g);
if(m && m.length >= 3) {
var r = parseInt(m[0]), g = parseInt(m[1]), b = parseInt(m[2]), a = m[3] !== undefined ? parseFloat(m[3]) : 1;
if(a === 0) continue;
var brightness = (r * 299 + g * 587 + b * 114) / 1000;
if(brightness <= 80) return true;
if(brightness >= 160) return false;
}
}
return false;
}
function getSLD() {
var host = window.location.hostname;
if(!host) return 'local';
var parts = host.split('.');
return parts.length > 2 ? parts.slice(-3).join('.') : host;
}
function applyDim() {
var sld = getSLD();
var savedState = GM_getValue('pageDimmer_display_' + sld);
if(savedState !== undefined) {
dim.style.display = savedState == '0' ? 'none' : 'block';
} else {
dim.style.display = isPageDark() ? 'none' : 'block';
}
if(GM_getValue('pageDimmer_opacity')) dim.style.opacity = GM_getValue('pageDimmer_opacity');
}
// Apply immediately on load
applyDim();
// Re-check background color after checkDelay in case page changed it late
// Only re-applies if no manual preference is saved for this domain
setTimeout(function() {
var sld = getSLD();
if(GM_getValue('pageDimmer_display_' + sld) === undefined) {
dim.style.display = isPageDark() ? 'none' : 'block';
}
}, checkDelay);
function toggleDim() {
var sld = getSLD();
var savedState = GM_getValue('pageDimmer_display_' + sld);
if(savedState !== undefined) {
GM_deleteValue('pageDimmer_display_' + sld);
dim.style.display = isPageDark() ? 'none' : 'block';
} else {
var newState = dim.style.display == 'block' ? 0 : 1;
dim.style.display = newState == 1 ? 'block' : 'none';
GM_setValue('pageDimmer_display_' + sld, newState);
}
}
function clearPreferences() {
showModal('Clear all saved domain preferences?', [
{
label: 'Clear',
action: function() {
var keys = GM_listValues();
for(var i = 0; i < keys.length; i++) {
if(keys[i].indexOf('pageDimmer_display_') === 0) GM_deleteValue(keys[i]);
}
showModal('Preferences cleared.', [
{ label: 'OK', action: function() {} }
]);
}
},
{ label: 'Cancel', action: function() {} }
]);
}
function adjustDim(add) {
if(dim.style.display == 'none') toggleDim();
var opac = parseFloat(dim.style.opacity);
opac = add ? opac + 0.05 : opac - 0.05;
opac = Math.min(Math.max(opac, 0.0), 0.8);
opac = Math.round(opac * 100) / 100;
dim.style.opacity = opac;
GM_setValue('pageDimmer_opacity', dim.style.opacity);
var brightness = Math.round((1 - opac) * 100);
var msg = 'Brightness: ' + brightness + '%';
if(add && opac >= 0.8) msg += '\nCan\'t go darker than 20%';
showToast(msg);
}
document.addEventListener('keydown', function(e) {
var key = e.keyCode || e.which;
var kMinus, kPlus;
if(/Firefox/.test(navigator.userAgent)) { kMinus = key == 173 || key == 109; kPlus = key == 61 || key == 107; }
else { kMinus = key == 189 || key == 109; kPlus = key == 187 || key == 107; }
if(e.ctrlKey && e.altKey && key == 48) toggleDim(); // CTRL + ALT + 0
if(e.ctrlKey && e.altKey && key == 82) clearPreferences(); // CTRL + ALT + R
if(e.ctrlKey && e.altKey) {
if(kMinus) adjustDim(true); // key -
else if(kPlus) adjustDim(false); // key =
}
});
})();
补充,在violentmonkey上使用正常,没试过其他userscript插件
有人提到油猴我就冒个泡,之前找脚本发现几乎都不能访问了
最后发现有能用的镜像站 https://home.greasyfork.org.cn/zh-hans
可以搜下
单纯只是要护眼的话,Dark Reader。
如果要更丰富一点的自定义(Dark Reader自动调的不一定好看),Stylus
你试试CareUEyes软件,可以自定义屏幕的冷暖色,亮度高度,定制功能比较多
咋做最佳回答来着忘了