From 7ac7280a7a487b201183ae52cfa42231f5ea40c0 Mon Sep 17 00:00:00 2001 From: nite Date: Thu, 11 Jun 2026 01:29:57 +1000 Subject: [PATCH] init --- 423down-vip.js | 105 +++++++++++++++++++++++++++++++++++++++++++++ steam-game.js | 113 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 218 insertions(+) create mode 100644 423down-vip.js create mode 100644 steam-game.js diff --git a/423down-vip.js b/423down-vip.js new file mode 100644 index 0000000..e740b17 --- /dev/null +++ b/423down-vip.js @@ -0,0 +1,105 @@ +// ==UserScript== +// @name 423down VIP 资源获取 +// @namespace https://www.nite07.com/ +// @author Nite +// @homepageURL https://www.nite07.com/ +// @match https://www.423down.com/*.html +// @connect 423.nite07.com +// @connect *.nite07.com +// @grant GM_xmlhttpRequest +// @run-at document-end +// @license MIT +// ==/UserScript== + +(function () { + "use strict"; + + const API_ORIGIN = "https://423.nite07.com"; + const ARTICLE_PATH_RE = /^\/(\d+)\.html$/; + + const articleID = getArticleID(window.location.pathname); + if (!articleID) { + return; + } + + replaceArticleHTML(articleID); + + function getArticleID(pathname) { + const match = pathname.match(ARTICLE_PATH_RE); + return match ? match[1] : ""; + } + + function replaceArticleHTML(articleID) { + requestArticleHTML(articleID) + .then((html) => { + const articleContainer = document.querySelector( + "div.content > div:first-child", + ); + if (!articleContainer) { + console.warn("[423down-proxy] 未找到正文容器,无法替换 HTML"); + return; + } + + let newDiv = articleContainer.cloneNode(false); + let parentElem = articleContainer.parentElement; + articleContainer.remove(); + + newDiv.className = "entry"; + newDiv.style = ""; + newDiv.innerHTML = html; + parentElem.prepend(newDiv); + console.info(`[423down-proxy] 已替换文章 ${articleID} 的正文 HTML`); + }) + .catch((error) => { + console.error("[423down-proxy] 获取文章 HTML 失败:", error); + }); + } + + function requestArticleHTML(articleID) { + const url = `${API_ORIGIN}/?article_id=${encodeURIComponent(articleID)}`; + + return new Promise((resolve, reject) => { + GM_xmlhttpRequest({ + method: "GET", + url, + responseType: "json", + timeout: 30_000, + onload(response) { + if (response.status < 200 || response.status >= 300) { + reject(new Error(`HTTP ${response.status}`)); + return; + } + + const data = parseResponse(response); + if (!data || data.ok !== true || typeof data.html !== "string") { + reject( + new Error(data && data.error ? data.error : "接口响应格式不正确"), + ); + return; + } + + resolve(data.html); + }, + onerror() { + reject(new Error("网络请求失败")); + }, + ontimeout() { + reject(new Error("网络请求超时")); + }, + }); + }); + } + + function parseResponse(response) { + if (response.response && typeof response.response === "object") { + return response.response; + } + + try { + return JSON.parse(response.responseText); + } catch (error) { + console.error("[423down-proxy] JSON 解析失败:", error); + return null; + } + } +})(); diff --git a/steam-game.js b/steam-game.js new file mode 100644 index 0000000..708b002 --- /dev/null +++ b/steam-game.js @@ -0,0 +1,113 @@ +// ==UserScript== +// @name Nite's Game | 免费获取 Steam 游戏资源 +// @namespace https://game.nite07.com +// @version 1.0.0 +// @description 在 Steam 商店页面添加免费获取游戏资源的跳转链接 +// @author Nite +// @match https://store.steampowered.com/app/* +// @grant GM_xmlhttpRequest +// @connect game.nite07.com +// @homepage https://game.nite07.com +// @license MIT +// ==/UserScript== + +(function () { + "use strict"; + + // 从 URL 中提取游戏 ID + const getGameId = () => { + const match = window.location.pathname.match(/\/app\/(\d+)/); + return match ? match[1] : null; + }; + + // 使用 Get 请求检查游戏页面是否存在 + const checkGamePage = (gameId) => { + return new Promise((resolve) => { + GM_xmlhttpRequest({ + method: "GET", + url: `https://game.nite07.com/game/steam/${gameId}`, + onload: (response) => { + resolve(response.status === 200); + }, + onerror: () => { + resolve(false); + }, + ontimeout: () => { + resolve(false); + }, + timeout: 5000, + }); + }); + }; + + // 添加按钮到页面 + const addButton = (gameId) => { + const purchaseArea = document.querySelector("#game_area_purchase"); + if (!purchaseArea) { + console.log("未找到购买区域"); + return; + } + + // 获取游戏名称 + const gameName = + document.querySelector(".apphub_AppName")?.textContent || "game"; + + // 创建按钮容器,完全模仿 Steam 官方样式 + const buttonContainer = document.createElement("div"); + buttonContainer.className = "game_area_purchase_game"; + buttonContainer.setAttribute("role", "region"); + buttonContainer.setAttribute( + "aria-labelledby", + `game_area_purchase_section_external_${gameId}`, + ); + + buttonContainer.innerHTML = ` +
+

+ Play ${gameName} +

+
+
+
+ Free to play +
+ +
+
+ `; + + // 插入到购买区域的第一个子元素之前 + purchaseArea.insertBefore(buttonContainer, purchaseArea.firstChild); + }; + + // 主函数 + const init = async () => { + const gameId = getGameId(); + if (!gameId) { + return; + } + + console.log(`[Steam 外部链接] 检测到游戏 ID: ${gameId}`); + + const exists = await checkGamePage(gameId); + if (exists) { + console.log(`[Steam 外部链接] 页面存在,添加按钮`); + addButton(gameId); + } else { + console.log(`[Steam 外部链接] 页面不存在,跳过`); + } + }; + + // 等待页面加载完成后执行 + if (document.readyState === "loading") { + document.addEventListener("DOMContentLoaded", init); + } else { + init(); + } +})();