Steam Search - Click Through To Game

If the URL contains the clickthrough=1 GET variable, then if there is an exact match for the search, click through to it to open the game's page. This is for use with search add-ons and search engine keyword functionality. 5/18/2023, 3:25:43 AM

当前为 2023-05-18 提交的版本,查看 最新版本

// ==UserScript==
// @name        Steam Search - Click Through To Game
// @namespace   Violentmonkey Scripts
// @match       https://store.steampowered.com/search/
// @grant       none
// @version     1.0
// @author      -
// @description If the URL contains the clickthrough=1 GET variable, then if there is an exact match for the search, click through to it to open the game's page. This is for use with search add-ons and search engine keyword functionality. 5/18/2023, 3:25:43 AM
// ==/UserScript==

const urlParams = new URLSearchParams(window.location.search);
title = urlParams.get("term");


if ((urlParams.get("clickthrough") === "1") && (title !== null) && (title !== '')) {
  // the parameter is set, let's find the link

  // escape double quotes in title
  title2 = title.replaceAll(/"/g, '\\"');

  xpath = '//a[contains(@class, "search_result_row") and descendant::span[contains(@class, "title") and text()="'+ title2 +'"]]';
  result = document.evaluate(xpath, document, null, XPathResult.ANY_TYPE, null);
  a = result.iterateNext();

  // check that we have found exactly one such link. if there's more, don't do anything, let the person click through manually.
  if (a !== null && result.iterateNext() === null) {
    window.location.assign(a.href)
  }
}