SWH_Helper

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

目前为 2020-12-23 提交的版本。查看 最新版本

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

QingJ © 2025

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