Greasy Fork镜像 支持简体中文。

steamgifts rating and platforms

Show rating and supported platforms on sitesteamgifts.com according information from store.steampowered.com

  1. // ==UserScript==
  2. // @name steamgifts rating and platforms
  3. // @namespace Gidden
  4. // @version 2.2
  5. // @description Show rating and supported platforms on sitesteamgifts.com according information from store.steampowered.com
  6. // @require http://code.jquery.com/jquery.min.js
  7. // @author Gidden
  8. // @match http://www.steamgifts.com/
  9. // @match http://www.steamgifts.com/giveaways/search?*
  10. // @match https://www.steamgifts.com/
  11. // @match https://www.steamgifts.com/giveaways/search?*
  12. // @grant GM_xmlhttpRequest
  13. // ==/UserScript==
  14.  
  15. // Storage existence test
  16. function supports_html5_storage() {
  17. try {
  18. return 'localStorage' in window && window.localStorage !== null;
  19. } catch (e) {
  20. return false;
  21. }
  22. }
  23.  
  24. // Get color according percentage (0% = Red, 100% = Green)
  25. function getColor(value){
  26. //value from 0 to 1
  27. var hue=((value)*120).toString(10);
  28. return ["hsl(",hue,",100%,42%)"].join("");
  29. }
  30.  
  31. var platforms = ["win", "mac", "linux", "steamplay"];
  32.  
  33. // Get actual configuration from storage
  34. function getFilterCfg(myItem)
  35. {
  36. if (myItem == "percentage") {
  37. myValue = 0;
  38. } else {
  39. myValue = 1;
  40. }
  41. if (supports_html5_storage()) {
  42. if (localStorage.getItem(myItem) !== null) {
  43. myValue = localStorage.getItem(myItem);
  44. }
  45. }
  46. return myValue;
  47. }
  48.  
  49. // Store information about game
  50. function saveGameData(url, data) {
  51. if (supports_html5_storage()) {
  52. localStorage.setItem(url, JSON.stringify(data));
  53. }
  54. }
  55.  
  56. // Get stored information about game
  57. function loadGameData(url) {
  58. var myValue = null;
  59. if (supports_html5_storage()) {
  60. myValue = localStorage.getItem(url);
  61. if (myValue) {
  62. myValue = JSON.parse(myValue);
  63. }
  64. }
  65. return myValue;
  66. }
  67.  
  68. // Filtering functions
  69. var filterFunction = "" +
  70. "var platforms = [\"win\", \"mac\", \"linux\", \"steamplay\"];" +
  71. "function supports_html5_storage() {" +
  72. " try {" +
  73. " return 'localStorage' in window && window.localStorage !== null;" +
  74. " } catch (e) {" +
  75. " return false;" +
  76. " }" +
  77. "}" +
  78. "function saveFilterCfg()" +
  79. "{" +
  80. " if (supports_html5_storage()) {" +
  81. " for (var x in platforms){" +
  82. " platform = platforms[x];" +
  83. " if (document.getElementById(\"filter_\" + platform).checked) {" +
  84. " localStorage.setItem(platform, 1);" +
  85. " } else {" +
  86. " localStorage.setItem(platform, 0);" +
  87. " }" +
  88. " }" +
  89. " if (document.getElementById(\"filter_level\").checked) {" +
  90. " localStorage.setItem(\"level\", 1);" +
  91. " } else {" +
  92. " localStorage.setItem(\"level\", 0);" +
  93. " }" +
  94. " localStorage.setItem(\"percentage\", document.getElementById(\"filter_percentage\").value);" +
  95. " }" +
  96. "}" +
  97. "function changeFilter(){" +
  98. "" +
  99. " platformCheck = [];" +
  100. " for (var x in platforms){" +
  101. " platform = platforms[x];" +
  102. " if (document.getElementById(\"filter_\" + platform).checked) {" +
  103. " platformCheck.push(platform);" +
  104. " }" +
  105. " }" +
  106. " percCheck = document.getElementById(\"filter_percentage\").value;" +
  107. "" +
  108. " var headers = $(\"div.giveaway__summary h2.giveaway__heading\");" +
  109. "" +
  110. " headers.each(function() {" +
  111. " var header = $(this);" +
  112. " var showEl = true;" +
  113. "" +
  114. " if (document.getElementById(\"filter_level\").checked){" +
  115. " if (header.parent().find(\"div.giveaway__column--contributor-level--negative\").length) {" +
  116. " header.parent().parent().parent().hide();" +
  117. " return;" +
  118. " }" +
  119. " }" +
  120. "" +
  121. " percE = header.find(\"span.percentage\");" +
  122. "" +
  123. " if (percE.length)" +
  124. " {" +
  125. " var perc2 = percE[0].getAttribute(\"perc\");" +
  126. " if (perc2 < percCheck){" +
  127. " showEl = false;" +
  128. " } else {" +
  129. " showEl = false;" +
  130. " for (var x in platformCheck){" +
  131. " actPlatformCheck = platformCheck[x];" +
  132. " if (header.find(\"span.\"+actPlatformCheck).length) {" +
  133. " showEl = true;" +
  134. " }" +
  135. " }" +
  136. " }" +
  137. " }" +
  138. "" +
  139. " if (showEl) {" +
  140. " header.parent().parent().parent().show();" +
  141. " } else {" +
  142. " header.parent().parent().parent().hide();" +
  143. " }" +
  144. " });" +
  145. " saveFilterCfg();" +
  146. "}";
  147.  
  148. function renderPluginGame(header, gameData) {
  149.  
  150. if ((header === null) || (gameData === null) || ("error" in gameData)){
  151. return;
  152. }
  153.  
  154. // Remove old informations
  155. header.find("a.giveaway__icon span").remove();
  156. header.find("h2.giveaway__heading span").remove();
  157.  
  158. var a_tag = header.find( "a.giveaway__icon" );
  159. var i_tag = header.find( "i.giveaway__icon" );
  160. if (! i_tag.length) {
  161. i_tag = a_tag;
  162. }
  163. a_tag.attr("style", "opacity:1");
  164. a_tag.find("i.fa-steam").attr("style", "opacity:.35");
  165.  
  166. // Render perc + ppl
  167. if ("perc" in gameData) {
  168. var rating = gameData.perc + '% (' + gameData.ppl + ') ';
  169. a_tag.append(" <span style=\"color:" + getColor(gameData.perc /100.0) + "\" class=\"percentage\" perc=\"" + gameData.perc + "\">" + rating + "</span>");
  170. }
  171.  
  172. // Render platforms
  173. if ("platforms" in gameData)
  174. {
  175. //a_tag.append(" <span>" + platform.html() + "</span>");
  176. }
  177. var platformsHtml = "<span>";
  178. for (var platf in gameData.platforms) {
  179. platformsHtml = platformsHtml + "<span class=\"platform_img " + platf + "\"></span>";
  180. }
  181. a_tag.append(platformsHtml + "</span>");
  182.  
  183. // Render cards
  184. if (("cards" in gameData) && (gameData.cards)) {
  185. i_tag.after("<span class=\"platform_img right_allign\"><img src=\"http://store.akamai.steamstatic.com/public/images/v6/ico/ico_cards.png\"></span>");
  186. }
  187.  
  188. if ((gameData.perc < getFilterCfg("percentage"))) {
  189. header.parent().parent().parent().hide();
  190. }
  191.  
  192. hide = true;
  193. for (var x in platforms) {
  194. platformCheck = platforms[x];
  195. if ((gameData.platforms[platformCheck] || false) && (getFilterCfg(platformCheck) == 1)) {
  196. hide = false;
  197. }
  198. }
  199. if (hide) {
  200. header.parent().parent().parent().hide();
  201. }
  202. }
  203.  
  204. function exportDataFromPage(steamURL, responseText, callFunction) {
  205. var gameData = {};
  206. gameData.ppl = false;
  207. gameData.perc = false;
  208. gameData.platforms = {};
  209. gameData.cards = false;
  210. gameData.fetchTime = new Date().getTime();
  211.  
  212. var ratingFull = responseText.find("div.glance_ctn div[itemprop=aggregateRating]");
  213.  
  214. if (!ratingFull.length) {
  215. gameData.error = true;
  216. saveGameData(steamURL, gameData);
  217. } else {
  218. ratingFull = ratingFull.attr("data-store-tooltip");
  219.  
  220. // extract percentare review (perc) and peoples reviewed (ppl) variables.
  221. if (ratingFull.length > 0) {
  222. var ratingFullString = ratingFull.trim();
  223. var perc = ratingFullString.match("[0-9]+ ?%");
  224. if (perc === null) {
  225. perc = ratingFullString.match("% ?[0-9]+");
  226. }
  227. gameData.perc = perc[0].replace("%", "").replace(" ", "");
  228. ppl = ratingFullString.match(/[0-9,]+/g);
  229. if (ppl[0] == gameData.perc) {
  230. ppl = ppl[1];
  231. } else {
  232. ppl = ppl[0];
  233. }
  234. gameData.ppl = ppl.replace(",", ".");
  235. }
  236.  
  237. // extract platforms
  238. var platform = responseText.find("div.game_area_purchase_platform");
  239. if (platform.length) {
  240. for (var x in platforms){
  241. var actPlatformCheck = platforms[x];
  242. if (platform.find("span."+actPlatformCheck).length) {
  243. gameData.platforms[actPlatformCheck] = true;
  244. }
  245. }
  246. }
  247.  
  248. // extract support of gaming cards
  249. var cards;
  250. if (platform.length) {
  251. cards = responseText.find("a[href*='http://store.steampowered.com/search/?category2=29']");
  252. gameData.cards = cards.length > 0;
  253. }
  254.  
  255.  
  256. // Save
  257. saveGameData(steamURL, gameData);
  258.  
  259. //renderPluginGame(header, gameData);
  260. if (callFunction !== null) {
  261. callFunction(steamURL, gameData);
  262. }
  263. }
  264. return gameData;
  265. }
  266.  
  267. function fetchSteamDate(steamURL, callFunction) {
  268. var gameData = {};
  269.  
  270. GM_xmlhttpRequest({
  271. method: "GET",
  272. url: steamURL,
  273. context: steamURL,
  274. // synchronous: true,
  275. onload: function(response) {
  276. var responseText = $(response.responseText);
  277. var ageCheck = responseText.find("div#agegate_box");
  278. if (ageCheck.length) {
  279. GM_xmlhttpRequest({
  280. method: "POST",
  281. data: "snr=1_agecheck_agecheck__age-gate&ageDay=1&ageMonth=January&ageYear=1980",
  282. headers: {
  283. "Content-Type": "application/x-www-form-urlencoded"
  284. },
  285. url: steamURL.replace("/app/","/agecheck/app/"),
  286. context: steamURL,
  287. onload: function(response) {
  288. var responseText = $(response.responseText);
  289. exportDataFromPage(steamURL, responseText, callFunction);
  290. }
  291. });
  292. } else {
  293. exportDataFromPage(steamURL, responseText, callFunction);
  294. }
  295. }
  296. });
  297.  
  298. return gameData;
  299. }
  300.  
  301. // Generate html string for checkboxes
  302. var checkboxes = "";
  303. for (var x in platforms){
  304. platform = platforms[x];
  305. var checked = "";
  306. if (getFilterCfg(platform) == 1) {
  307. checked = "checked";
  308. }
  309. checkboxes += "<input class=\"filter_checkboxes\" type=\"checkbox\" name=\"filter_" + platform + "\" id=\"filter_" + platform + "\" onclick=\"changeFilter();\" " + checked + "><label class=\"checkboxes\" for=\"filter_" + platform + "\"><span class=\"platform_img " + platform + "\"></span></label>";
  310. }
  311.  
  312. // New headers. Mainly css styles
  313. $("head link:last")
  314. .before("<link rel=stylesheet type=text/css href=https://steamstore-a.akamaihd.net/public/css/v6/store.css>")
  315. .after("<style>span.platform_img {background-color: black; height:20px; display: inline-block; opacity: 0.35;} input.filter_checkboxes {height:15px; width:20px;} input.filter_percentage {height:18px; width:40px; margin:5px; padding:0px 10px;} label.checkboxes {margin-right:5px;}</style>")
  316. .after("<style>span.percentage {font-size: medium; font-weight: bold;} h2.giveaway__heading {position:relative;} span img {width: 20px; height: 16px;} span.right_allign {position:absolute; right: 0; top: 0;}</style>")
  317. .after("<script type=\"text/javascript\">" + filterFunction + "</script>");
  318.  
  319. var checkedLevel = "";
  320. if (getFilterCfg("level") == 1) {
  321. checkedLevel = "checked";
  322. }
  323.  
  324. // Appending left filter panel
  325. filterPanel = "<h3 class=\"sidebar__heading\">Filter</h3><div style=\"margin-left:10px;\">" +
  326. " <span style=\"font-weight: bold;\">Game</span> &gt;= <input type=\"text\" class=\"filter_percentage\" id=\"filter_percentage\" value=\"" + getFilterCfg("percentage") + "\" onchange=\"changeFilter()\" onkeyup=\"changeFilter()\">% <br>" +
  327. checkboxes + "</br>" +
  328. "<input type=\"checkbox\" class=\"filter_checkboxes\" id=\"filter_level\" onclick=\"changeFilter();\" " + checkedLevel + "><label class=\"checkboxes\" for=\"filter_level\"><span style=\"font-weight: bold;\">Hide higher level</span></label>" +
  329. "</div>";
  330.  
  331. $("div.sidebar__search-container").after(filterPanel);
  332.  
  333. // Fetching steam for games information
  334. var needFetch = {};
  335. var headers = $("div.giveaway__summary h2.giveaway__heading");
  336. var actTime = new Date().getTime();
  337. headers.each(function() {
  338. var header = $(this);
  339. var iconElement = header.find("a.giveaway__icon");
  340. if (iconElement.length) {
  341. var steamURL = iconElement.attr("href").trim();
  342.  
  343. if ((getFilterCfg("level") == 1) && (header.parent().find("div.giveaway__column--contributor-level--negative").length)) {
  344. header.parent().parent().parent().hide();
  345. }
  346.  
  347. var gameData = loadGameData(steamURL);
  348.  
  349. if (gameData === null) {
  350. needFetch[steamURL] = true;
  351. } else {
  352. renderPluginGame(header, gameData);
  353.  
  354. // If game info are older than one day then fetch new info.
  355. if ((actTime - gameData.fetchTime) > 24*60*60*1000) {
  356. needFetch[steamURL] = true;
  357. }
  358. }
  359. }
  360. });
  361.  
  362. function afterFetch(steamURL, gameData) {
  363. var headers = $("a[href=\"" + steamURL + "\"]");
  364. headers.each(function() {
  365. var header = $(this).parent();
  366. renderPluginGame(header, gameData);
  367. });
  368. }
  369.  
  370. for(var steamURL in needFetch) {
  371. var gameData = fetchSteamDate(steamURL, afterFetch);
  372. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址