Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

This is a script that quickly redirects to corresponding Steam games on the HumbleBundle website.

---
## 安装
[点击安装 addSteamLink.user.js](https://github.com/mookechee/HB-RapidSteamSearchJS/raw/main/addSteamLink.user.js)

需要先安装 Tampermonkey、Violentmonkey 或其他兼容的 userscript 管理器。

---
## 使用后效果
点击标题处的超链接即可跳转steam搜索界面
Expand Down
28 changes: 11 additions & 17 deletions addSteamLink.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,21 @@
// @license MIT
// @homepage https://github.com/mookechee/HB-RapidSteamSearchJS
// @supportURL https://github.com/mookechee/HB-RapidSteamSearchJS/issues
// @updateURL https://github.com/mookechee/HB-RapidSteamSearchJS/raw/main/addSteamLink.js
// @downloadURL https://github.com/mookechee/HB-RapidSteamSearchJS/raw/main/addSteamLink.js
// @updateURL https://github.com/mookechee/HB-RapidSteamSearchJS/raw/main/addSteamLink.user.js
// @downloadURL https://github.com/mookechee/HB-RapidSteamSearchJS/raw/main/addSteamLink.user.js
// @run-at document-end
// ==/UserScript==

(function() {
const CONFIG = {
initialDelay: 500, // 初始等待500ms
retryInterval: 300, // 每300ms检查一次
maxRetries: 5 // 最多重试5次
initialDelay: 500 // 初始等待500ms
};

let retryCount = 0;
const selector = 'h1[data-entity-kind="product"][data-anchor-name="#human_name"].human_name-view';

function initialize() {
const selector = 'h1[data-entity-kind="product"][data-anchor-name="#human_name"].human_name-view';
const elements = document.querySelectorAll(selector);

if (elements.length > 0) {
processElements(elements);
startMutationObserver();
} else if (retryCount < CONFIG.maxRetries) {
retryCount++;
setTimeout(initialize, CONFIG.retryInterval);
}
processElements(document.querySelectorAll(selector));
startMutationObserver();
}

function processElements(elements) {
Expand All @@ -58,9 +48,13 @@
const observer = new MutationObserver(mutations => {
mutations.forEach(mutation => {
mutation.addedNodes.forEach(node => {
if (node.nodeType === 1 && node.matches('h1[data-entity-kind="product"]')) {
if (node.nodeType !== Node.ELEMENT_NODE) return;

if (node.matches(selector)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Match dynamic product headers before extra attrs are added

The new observer path now requires node.matches(selector) where selector includes both data-anchor-name and .human_name-view, but the observer is only configured for childList mutations. If Humble inserts a product <h1 data-entity-kind="product"> first and applies those extra attributes/classes afterward (attribute mutation, no new node), this code never calls processElements, so the Steam link is not attached on dynamically rendered pages. The previous implementation handled this case by matching any h1[data-entity-kind="product"] at insertion time.

Useful? React with 👍 / 👎.

processElements([node]);
}

processElements(node.querySelectorAll(selector));
});
});
});
Expand Down