Steam Error Widget Helper

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

当前为 2021-03-02 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Steam Error Widget Helper
  3. // @namespace https://greasyfork.org/users/2205
  4. // @description:ru Для виджетов с ошибкой отображает линк на steamdb.info и если возможно - название игры.
  5. // @description For error widgets shows steamdb.info link and game name (if possible).
  6. // @include http://store.steampowered.com/*
  7. // @include https://store.steampowered.com/*
  8. // @run-at document-end
  9. // @version 1.3
  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 getJSON = 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[1];
  30. }
  31. //console.log(name);
  32. callback(name)
  33. /*
  34. let data = JSON.parse(response.response);
  35. if (!('response' in data)) {
  36. if (data[appid].success == true) {
  37. if (typeof(data[appid].data.name)!=='undefined') {
  38. callback(data[appid].data.name);
  39. return;
  40. }
  41. }
  42. getJSONRL('https://api.steampowered.com/IStoreService/GetAppList/v1/?key=7BAC459A4D25F889FAB7813D49069C7B&max_results=1&last_appid='+(appid-1), callback);
  43. return;
  44. } else {//second request
  45. let data = JSON.parse(response.response);
  46. if (data.response.last_appid == appid) {
  47. callback(data.response.apps[0].name);
  48. return;
  49. }
  50. callback(null);
  51. return;
  52. }*/
  53. } else {
  54. callback(null);
  55. }
  56. },
  57. onerror: function() {
  58. console.log('Error.');
  59. },
  60. ontimeout: function() {
  61. console.log('Error.');
  62. }
  63. });
  64.  
  65. };
  66.  
  67. //rate limiting
  68. var getJSONRL = function(url, callback) {
  69. var Rate=1500; //ms between requests;
  70. var lastCall=localStorage.getItem ('ITCFTRateLimiter');
  71. if (lastCall!==null) {
  72. if ((parseInt(lastCall) + Rate) > Date.now()) {
  73. window.setTimeout(function(){
  74. getJSONRL(url,callback);
  75. },parseInt(lastCall)+Rate-Date.now());
  76. } else { //already time
  77. getJSON(url,callback);
  78. localStorage.setItem('ITCFTRateLimiter',Date.now());
  79. }
  80. } else { //first call ever
  81. getJSON(url,callback);
  82. localStorage.setItem('ITCFTRateLimiter',Date.now());
  83. }
  84. };
  85.  
  86. +function(){
  87.  
  88. //forum widgets
  89. var wcontainer=document.getElementById ('widget');
  90. if (wcontainer!==null) {
  91. var appimagecontainers=wcontainer.getElementsByClassName('capsule');
  92. if (appimagecontainers.length===0) {
  93. appid=window.location.href.match(/(http.{0,1}:\/\/store\.steampowered\.com\/)(.*)\/(\d+)(.*)/)[3];
  94. //getJSONRL('https://api.steampowered.com/IStoreService/GetAppList/v1/?key=7BAC459A4D25F889FAB7813D49069C7B&max_results=1&last_appid='+appid, function(err, data) {
  95. //getJSONRL('/api/appdetails?appids='+appid, function(gamename) {
  96. getJSONRL('https://steamcommunity.com/app/'+appid, function(gamename) {
  97. let ImageElement = document.createElement("img");
  98. //https://steamcdn-a.akamaihd.net/steam/apps/761430/header_292x136.jpg
  99. //https://cdn.akamai.steamstatic.com/steam/apps/761430/capsule_184x69.jpg
  100. //https://cdn.cloudflare.steamstatic.com/steam/apps/1554300/header.jpg
  101. ImageElement.setAttribute("style","margin:5px;float:right");
  102. ImageElement.setAttribute("src","https://cdn.akamai.steamstatic.com/steam/apps/"+appid+"/capsule_184x69.jpg")
  103. wcontainer.appendChild(ImageElement);
  104. let NewElement=document.createElement("div");
  105. NewElement.setAttribute("class","desc");
  106. let NameElement=NewElement.appendChild(document.createElement("p"));
  107. NameElement.setAttribute("style","font-size: 20px !important; line-height: 28px !important");
  108. let SteamUrlElement=NameElement.appendChild(document.createElement("a"));
  109. SteamUrlElement.setAttribute("style", "color: #898a8c !important;");
  110. SteamUrlElement.setAttribute("href","https://store.steampowered.com/app/"+appid);
  111. SteamUrlElement.setAttribute("target","_blank");
  112. if (gamename===null) {
  113. SteamUrlElement.appendChild(document.createTextNode("Unknown app "+appid));
  114. } else {
  115. SteamUrlElement.appendChild(document.createTextNode(gamename));
  116. }
  117. let UrlElement=NewElement.appendChild(document.createElement("a"));
  118. UrlElement.setAttribute("href","https://steamdb.info/app/"+appid);
  119. UrlElement.setAttribute("style","color: #898a8c !important; text-decoration: underline !important; line-height: 20px !important");
  120. UrlElement.setAttribute("target","_blank");
  121. UrlElement.appendChild(document.createTextNode("View on Steam Database ("+appid+")"));
  122. let showplace=wcontainer.appendChild(NewElement);
  123. });
  124. }
  125. }
  126. }();