Steam Error Widget Helper

For error widgets shows steamdb.info link and game name (if possible).

  1. // ==UserScript==
  2. // @name Steam Error Widget Helper
  3. // @namespace https://greasyfork.org/users/2205
  4. // @description For error widgets shows steamdb.info link and game name (if possible).
  5. // @author Rudokhvist
  6. // @include http://store.steampowered.com/*
  7. // @include https://store.steampowered.com/*
  8. // @run-at document-end
  9. // @version 1.4
  10. // @language English
  11. // @connect api.steampowered.com
  12. // @connect steamcommunity.com
  13. // @grant GM_xmlhttpRequest
  14. // @grant GM.xmlhttpRequest
  15. // ==/UserScript==
  16.  
  17. var appid;
  18.  
  19. var getName = function(url, callback) {
  20. GM_xmlhttpRequest({
  21. method: "GET",
  22. url: url,
  23. onload: function(response) {
  24. //console.log(response);
  25. if (response.status === 200) {
  26. let res = /<title>(.+)\s::\s(.+)<\/title>/.exec(response.response);
  27. let name = null;
  28. if (res != null) {
  29. name = res[2].trim();
  30. if (name === "Steam Community") {
  31. name = res[1].trim()
  32. }
  33. }
  34. callback(name)
  35.  
  36. } else {
  37. callback(null);
  38. }
  39. },
  40. onerror: function() {
  41. console.log('Error.');
  42. },
  43. ontimeout: function() {
  44. console.log('Error.');
  45. }
  46. });
  47.  
  48. };
  49.  
  50. //rate limiting
  51. var getNameRL = function(url, callback) {
  52. var Rate=1500; //ms between requests;
  53. var lastCall=localStorage.getItem ('ITCFTRateLimiter');
  54. if (lastCall!==null) {
  55. if ((parseInt(lastCall) + Rate) > Date.now()) {
  56. window.setTimeout(function(){
  57. getNameRL(url,callback);
  58. },parseInt(lastCall)+Rate-Date.now());
  59. } else { //already time
  60. getName(url,callback);
  61. localStorage.setItem('ITCFTRateLimiter',Date.now());
  62. }
  63. } else { //first call ever
  64. getName(url,callback);
  65. localStorage.setItem('ITCFTRateLimiter',Date.now());
  66. }
  67. };
  68.  
  69. +function(){
  70.  
  71. //forum widgets
  72. var wcontainer=document.getElementById ('widget');
  73. if (wcontainer!==null) {
  74. var appimagecontainers=wcontainer.getElementsByClassName('capsule');
  75. if (appimagecontainers.length===0) {
  76. appid=window.location.href.match(/(http.{0,1}:\/\/store\.steampowered\.com\/)(.*)\/(\d+)(.*)/)[3];
  77. getNameRL('https://steamcommunity.com/app/'+appid, function(gamename) {
  78. let ImageElement = document.createElement("img");
  79. ImageElement.setAttribute("style","margin:5px;float:right");
  80. ImageElement.setAttribute("src","https://cdn.akamai.steamstatic.com/steam/apps/"+appid+"/capsule_184x69.jpg")
  81. wcontainer.appendChild(ImageElement);
  82. let NewElement=document.createElement("div");
  83. NewElement.setAttribute("class","desc");
  84. let NameElement=NewElement.appendChild(document.createElement("p"));
  85. NameElement.setAttribute("style","font-size: 20px !important; line-height: 28px !important");
  86. let SteamUrlElement=NameElement.appendChild(document.createElement("a"));
  87. SteamUrlElement.setAttribute("style", "color: #898a8c !important;");
  88. SteamUrlElement.setAttribute("href","https://store.steampowered.com/app/"+appid);
  89. SteamUrlElement.setAttribute("target","_blank");
  90. if (gamename===null) {
  91. SteamUrlElement.appendChild(document.createTextNode("Unknown app "+appid));
  92. } else {
  93. SteamUrlElement.appendChild(document.createTextNode(gamename));
  94. }
  95. let UrlElement=NewElement.appendChild(document.createElement("a"));
  96. UrlElement.setAttribute("href","https://steamdb.info/app/"+appid);
  97. UrlElement.setAttribute("style","color: #898a8c !important; text-decoration: underline !important; line-height: 20px !important");
  98. UrlElement.setAttribute("target","_blank");
  99. UrlElement.appendChild(document.createTextNode("View on Steam Database ("+appid+")"));
  100. let showplace=wcontainer.appendChild(NewElement);
  101. });
  102. }
  103. }
  104. }();