小黑盒游戏图片修复

修复网页新版小黑盒Steam游戏图片与视频无法直连加载的问题。

  1. // ==UserScript==
  2. // @name 小黑盒游戏图片修复
  3. // @namespace https://github.com/zXLi1222
  4. // @version 1.4.3
  5. // @description 修复网页新版小黑盒Steam游戏图片与视频无法直连加载的问题。
  6. // @author L
  7. // @icon https://www.xiaoheihe.cn/favicon.ico
  8. // @match *://xiaoheihe.cn/*
  9. // @match *://www.xiaoheihe.cn/*
  10. // @grant GM_registerMenuCommand
  11. // @grant GM_setValue
  12. // @grant GM_getValue
  13. // @license MIT
  14. // ==/UserScript==
  15.  
  16. (function() {
  17. 'use strict';
  18.  
  19. // GM_registerMenuCommand设置选项
  20. GM_registerMenuCommand("设置", () => {
  21. showSettingsModal();
  22. });
  23.  
  24. // 获取用户设置
  25. let replaceEnabled = GM_getValue("replaceEnabled", true);
  26.  
  27. // 图片修复功能
  28. function replaceMediaDomains() {
  29. if (replaceEnabled) {
  30. const images = document.querySelectorAll("img");
  31. images.forEach(img => {
  32. if (img.src.includes("shared.akamai.steamstatic.com")) {
  33. img.src = img.src.replace("shared.akamai.steamstatic.com", "shared.cdn.steamchina.eccdnx.com");
  34. }
  35. if (img.src.includes("cdn.akamai.steamstatic.com")) {
  36. img.src = img.src.replace("cdn.akamai.steamstatic.com", "cdn.steamchina.eccdnx.com");
  37. }
  38. });
  39.  
  40. const videos = document.querySelectorAll("video");
  41. videos.forEach(video => {
  42. if (video.src.includes("video.akamai.steamstatic.com")) {
  43. video.src = video.src.replace("video.akamai.steamstatic.com", "video.cdn.steamchina.eccdnx.com");
  44. }
  45. });
  46. }
  47. }
  48.  
  49. replaceMediaDomains();
  50.  
  51. const observer = new MutationObserver(() => {
  52. replaceMediaDomains();
  53. });
  54. observer.observe(document.body, { childList: true, subtree: true });
  55.  
  56. document.body.addEventListener("load", () => {
  57. replaceMediaDomains();
  58. }, true);
  59.  
  60. // 弹出设置
  61. function showSettingsModal() {
  62. // 创建遮罩层
  63. const overlay = document.createElement("div");
  64. overlay.style.cssText = "position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.5); z-index: 9998; opacity: 0; transition: opacity 0.3s;";
  65. document.body.appendChild(overlay);
  66.  
  67. // 创建弹窗
  68. const modal = document.createElement("div");
  69. modal.style.cssText = "position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%) scale(0.8); background: #1e1e1e; color: #c7c7c7; padding: 20px; border-radius: 8px; width: 400px; z-index: 9999; box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3); opacity: 0; transition: opacity 0.3s, transform 0.3s;";
  70. modal.innerHTML = `
  71. <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
  72. <h2 style="margin: 0; font-size: 18px;">BetterHeybox 设置</h2>
  73. <button id="closeModal" style="background: none; border: none; color: #c7c7c7; font-size: 18px; cursor: pointer;">✖</button>
  74. </div>
  75.  
  76. <div style="margin-bottom: 15px;">
  77. <label style="display: flex; align-items: center; gap: 10px; position: relative;">
  78. <input type="checkbox" id="replaceToggle" ${replaceEnabled ? 'checked' : ''} style="width: 18px; height: 18px;">
  79. <span>Steam游戏图片视频修复</span>
  80. <span style="width: 18px; height: 18px; background: #555; color: #fff; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 14px; cursor: pointer;" title="启用后将自动替换 Steam 资源域名为 白山云SteamChina 域名,以修复Steam游戏图片、视频、图标无法正常加载的问题。">?</span>
  81. </label>
  82. </div>
  83.  
  84. <div style="text-align: center; margin-top: 20px;">
  85. <button id="saveSettings" style="background-color: #007acc; color: #fff; border: none; padding: 10px 20px; font-size: 16px; border-radius: 4px; cursor: pointer;">保存设置</button>
  86. </div>
  87. `;
  88. document.body.appendChild(modal);
  89.  
  90. setTimeout(() => {
  91. overlay.style.opacity = "1";
  92. modal.style.opacity = "1";
  93. modal.style.transform = "translate(-50%, -50%) scale(1)";
  94. }, 0);
  95.  
  96. document.getElementById("closeModal").addEventListener("click", () => closeModal(overlay, modal));
  97.  
  98. // 保存设置
  99. document.getElementById("saveSettings").addEventListener("click", () => {
  100. const replaceToggle = document.getElementById("replaceToggle").checked;
  101. GM_setValue("replaceEnabled", replaceToggle);
  102. alert("设置已保存!刷新页面以应用更改。");
  103. closeModal(overlay, modal);
  104. });
  105.  
  106. overlay.addEventListener("click", () => closeModal(overlay, modal));
  107. }
  108.  
  109. function closeModal(overlay, modal) {
  110. overlay.style.opacity = "0";
  111. modal.style.opacity = "0";
  112. modal.style.transform = "translate(-50%, -50%) scale(0.8)";
  113. setTimeout(() => {
  114. document.body.removeChild(overlay);
  115. document.body.removeChild(modal);
  116. }, 300);
  117. }
  118. })();

QingJ © 2025

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