Open In Steam

Adds a link to open Steam content in the desktop client.

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Open In Steam
// @namespace    http://brooksaar.com/
// @version      0.2
// @description  Adds a link to open Steam content in the desktop client.
// @author       Aaron Brooks
// @match        *://steamcommunity.com/*
// @match        *://store.steampowered.com/*
// @grant        none
// ==/UserScript==

function CreateButton(namedPage, pageId) {
    var steamButton = document.createElement("a");
    var buttonText = document.createTextNode("Open in Steam!");
    steamButton.setAttribute("href", "steam://url/" + namedPage + pageId);
    steamButton.setAttribute("class", "menuitem");
    steamButton.appendChild(buttonText);

    var superNav = document.getElementsByClassName("supernav_container")[0];
    superNav.appendChild(steamButton);
}

// Thanks David Morales, https://stackoverflow.com/questions/11582512/how-to-get-url-parameters-with-javascript/11582513#11582513
function getURLParameter(name) {
    return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null;
}

var namedPage = ""; // trailing slash important!
var pageId = "";

var currentUrl = window.location.href;
if(currentUrl.match("store.steampowered.com/app/")) {
    var urlParts = currentUrl.split("/");

    namedPage = "StoreAppPage/";
    pageId = urlParts[4];

    CreateButton(namedPage, pageId);
} else if(currentUrl.match("steamcommunity.com/sharedfiles/")) {
    pageId = getURLParameter("id");
    namedPage = "CommunityFilePage/";

    CreateButton(namedPage, pageId);
}