SWH_Helper

从steamdb.keylol.com获取愿望单数据

  1. // ==UserScript==
  2. // @name SWH_Helper
  3. // @namespace https://blog.chrxw.com
  4. // @version 1.40
  5. // @description 从steamdb.keylol.com获取愿望单数据
  6. // @author Chr_
  7. // @match https://swh.chrxw.com/
  8. // @match http://localhost/
  9. // @match https://steamdb.keylol.com/*
  10. // @connect steamdb.keylol.com
  11. // @connect swh.chrxw.com
  12. // @connect swh.chrxw.cn
  13. // @grant GM_setValue
  14. // @grant GM_getValue
  15. // @grant GM_xmlhttpRequest
  16. // ==/UserScript==
  17.  
  18. (function () {
  19. 'use strict';
  20. var serverdic = {
  21. 'ali': ["阿里云1", "swh.chrxw.cn:20443"],
  22. 'ali2': ["阿里云2", "swh2.chrxw.cn:20443"],
  23. }
  24. var review = ['评测不足', '差评如潮', '特别差评', '差评', '多半差评', '褒贬不一', '多半好评', '好评', '特别好评', '好评如潮', '好评如潮'];
  25. var infodict;
  26. var wishlist;
  27. var wishstr;
  28. var server;
  29. var tmp;
  30.  
  31. if (window.location.host == 'steamdb.keylol.com') {
  32. wishstr = window.localStorage.getItem('wish');
  33. GM_setValue('wish', wishstr);
  34. var nav = document.getElementsByClassName('nav')[0];
  35. var button = document.createElement('li');
  36. button.setAttribute('class', 'nav-swh');
  37. button.setAttribute('class', 'nav-swh');
  38. var link = document.createElement('a');
  39. link.setAttribute('href', 'https://swh.chrxw.com')
  40. link.text = '愿望单助手';
  41. button.appendChild(link);
  42. nav.appendChild(button);
  43. var i = setInterval(() => {
  44. var tips = document.getElementById('own_after').children[0];
  45. if (tips.textContent.indexOf("成功读取") != -1) {
  46. clearInterval(i);
  47. wishstr = window.localStorage.getItem('wish');
  48. GM_setValue('wish', wishstr);
  49. link.text = '同步完毕,点此返回SWH';
  50. }
  51. }, 1000);
  52. } else {
  53. wishstr = GM_getValue('wish');
  54. if (!wishstr) {
  55. wishstr = '[]'
  56. }
  57. wishlist = JSON.parse(wishstr);
  58. infodict = GM_getValue('infodict');
  59. if (!infodict) {
  60. infodict = {};
  61. }
  62. document.getElementById('install').remove();
  63. document.getElementById('noserver').remove();
  64. var sbox = document.getElementById('server');
  65. var opt;
  66. for (var key in serverdic) {
  67. opt = document.createElement('option');
  68. opt.value = key;
  69. opt.text = serverdic[key][0];
  70. sbox.appendChild(opt);
  71. }
  72. var bts = document.getElementById('buttons');
  73. var btn;
  74. btn = document.createElement('button');
  75. btn.type = 'button';
  76. btn.className = 'layui-btn layui-btn-sm layui-btn-normal';
  77. btn.textContent = '查看帮助';
  78. btn.addEventListener('click', showHelp, false);
  79. bts.appendChild(btn);
  80. btn = document.createElement('button');
  81. btn.type = 'button';
  82. btn.className = 'layui-btn layui-btn-sm ';
  83. btn.textContent = '更新愿望单';
  84. btn.addEventListener('click', updateWishlist, false);
  85. bts.appendChild(btn);
  86. btn = document.createElement('button');
  87. btn.type = 'button';
  88. btn.className = 'layui-btn layui-btn-sm layui-btn-danger';
  89. btn.textContent = '生成表格';
  90. btn.addEventListener('click', flashLocalData, false);
  91. bts.appendChild(btn);
  92. if (infodict) {
  93. renderTable();
  94. var k, t = 0;
  95. for (k in infodict) { t++; }
  96. document.getElementById('status').textContent = '已显示' + t.toString() + '条缓存数据'
  97. } else if (wishlist) {
  98. document.getElementById('status').textContent = '检测到愿望单信息,请点【生成表格】开始获取数据'
  99. } else {
  100. document.getElementById('status').textContent = '未检测到愿望单数据,请点【更新愿望单】获取数据'
  101. }
  102. }
  103.  
  104. function showHelp() {
  105. layui.use('layer', function () {
  106. var layer = layui.layer;
  107. layer.open({
  108. title: '帮助'
  109. , content: '使用方法:</br>1.先点【更新愿望单】获取愿望单数据</br>2.然后点【生成表格】,数据会保存在本地,刷新后不会丢失.'
  110. });
  111. });
  112. }
  113.  
  114. function updateWishlist() {
  115. function goToKeylol() {
  116. window.location.href = 'https://steamdb.keylol.com/sync'
  117. }
  118. layui.use('layer', function () {
  119. layer.msg('即将前往Keylol,同步完成后刷新本页即可生效.');
  120. });
  121. setTimeout(goToKeylol, 2000);
  122. }
  123.  
  124. function getSelectServer() {
  125. var choose = document.getElementById('server').value;
  126. for (var key in serverdic) {
  127. if (choose == key) {
  128. server = 'https://' + serverdic[key][1];
  129. }
  130. }
  131. }
  132.  
  133. function flashLocalData() {
  134. getSelectServer();
  135. var process = document.getElementById('process');
  136. var status = document.getElementById('status');
  137. var count = 0;
  138. var total = wishlist.length;
  139. var tmp;
  140.  
  141. tmp = setInterval(
  142. function () {
  143. getFromRemote(wishlist[count]);
  144. }
  145. , 500)
  146.  
  147. while (count >= total) {
  148. clearInterval(tmp);
  149. }
  150.  
  151. function getFromRemote(appid) {
  152. try {
  153. GM_xmlhttpRequest({
  154. method: "GET",
  155. headers: {
  156. "User-Agent": "SWH_Helper 1.0",
  157. "Accept": "application/json"
  158. },
  159. url: server + '/games/' + appid.toString(),
  160. onload: function (response) {
  161. count++;
  162. status.textContent = '进度:' + count.toString() + '/' + total.toString() + ',刷新即可终止操作(已有数据会保留)';
  163. process.style.width = getPercent(count, total)
  164. if (response.status == 200) {
  165. var t = JSON.parse(response.responseText);
  166. t["lowest"] = t["pcurrent"] <= t["plowest"];
  167. infodict[appid] = t;
  168. GM_setValue('infodict', infodict);
  169. renderTable();
  170. } else {
  171. console.log('未查到信息,appid:', appid);
  172. }
  173. if (count >= total) {
  174. console.log('处理完毕');
  175. }
  176. }
  177. });
  178. } catch (e) {
  179. console.log(e);
  180. }
  181. }
  182. }
  183.  
  184. function cardb2s(b) {
  185. return b["card"] ? "√" : ""
  186. }
  187. function limitb2s(b) {
  188. return b["limit"] ? "√" : ""
  189. }
  190. function adultb2s(b) {
  191. return b["adult"] ? "√" : ""
  192. }
  193. function freeb2s(b) {
  194. return b["free"] ? "√" : ""
  195. }
  196. function releaseb2s(b) {
  197. return b["release"] ? "√" : ""
  198. }
  199. function lowestb2s(b) {
  200. return b["lowest"] ? "√" : ""
  201. }
  202. function genLink(b) {
  203. var id = b["appid"].toString()
  204. return '<a style="color: #01AAED;" href=https://store.steampowered.com/app/' + id + '>' + id + '</a>'
  205. }
  206. function genPicLink(b) {
  207. var id = b["appid"].toString()
  208. return '<a style="color: #01AAED;" href=https://store.steampowered.com/app/' + id + '>' + '<img style="height:100%" src="https://steamcdn-a.akamaihd.net/steam/apps/' + id + '/capsule_sm_120.jpg"></a>'
  209. }
  210. function treleaset2s(b) {
  211. if (!b['trelease']) {
  212. return '-'
  213. }
  214. var date = new Date(b['trelease'] * 1000);
  215. return date.getFullYear().toString() + '-' + (date.getMonth() + 1).toString() + '-' + date.getDate().toString()
  216. }
  217. function tlowestt2s(b) {
  218. if (!b['tlowest']) {
  219. return '-'
  220. }
  221. var date = new Date(b['tlowest'] * 1000);
  222. return date.getFullYear().toString() + '-' + (date.getMonth() + 1).toString() + '-' + date.getDate().toString()
  223. }
  224. function tmodifyt2s(b) {
  225. if (!b['tmodify']) {
  226. return '-'
  227. }
  228. var date = new Date(b['tmodify'] * 1000);
  229. return date.getFullYear().toString() + '-' + (date.getMonth() + 1).toString() + '-' + date.getDate().toString()
  230. }
  231. function review2text(b) {
  232. return review[b["rscore"]];
  233. }
  234. function rpercent2p(b) {
  235. return b["rpercent"].toString() + '%';
  236. }
  237. function pcut2p(b) {
  238. return b["pcut"].toString() + '%';
  239. }
  240. function plowestcut2p(b) {
  241. return b["plowestcut"].toString() + '%';
  242. }
  243.  
  244. function renderTable() {
  245. var data = [];
  246. for (var key in infodict) {
  247. data.push(infodict[key]);
  248. }
  249. layui.use('table', function () {
  250. var table = layui.table;
  251. table.render({
  252. elem: '#test'
  253. , cols: [[
  254. { field: 'appid', title: 'APPID', width: 100, sort: true, fixed: 'left', align: "center", templet: genLink }
  255. , { field: 'pic', title: '预览图', width: 110, align: "center", templet: genPicLink }
  256. , { field: 'name_cn', title: '名称', width: 200, sort: true, align: "center" }
  257. , { field: 'card', title: '卡牌', minWidth: 50, sort: true, align: "center", templet: cardb2s }
  258. , { field: 'limit', title: '受限', minWidth: 50, sort: true, align: "center", templet: limitb2s }
  259. , { field: 'adult', title: '软锁', width: 50, sort: true, align: "center", templet: adultb2s }
  260. , { field: 'free', title: '免费', width: 50, sort: true, align: "center", templet: freeb2s }
  261. , { field: 'release', title: '发售', width: 50, sort: true, align: "center", templet: releaseb2s }
  262. , { field: 'lowest', title: '史低', width: 50, sort: true, align: "center", templet: lowestb2s }
  263.  
  264. , { field: 'rscore', title: '评测结果', width: 120, sort: true, align: "center", templet: review2text }
  265. , { field: 'rtotal', title: '总评', width: 80, sort: true, align: "center" }
  266. , { field: 'rpercent', title: '好评', width: 80, sort: true, align: "center", templet: rpercent2p }
  267.  
  268. , { field: 'pcurrent', title: '现价', width: 80, sort: true, align: "center" }
  269. , { field: 'porigin', title: '原价', width: 80, sort: true, align: "center" }
  270. , { field: 'plowest', title: '史低价', width: 100, sort: true, align: "center" }
  271. , { field: 'pcut', title: '当前折扣', width: 100, sort: true, align: "center", templet: pcut2p }
  272. , { field: 'plowestcut', title: '史低折扣', width: 100, sort: true, align: "center", templet: plowestcut2p }
  273.  
  274. , { field: 'tag', title: '标签', width: 150, align: "center" }
  275. , { field: 'developer', title: '开发商', width: 150, align: "center" }
  276. , { field: 'publisher', title: '发行商', width: 150, align: "center" }
  277.  
  278. , { field: 'tlowest', title: '史低时间', width: 105, sort: true, align: "center", templet: tlowestt2s }
  279. , { field: 'trelease', title: '发售时间', width: 105, sort: true, align: "center", templet: treleaset2s }
  280. , { field: 'tmodify', title: '更新时间', width: 105, sort: true, align: "center", templet: tmodifyt2s }
  281.  
  282. , { field: 'gtype', title: '类型', width: 50, sort: true, align: "center" }
  283. , { field: 'source', title: '来源', width: 50, sort: true, align: "center" }
  284. ]]
  285. , data: data
  286. , skin: 'row' //表格风格
  287. , even: true
  288. , page: true //是否显示分页
  289. , limits: [30, 60, 100, 150, 300, 600, 1000, 1500, 2000]
  290. , limit: 100
  291. , cellMinWidth: 80
  292. , height: 'full-215'
  293. });
  294. });
  295. }
  296. function getPercent(num, total) {
  297. num = parseFloat(num);
  298. total = parseFloat(total);
  299. if (isNaN(num) || isNaN(total)) {
  300. return "0%";
  301. }
  302. return total <= 0 ? "0%" : (Math.round(num / total * 100)) + "%";
  303. }
  304. })();

QingJ © 2025

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