Steam Error Widget Helper

Для виджетов с ошибкой отображает линк на steamdb.info и если возможно - название игры.

当前为 2020-06-14 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Steam Error Widget Helper
  3. // @name:en Steam Error Widget Helper
  4. // @namespace https://greasyfork.org/users/2205
  5. // @description Для виджетов с ошибкой отображает линк на steamdb.info и если возможно - название игры.
  6. // @description:en For error widgets shows steamdb.info link and game name (if possible).
  7. // @license Apache-2.0
  8. // @author Ryzhehvost
  9. // @include http://store.steampowered.com/*
  10. // @include https://store.steampowered.com/*
  11. // @run-at document-end
  12. // @version 1.2
  13. // @language English
  14. // ==/UserScript==
  15.  
  16.  
  17. var getJSON = function(url, callback) {
  18. var xhr = new XMLHttpRequest();
  19. xhr.open('GET', url, true);
  20. xhr.responseType = 'json';
  21. xhr.onload = function() {
  22. var status = xhr.status;
  23. if (status === 200) {
  24. callback(null, xhr.response);
  25. } else {
  26. callback(status, xhr.response);
  27. }
  28. };
  29. xhr.send();
  30. };
  31.  
  32. //rate limiting
  33. var getJSONRL = function(url, callback) {
  34. var Rate=1500; //ms between requests;
  35. var lastCall=localStorage.getItem ('ITCFTRateLimiter');
  36. if (lastCall!==null) {
  37. if ((parseInt(lastCall) + Rate) > Date.now()) {
  38. window.setTimeout(function(){
  39. getJSONRL(url,callback);
  40. },parseInt(lastCall)+Rate-Date.now());
  41. } else { //already time
  42. getJSON(url,callback);
  43. localStorage.setItem('ITCFTRateLimiter',Date.now());
  44. }
  45. } else { //first call ever
  46. getJSON(url,callback);
  47. localStorage.setItem('ITCFTRateLimiter',Date.now());
  48. }
  49. };
  50.  
  51. +function(){
  52.  
  53. //forum widgets
  54. var wcontainer=document.getElementById ('widget');
  55. if (wcontainer!==null) {
  56. var appimagecontainers=wcontainer.getElementsByClassName('capsule');
  57. if (appimagecontainers.length===0) {
  58. var appid=window.location.href.match(/(http.{0,1}:\/\/store\.steampowered\.com\/)(.*)\/(\d+)(.*)/)[3];
  59. getJSONRL('/api/appdetails?appids='+appid, function(err, data) {
  60. if (err !== null) {
  61. console.log('Something went wrong: ' + err);
  62. } else {
  63. var gamename=null;
  64. if (data[appid].success) {
  65. if (typeof(data[appid].data.name)!=='undefined') {
  66. gamename=data[appid].data.name;
  67. }
  68. }
  69. NewElement=document.createElement("div");
  70. NewElement.setAttribute("class","desc");
  71. NameElement=NewElement.appendChild(document.createElement("p"));
  72. NameElement.setAttribute("style","font-size: 20px !important; line-height: 28px !important");
  73. SteamUrlElement=NameElement.appendChild(document.createElement("a"));
  74. SteamUrlElement.setAttribute("style", "color: #898a8c !important;");
  75. SteamUrlElement.setAttribute("href","https://store.steampowered.com/app/"+appid);
  76. SteamUrlElement.setAttribute("target","_blank");
  77. if (gamename===null) {
  78. SteamUrlElement.appendChild(document.createTextNode("https://store.steampowered.com/app/"+appid));
  79. } else {
  80. SteamUrlElement.appendChild(document.createTextNode(gamename));
  81. }
  82. UrlElement=NewElement.appendChild(document.createElement("a"));
  83. UrlElement.setAttribute("href","https://steamdb.info/app/"+appid);
  84. UrlElement.setAttribute("style","color: #898a8c !important; text-decoration: underline !important; line-height: 20px !important");
  85. UrlElement.setAttribute("target","_blank");
  86. UrlElement.appendChild(document.createTextNode("View on Steam Database ("+appid+")"));
  87. showplace=wcontainer.appendChild(NewElement);
  88. }
  89. });
  90. }
  91. }
  92. }();