// ==UserScript== // @name 暗色的Epic游戏商店页面 // @namespace https://scriptcat.org/zh-CN/script-show-page/3333 // @version 0.5 // @description Epic游戏商店页面, 开盲盒一样呢, 必须闪你眼 // @author beibeibeibei // @license MIT // @match https://store.epicgames.com/zh-CN/p/* // @match https://store.epicgames.com/zh-CN/all-dlc/* // @match https://store.epicgames.com/zh-CN/achievements/* // @match https://store.epicgames.com/zh-CN/news/* // @match https://store.epicgames.com/purchase* // @grant GM_addStyle // ==/UserScript== (function() { 'use strict'; // 亮色页面举例 // 毛线先生https://store.epicgames.com/zh-CN/p/chuchel-203808 // 蓝精灵2:绿石之囚https://store.epicgames.com/zh-CN/p/the-smurfs-2-the-prisonner-of-the-green-stone-ba4653 // 小雷神https://store.epicgames.com/zh-CN/p/tiny-thor-76de1f // 模拟鹿https://store.epicgames.com/zh-CN/p/deeeer-simulator-9bfc4a // 海豚精灵:海洋任务https://store.epicgames.com/zh-CN/p/dolphin-spirit-ocean-mission-2d0f3b // 深蓝 // https://store.epicgames.com/zh-CN/p/sail-forth-51847e // https://store.epicgames.com/zh-CN/p/the-werecleaner-736968 // https://store.epicgames.com/zh-CN/p/tiny-lands-527466 // https://store.epicgames.com/zh-CN/p/machinarium-5e6c71 // https://store.epicgames.com/zh-CN/p/naiad-88d201 // https://store.epicgames.com/zh-CN/p/samorost-1-280ea4 // 棕色 // https://store.epicgames.com/zh-CN/p/doggy-farmer-915382 // 紫色 // https://store.epicgames.com/zh-CN/p/buddy-and-friends-in-halloween-192190 // 自动重试获取元素 function findElementWithRetry(selector, text, delay, maxAttempts) { return new Promise((resolve, reject) => { let attemptCount = 0; function tryGetElement() { const elements = document.querySelectorAll(selector); let foundElement = null; elements.forEach(el => { if (el.textContent.includes(text)) { foundElement = el; } }); if (foundElement) { resolve(foundElement); } else if (attemptCount < maxAttempts) { attemptCount++; setTimeout(tryGetElement, delay); } else { reject(new Error(`无法在 ${maxAttempts} 次尝试内获取到元素`)); } } tryGetElement(); }); } function isDarkColor(color) { // 处理不同的颜色格式 let r, g, b; // 十六进制颜色 if (color.startsWith('#')) { // 去掉#号 color = color.slice(1); // 处理3位 shorthand if (color.length === 3) { color = color.split('').map(c => c + c).join(''); } // 确保是6位颜色 if (color.length !== 6) { throw new Error('Invalid hex color format'); } r = parseInt(color.substring(0, 2), 16); g = parseInt(color.substring(2, 4), 16); b = parseInt(color.substring(4, 6), 16); } // RGB颜色 else if (color.startsWith('rgb')) { // 处理RGB格式 (例如: rgb(255, 255, 255)) const rgbMatch = color.match(/\(([\d, ]+)\)/); if (rgbMatch) { const rgbValues = rgbMatch[1].split(',').map(num => parseInt(num.trim(), 10)); [r, g, b] = rgbValues; } else { throw new Error('Invalid rgb color format'); } } // RGBA颜色,忽略透明度 else if (color.startsWith('rgba')) { const rgbMatch = color.match(/\(([\d, .]+)\)/); if (rgbMatch) { const rgbValues = rgbMatch[1].split(',').map((val, i) => i < 3 ? parseInt(val.trim(), 10) : parseFloat(val.trim())); [r, g, b] = rgbValues.slice(0, 3); } else { throw new Error('Invalid rgba color format'); } } // 如果不是识别的格式,抛出错误 else { console.log("%c%s", "color:orange;", "Error: Unsupported color format. Use hex, rgb, or rgba."); return true; } // 计算颜色亮度(基于人眼对不同颜色的敏感程度) const brightness = (0.299 * r + 0.587 * g + 0.114 * b) / 255; // 如果亮度小于0.5,则认为是深色 return brightness < 0.5; } // 查找第n多的类名, 还要求找到的类名里, 第一个元素和第二个元素的父节点是同一个元素 function findNthMostCommonClass(parentNode, n) { // 检查n是否是正整数 if (n <= 0) { return { class: "n必须是一个大于0的正整数", count: 0 }; } // 获取父节点下的所有元素 const elements = parentNode.querySelectorAll('*'); // 统计类名出现的次数和父节点信息 const classCount = {}; const classParents = {}; elements.forEach(element => { const className = element.getAttribute('class'); if (className) { const classNames = className.split(' '); classNames.forEach(className => { if (className) { classCount[className] = (classCount[className] || 0) + 1; if (!classParents[className]) { classParents[className] = new Set(); } classParents[className].add(element.parentNode); } }); } }); // 筛选符合父节点条件的类名 const filteredClassCount = {}; for (const className in classCount) { if (classParents[className].size === 1 && classCount[className] >= 2) { filteredClassCount[className] = classCount[className]; } } // 将类名和出现次数转换为数组 const filteredClassCountArray = Object.entries(filteredClassCount); // 按出现次数从高到低排序 filteredClassCountArray.sort((a, b) => b[1] - a[1]); // 找出第n多的类名 if (filteredClassCountArray.length >= n) { return { class: filteredClassCountArray[n - 1][0], count: filteredClassCountArray[n - 1][1] }; } else { return { class: "没有符合条件的类名", count: 0 }; } } function isGameMainPage() { // 根据 data-testid 属性判断游戏本体页面 // [href="https://www.globalratings.com/ratingsguide.aspx#generic"] const carouselSlider = document.querySelector('[data-testid="carousel-slider"]'); const aboutLongDescription = document.getElementById('about-long-description'); return carouselSlider !== null && aboutLongDescription !== null; } function isGameDLCPage() { // 根据 h1 标签的文字内容判断 DLC 页面 const h1Elements = document.querySelectorAll('h1'); for (let i = 0; i < h1Elements.length; i++) { const h1Text = h1Elements[i].textContent; if (h1Text.includes('DLC 和附加内容')) { return true; } } return false; } function isGameAchievementPage() { // 根据 data-testid 属性判断成就页面 const achievementHero = document.querySelector('[data-testid="AchievementHero"]'); return achievementHero !== null; } // 最后一次触发回调的时间 let lastTriggerTime = 0; // 防抖时间间隔(毫秒) const debounceInterval = 3000; // 创建 MutationObserver 实例 const observer = new MutationObserver(function(mutations) { // 获取当前时间 const currentTime = Date.now(); // 如果距离上一次触发回调的时间间隔小于防抖时间间隔,则不执行回调 if (currentTime - lastTriggerTime < debounceInterval) { return; } // 更新最后触发回调的时间 lastTriggerTime = currentTime; // 页面跳转后 URL 会变化,获取当前 URL const currentUrl = window.location.href; // 根据页面特征判断当前页面类型 let currentPageType = ''; if (isGameMainPage()) { currentPageType = '游戏本体页面'; } else if (isGameDLCPage()) { currentPageType = '游戏 DLC 页面'; } else if (isGameAchievementPage()) { currentPageType = '游戏成就页面'; } else { currentPageType = '未知页面'; } // 监听结果 // console.log('当前页面类型:' + currentPageType); // console.log('当前 URL:' + currentUrl); if (window.location.href.startsWith('https://store.epicgames.com/zh-CN/p/')) { // 不根据监听结果直接设置颜色['基础游戏', '附加内容'] Array.from(document.querySelectorAll('aside span span')).filter(span => ['基础游戏', '附加内容'].some(char => span.textContent.includes(char))).forEach(span => { span.parentElement.parentElement.parentElement.style.background = "#343437"; span.style.setProperty('color', 'white', 'important'); }); // 游戏简介 document.querySelector('[data-testid="expand-collapse-button"]')?.parentElement.parentElement.parentElement.firstChild.firstChild.style.setProperty('color', 'white', 'important'); // 系统要求 for (const h3 of document.querySelectorAll("h3")) { if (h3.textContent.includes("系统要求")) { h3.parentElement.nextElementSibling.firstChild.style.background = "#202024"; } } // 设置下边框 const result = findNthMostCommonClass(document.querySelector('aside'), 1); // console.log(`出现次数第${nth}多的类名是:${result.class},出现了${result.count}次`); // border-bottom: 1px solid rgba(0, 0, 0, 0.15); // border-bottom: 1px solid rgba(255, 255, 255, 0.15); document.querySelectorAll("." + result.class).forEach((e) => { e.style.borderBottom = "1px solid rgba(255, 255, 255, 0.15)"; }) // 判断购买按钮是否对比度过低 // 黄色背景rgb(227, 174, 64) rgb(255, 239, 29) rgb(199, 144, 30) findElementWithRetry('[data-testid="purchase-cta-button"]', '', 100, 10).then((buyBtn) => { const buybtnbgcolors = getComputedStyle(buyBtn).backgroundColor.match(/\d+/g); if (buybtnbgcolors[0] >= 199 && buybtnbgcolors[1] >= 144 && buybtnbgcolors[1] <= 239 && buybtnbgcolors[2] <= 64) { /*购买按钮文字*/ /*DLC加入购物车文字*/ //[data-testid="purchase-cta-button"] span, //[data-testid="add-to-cart-cta-button"] span{ // text-shadow: 3px 3px 4px black, -3px -3px 4px black, -3px 3px 4px black, 3px -3px 4px black; //} Array.from(document.querySelector('[data-testid="purchase-cta-button"]').querySelectorAll('span')).reverse()[0].style.textShadow = "0px -3px 4px black, -3px 3px 4px black, 3px 3px 4px black, 0px 0px 4px black"; document.querySelectorAll('[data-testid="add-to-cart-cta-button"]').forEach((b) => { Array.from(b.querySelectorAll('span')).reverse()[0].style.textShadow = "0px -3px 4px black, -3px 3px 4px black, 3px 3px 4px black, 0px 0px 4px black"; }); } }).catch(error => { console.log(error.error); }); } // 根据监听结果切换颜色(总览/附加内容/成就系统)(不一定有三个,也可能一个都没有) findElementWithRetry('ul', '总览', 500, 10) .then(ulElement => { // 找到sticky-nav中的三个切换选项卡(总览/附加内容/成就系统)(不一定有三个,也可能一个都没有,也可能有'常见问题') const sticky_nav_btns = ulElement.querySelectorAll("li span>*"); let mainBtn; let dlcBtn; let achievementBtn; sticky_nav_btns.forEach(b => { if (b.textContent.includes('总览')) { mainBtn = b; } else if (b.textContent.includes('附加内容')) { dlcBtn = b; } else if (b.textContent.includes('成就系统')) { achievementBtn = b; } }); sticky_nav_btns.forEach((b) => { // 重置颜色 color: rgba(255, 255, 255, 0.65) !important; b.style.setProperty('color', 'rgba(255, 255, 255, 0.65)', 'important'); }); //设置颜色 switch (currentPageType) { case '游戏本体页面': mainBtn?.style.setProperty('color', 'white', 'important'); break; case '游戏 DLC 页面': dlcBtn?.style.setProperty('color', 'white', 'important'); break; case '游戏成就页面': achievementBtn?.style.setProperty('color', 'white', 'important'); break; case '未知页面': break; default: break; } }).catch(error => { console.log(error.error); }); }); const css = ` /* 参考gta5页面 https://store.epicgames.com/zh-CN/p/grand-theft-auto-v */ egs-navigation { background: #161618; } main { background-color: #101014; } /* 包含搜索和导航的头部区域 */ main > div:first-child { background-color: #101014; } main > div:first-child > div:first-child { background-color: #101014; } main > div:first-child * { color: white !important; } #SearchLayout { background: rgb(32, 32, 36); &:hover { transition: background 125ms ease-in-out; background: rgb(64, 64, 68); } svg * { color: rgba(255, 255, 255, 0.65) !important; } input::placeholder { color: rgba(255, 255, 255, 0.65) !important; } } /*搜索结果弹窗*/ [data-tippy-root] > div { box-shadow: rgba(0, 0, 0, 0.3) 0px 5px 10px; background: #18181c; } /* 页面主体 */ main > :nth-child(2) { background: rgb(16, 16, 20); color: white; * { color: white !important; } /*游戏名称*/ h1 { color: white !important; } /*游戏分数*/ div[data-testid*='star-ratings'] span > svg > path { stroke: white; } div[data-testid*='star-ratings'] + div span { color: white !important; } /*游戏标签*/ *:has(> div[data-testid*='star-ratings']) + * { background-color: #101014; } *:has(> div[data-testid*='star-ratings']) + * span { color: white !important; } /*sticky-nav*/ div[data-testid*='sticky-nav'] { background-color: #101014; li span > *:hover { filter: drop-shadow(0px 0px 3px gray); } a:focus::before { border: 1px solid white; } } /*切换幻灯片按钮(覆盖在video上的)*/ [data-testid="prev-button"], [data-testid="next-button"] { filter: drop-shadow(0px 0px 3px black); } /*修复幻灯片周围有一丝白边*/ li:has(video) > div { background: #101014; } /*播放设置弹窗*//*自动播放设置*/ [data-testid="settings-container"] { background: #101014; width: 230px; /*撑起宽度, 防止文字竖排*/ } /*非自动播放时显示的视频时长*/ video + * > button { background: #101014; } /*圆形播放状态提示*/ [role="status"][data-testid="status-icon"] { background: black; } /*播放完成视频中心覆盖的播放胶囊按钮*/ [data-testid="controls"] + div > button { background: black; } /*播放控制*/ [data-testid="controls"] > li { filter: drop-shadow(1px 1px 1px black); } /*切换幻灯片按钮(video下方的)*/ [aria-label*="一张幻灯片"]:not([data-testid="prev-button"], [data-testid="next-button"])::before { background-color: rgba(0, 0, 0, 0.15); border: 1px solid gray; } [aria-label*="一张幻灯片"]:not([data-testid="prev-button"], [data-testid="next-button"]):hover::before { background-color: rgba(0, 0, 0, 0.35); border: 1px solid white; } [aria-label*="一张幻灯片"]:not([data-testid="prev-button"], [data-testid="next-button"]):focus::before { border: 2px solid white; } /*年龄分级*/ [href="https://www.globalratings.com/ratingsguide.aspx#generic"] > * { border: 1px solid #ffffff26; &:hover { border: 1px solid white; } } /*aside*/ aside * { color: white !important; } /*游戏类型/特色*/ [data-testid="about-metadata-layout-column"] * { color: white !important; a { background-color: #343437; &:hover { background-color: #636366; } } } /*长介绍*/ #about-long-description * { color: white !important; } /*长介绍展开按钮*/ [data-testid="expand-collapse-button"] { color: white !important; } /*长介绍不展开时的渐变底部效果*/ [data-testid="expand-collapse-button"] + div { background: linear-gradient(rgba(16, 16, 20, 0), rgb(16, 16, 20)); } /*游戏版本*/ .swiper-wrapper .swiper-slide > div > :nth-child(2) { border: 1px solid #0000; &:hover { background: #101014; border: 1px solid white; border-radius: 0 0 12px 12px; } } /*测评卡片*/ [data-testid="carousel-content"] .swiper-slide { background: #202024; border-radius: 12px; } h3 { color: white !important; } } /*DLC*/ /*主体*/ [data-testid="egs-ssr-wrapper-all"] > div { background: #101014; } /*添至愿望清单*/ [data-tippy-root] > div { box-shadow: rgba(0, 0, 0, 0.3) 0px 5px 10px; background: #18181c; } /*搜索框*/ [data-testid="browse-filters-header-keywords"] input { border: 1px solid white; &::placeholder { color: rgba(255, 255, 255, 0.65) !important; } } /*筛选器分割线*/ [data-testid="egs-filter-sidebar"] > * { border-bottom: 1px solid white; } /*成就*/ /*主体*/ main > :nth-child(3):has([data-testid="AchievementHero"]) { background: #101014; } /*所有文字*/ main:has([data-testid="AchievementHero"]) * { color: white !important; } /*sticky-nav*/ main:has([data-testid="AchievementHero"]) [data-testid="sticky-nav"] { background: #101014; } /*成就分割线*/ [data-testid="AchievementHero"] + div > ul > li { border-bottom: 1px solid white; } /*成就总进度*/ [data-testid="AchievementHero"] { box-shadow: 0 0 1px 0 white; } /*news*/ html:has(#storeNews) { *:not(img,[data-testid="header"]):not(input,#SearchLayout) { background: #101014 !important; color: white !important; } egs-navigation, main > :nth-child(1) { box-shadow: 0 1px 0 0 white; } #SearchLayout { border: 1px solid white; overflow: hidden; input { color: white; &::placeholder { color: rgba(255, 255, 255, 0.65) !important; } } } } `; if (document.querySelector("main > :nth-child(1)")) { if (isDarkColor(getComputedStyle(document.querySelector("main > :nth-child(1)")).backgroundColor) === false) { // 添加样式 GM_addStyle(css); // 监听整个文档 observer.observe(document.body, { childList: true, subtree: true }); } } /*购买弹窗*/ const buycss = ` #purchase-app { background: black; color: white; .payment-location-bar { background: black; } .payment-methods__content { background: black; } .payment-summaries { background: black; } .payment-offer-summary__author { color: white; } .payment-offer-summary__origin-price { color: white; } .payment-offer-summary__current-price { color: white; } .payment-price__label { color: white; } .payment-price__value { color: white; } .earn-reward { background: #111; color: white; } .payment-developer-privacy { color: white; } .payment-contact-us { color: white; } .payment-check-box { background: #111; border: 1px solid gray; } .payment-purchase-close { background: #444; } .payment-purchase-close path { fill: white; } } `; // 添加样式 GM_addStyle(buycss); })();