Steam Error Widget Helper

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

当前为 2018-03-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. // @include http://store.steampowered.com/*
  8. // @include https://store.steampowered.com/*
  9. // @run-at document-end
  10. // @version 1.0
  11. // @language English
  12. // ==/UserScript==
  13.  
  14.  
  15. var getJSON = function(url, callback) {
  16. var xhr = new XMLHttpRequest();
  17. xhr.open('GET', url, true);
  18. xhr.responseType = 'json';
  19. xhr.onload = function() {
  20. var status = xhr.status;
  21. if (status === 200) {
  22. callback(null, xhr.response);
  23. } else {
  24. callback(status, xhr.response);
  25. }
  26. };
  27. xhr.send();
  28. };
  29.  
  30. //rate limiting
  31. var getJSONRL = function(url, callback) {
  32. var Rate=1500; //ms between requests;
  33. var lastCall=localStorage.getItem ('ITCFTRateLimiter');
  34. if (lastCall!==null) {
  35. if ((parseInt(lastCall) + Rate) > Date.now()) {
  36. window.setTimeout(function(){
  37. getJSONRL(url,callback);
  38. },parseInt(lastCall)+Rate-Date.now());
  39. } else { //already time
  40. getJSON(url,callback);
  41. localStorage.setItem('ITCFTRateLimiter',Date.now());
  42. }
  43. } else { //first call ever
  44. getJSON(url,callback);
  45. localStorage.setItem('ITCFTRateLimiter',Date.now());
  46. }
  47. };
  48.  
  49. +function(){
  50.  
  51. //forum widgets
  52. var wcontainer=document.getElementById ('widget');
  53. if (wcontainer!==null) {
  54. var appimagecontainers=wcontainer.getElementsByClassName('capsule');
  55. if (appimagecontainers.length===0) {
  56. var appid=window.location.href.match(/(http.{0,1}:\/\/store\.steampowered\.com\/)(.*)\/(\d+)(.*)/)[3];
  57. getJSONRL('http://store.steampowered.com/api/appdetails?appids='+appid, function(err, data) {
  58. if (err !== null) {
  59. console.log('Something went wrong: ' + err);
  60. } else {
  61. var gamename=null;
  62. if (typeof(data[appid].data.name)!=='undefined') {
  63. gamename=data[appid].data.name;
  64. }
  65. NewElement=document.createElement("div");
  66. NewElement.setAttribute("class","desc");
  67. NameElement=NewElement.appendChild(document.createElement("p"));
  68. NameElement.setAttribute("style","font-size: 20px !important; line-height: 28px !important");
  69. SteamUrlElement=NameElement.appendChild(document.createElement("a"));
  70. SteamUrlElement.setAttribute("style", "color: #898a8c !important;");
  71. SteamUrlElement.setAttribute("href","https://store.steampowered.com/app/"+appid);
  72. SteamUrlElement.setAttribute("target","_blank");
  73. if (gamename===null) {
  74. SteamUrlElement.appendChild(document.createTextNode("https://store.steampowered.com/app/"+appid));
  75. } else {
  76. SteamUrlElement.appendChild(document.createTextNode(gamename));
  77. }
  78. UrlElement=NewElement.appendChild(document.createElement("a"));
  79. UrlElement.setAttribute("href","https://steamdb.info/app/"+appid);
  80. UrlElement.setAttribute("style","color: #898a8c !important; text-decoration: underline !important; line-height: 20px !important");
  81. UrlElement.setAttribute("target","_blank");
  82. UrlElement.appendChild(document.createTextNode("View on Steam Database ("+appid+")"));
  83. showplace=wcontainer.appendChild(NewElement);
  84. }
  85. });
  86. }
  87. }
  88. }();