Steam Link App Opener

Opens Steam Links in the Steam Application

目前為 2021-11-29 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Steam Link App Opener
// @namespace    https://github.com/jaxellis
// @version      1.0.0
// @description  Opens Steam Links in the Steam Application
// @author       Jaxellis
// @icon         https://store.steampowered.com/favicon.ico
// @homepage     https://github.com/jaxellis/Steam-Link-App-Opener
// @supportURL   https://github.com/jaxellis/Steam-Link-App-Opener/issues/
// @include      http://*
// @include      https://*
// @grant        none
// @license      GPL-3.0-or-later; https://www.gnu.org/licenses/gpl-3.0.txt
// ==/UserScript==

class LinkCollector {
	constructor(domains) {
		this.regex = this.#createRegex(domains);
	}

	getLinks() {
		return [...document.querySelectorAll('a[href]')].filter(
			this.#isDomain,
			this
		);
	}

	#createRegex(domains) {
		let filterRegex = '';
		for (let domain of domains) {
			filterRegex += `${domain.replaceAll('.', '\\.')}\/.\\w*|`;
		}
		return new RegExp(filterRegex.replace(/\|([^\|]*)$/, '$1'));
	}

	#isDomain(link) {
		return link.href.match(this.regex);
	}
}

function main() {
	const pageLinks = new LinkCollector([
		'store.steampowered.com',
		'steamcommunity.com',
	]).getLinks();
	for (let link of pageLinks) {
		link.href = `steam://openurl/${link.href}`;
	}
}

main();

QingJ © 2025

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