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

  1. // ==UserScript==
  2. // @name Steam Search - Click Through To Game
  3. // @namespace Violentmonkey Scripts
  4. // @match https://store.steampowered.com/search/
  5. // @grant none
  6. // @version 2.0
  7. // @author -
  8. // @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
  9. // ==/UserScript==
  10.  
  11. const urlParams = new URLSearchParams(window.location.search);
  12. title = urlParams.get("term");
  13.  
  14.  
  15. if ((urlParams.get("clickthrough") === "1") && (title !== null) && (title !== '')) {
  16. // the parameter is set, let's find the link
  17.  
  18. titleLower = title.toLowerCase();
  19.  
  20. a = null;
  21. count = 0;
  22. document.querySelectorAll('a.search_result_row span.title').forEach(span => {
  23. if(span.innerText.toLowerCase() == titleLower) {
  24. if (count == 0) {
  25. a = span.closest('a.search_result_row');
  26. }
  27. count = count + 1;
  28. }
  29. })
  30.  
  31. // first, navigate to the current search results, but without the clickthrough GET var.
  32. // navigate replacing history so that if you navigate back to the search results, you can stay here
  33. urlParams.delete("clickthrough");
  34. noClickthroughUrl = window.location.origin + window.location.pathname + "?" + urlParams.toString()
  35. history.replaceState({}, "", noClickthroughUrl);
  36.  
  37. // if we found more than one match, or no matches, don't click any links
  38. if((count == 1) && (a !== null)) {
  39. // wait for window.location to have changed...
  40. ref = setInterval(function() {
  41. if(window.location.toString() == noClickthroughUrl) {
  42. clearInterval(ref);
  43. window.location.href = a.href;
  44. }
  45. }, 25);
  46. }
  47. }