坦克世界特惠商城历史订单汇总

访问https://shop.wot.360.cn/orderlist.html即可查看历史消费记录、送礼记录、收礼记录

  1. // ==UserScript==
  2. // @name 坦克世界特惠商城历史订单汇总
  3. // @namespace wot-order-list
  4. // @version 1.0.4
  5. // @description 访问https://shop.wot.360.cn/orderlist.html即可查看历史消费记录、送礼记录、收礼记录
  6. // @author Eruru
  7. // @match https://shop.wot.360.cn/orderlist.html
  8. // @icon https://shop.wot.360.cn/favicon.ico
  9. // @require https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.3.2/html2canvas.min.js
  10. // @grant none
  11. // @license MPL
  12. // ==/UserScript==
  13. (function() {
  14. 'use strict';
  15. // Your code here...
  16. var ids = ["shop-summary", "shop-summary-gift", "shop-summary-receive-gift"];
  17. $(".summary-table").remove ();
  18. $(".header").after ($("<table class='summary-table header' style='width: 1204px; margin: 0 auto;'><tr><td class='summary-table-placeholder'></td></tr></table>"));
  19. var panelElement = $(".summary-table-placeholder");
  20. for (var i =0;i<ids.length;i++) {
  21. panelElement.append ("<div class='"+ids[i]+"' style='margin-top: 30px;'></div>");
  22. }
  23. $.get("https://shop.wot.360.cn/api/order/list?game_id=1&ct=all&pn=1&ps=9999", function (response) {
  24. displayOrderList(ids[0], "消费记录", true, response);
  25. });
  26. $.get("https://shop.wot.360.cn/api/gift/sends?game_id=1&ct=undefined&pn=1&ps=9999", function (response) {
  27. displayOrderList(ids[1], "送礼记录", false, response);
  28. });
  29. $.get("https://shop.wot.360.cn/api/gift/receiver?game_id=1&ct=all&pn=1&ps=9999", function (response) {
  30. displayOrderList(ids[2], "收礼记录", false, response);
  31. });
  32. function displayOrderList(id, title, isPop, response) {
  33. var items = response.data.list;
  34. var currentSummary = new Summary();
  35. var summary = new Summary();
  36.  
  37. var snapshootBtn = isPop ? `<a class="summary-snapshoot-btn" style="padding: 0 15px;">存为截图</a>` : ''
  38. var slotRight = `<div style="position: absolute;top: 0;right: 0;color: cornflowerblue;bottom: 0;cursor: pointer;user-select: none;">${snapshootBtn}<a class="${id}-spread-btn" style="padding: 0 15px;">收起</a></div>`
  39.  
  40. var text = "<table border='1' style='width: 100%;'>";
  41. text += "<tr align='center' style='color: #f26402;position: relative;''><td colspan='4'>" + title + slotRight + "</td></tr>"
  42. text += "<tr align='center' style='color: #f26402;'><td width='60px'>序号</td><td>商品</td><td width='100px'>价格</td><td width='220px'>时间</td></tr>";
  43. var unknownTypes = [];
  44. var unknownStatus = [];
  45. for (var i = 0; i < items.length; i++) {
  46. var type = items[i]["type"];
  47. switch (type) {
  48. case "pop":
  49. case "subscribe":
  50. if (!isPop) {
  51. continue;
  52. }
  53. break;
  54. case "gift":
  55. if (isPop) {
  56. continue;
  57. }
  58. break;
  59. default:
  60. if (unknownTypes.indexOf (type) == -1) {
  61. unknownTypes.push (type);
  62. }
  63. break;
  64. }
  65. var status = items[i]["status"];
  66. switch (status) {
  67. case "SUCCESS":
  68. case "DELIVER_SUCC":
  69. break;
  70. default:
  71. if (unknownStatus.indexOf (status) == -1) {
  72. unknownStatus.push (status);
  73. }
  74. break;
  75. }
  76. var date = new Date(items[i]["create_time"]);
  77. if (i == 0) {
  78. currentSummary.year = date.getFullYear();
  79. }
  80. if (currentSummary.year != date.getFullYear()) {
  81. text += summaryToHtml(currentSummary);
  82. currentSummary = new Summary();
  83. currentSummary.year = date.getFullYear();
  84. }
  85. var goods = items[i]["goods"];
  86. var price = parseFloat(goods["price"]);
  87. var name = goods["name"];
  88. var packageContents = goods["package_content"];
  89. var count = items[i]["goods_count"];
  90. if (packageContents != null && packageContents.length > 0) {
  91. name += " ( " + packageContents.map(item => item["content"]).join("、") + " )";
  92. }
  93. if (count > 1) {
  94. name += " *" + count;
  95. }
  96. currentSummary.count++;
  97. currentSummary.price += price;
  98. summary.count++;
  99. summary.price += price;
  100. text += `<tr align='center' class='${id}-record'>`;
  101. text += "<td>" + (i + 1) + "</td>";
  102. text += "<td>" + name + "</td>";
  103. text += "<td>" + price + " 元</td>";
  104. text += "<td>" + dateToString(date) + "</td>";
  105. text += "</tr>";
  106. }
  107. if (items.length > 0) {
  108. text += summaryToHtml(currentSummary);
  109. }
  110. text += summaryToHtml(summary);
  111. text += "</table>";
  112. $("." + id).append(text);
  113. var debugText = "";
  114. if (unknownTypes.length > 0) {
  115. debugText += "未知的Types: " + unknownTypes.join ("、");
  116. }
  117. if (unknownStatus.length > 0) {
  118. if (debugText.length > 0) {
  119. debugText += "\r\n";
  120. }
  121. debugText += "未知的Status: " + unknownStatus.join ("、");
  122. }
  123. if (debugText.length > 0) {
  124. debugText = id + " 信息:\r\n" + debugText;
  125. alert (debugText);
  126. }
  127.  
  128. $(`.${id}-spread-btn`).on("click", function () {
  129. spreadTable(id);
  130. });
  131. $('.summary-snapshoot-btn').on("click", function () {
  132. snapshootTable(id);
  133. });
  134. }
  135. function dateToString(date) {
  136. var year = date.getFullYear();
  137. var month = date.getMonth() + 1;
  138. var day = date.getDate();
  139. var hours = date.getHours();
  140. var minutes = date.getMinutes();
  141. var seconds = date.getSeconds();
  142. return year + "年" + month + "月" + day + "日 " + hours + "时" + minutes + "分" + seconds + "秒";
  143. }
  144. function summaryToHtml(summary) {
  145. return "<tr align='center' style='color: #f26402;'><td>" + (summary.year == 0 ? "至今" : summary.year + "年") + "</td><td>共 " + summary.count + " 份订单</td><td colspan='2'>共 " + summary.price.toFixed(2) + " 元</td></tr>";
  146. }
  147. function Summary() {
  148. this.year = 0;
  149. this.count = 0;
  150. this.price = 0.0;
  151. }
  152. function spreadTable(id) {
  153. let btn = document.querySelector(`.${id}-spread-btn`);
  154. if (btn.innerText == '展开') {
  155. btn.innerText = '收起';
  156. document.querySelectorAll(`.${id}-record`).forEach(item => {
  157. item.style.display = 'table-row';
  158. })
  159. } else {
  160. btn.innerText = '展开';
  161. document.querySelectorAll(`.${id}-record`).forEach(item => {
  162. item.style.display = 'none';
  163. })
  164. }
  165. }
  166. function snapshootTable(id) {
  167. var getPixelRatio = function (context) { // 获取设备的PixelRatio
  168. var backingStore = context.backingStorePixelRatio ||
  169. context.webkitBackingStorePixelRatio ||
  170. context.mozBackingStorePixelRatio ||
  171. context.msBackingStorePixelRatio ||
  172. context.oBackingStorePixelRatio ||
  173. context.backingStorePixelRatio || 0.5;
  174. return (window.devicePixelRatio || 0.5) / backingStore;
  175. };
  176. //生成的图片名称
  177. var imgName = `360消费记录-${dateToString(new Date())}.jpg`;
  178. var shareContent = document.querySelector(".summary-table.header");
  179. var width = shareContent.offsetWidth;
  180. var height = shareContent.offsetHeight;
  181. var canvas = document.createElement("canvas");
  182. var context = canvas.getContext('2d');
  183. var scale = getPixelRatio(context); //将canvas的容器扩大PixelRatio倍,再将画布缩放,将图像放大PixelRatio倍。
  184. canvas.width = width * scale;
  185. canvas.height = height * scale;
  186. canvas.style.width = width + 'px';
  187. canvas.style.height = height + 'px';
  188. var opts = {
  189. scale: scale,
  190. logging: true,
  191. useCORS: true,
  192. canvas: canvas,
  193. width: width,
  194. height: height,
  195. backgroudColor: '#232323',
  196. dpi: window.devicePixelRatio
  197. };
  198. html2canvas(shareContent, opts).then(function (canvas) {
  199. context.imageSmoothingEnabled = false;
  200. context.webkitImageSmoothingEnabled = false;
  201. context.msImageSmoothingEnabled = false;
  202. context.imageSmoothingEnabled = false;
  203. var dataUrl = canvas.toDataURL('image/jpeg', 1.0);
  204. dataURIToBlob(imgName, dataUrl, callback);
  205. });
  206. var dataURIToBlob = function (imgName, dataURI, callback) {
  207. var binStr = atob(dataURI.split(',')[1]),
  208. len = binStr.length,
  209. arr = new Uint8Array(len);
  210. for (var i = 0; i < len; i++) {
  211. arr[i] = binStr.charCodeAt(i);
  212. }
  213. callback(imgName, new Blob([arr]));
  214. }
  215. var callback = function (imgName, blob) {
  216. var triggerDownload = $("<a>").attr("href", URL.createObjectURL(blob)).attr("download", imgName).appendTo("body").on("click", function () {
  217. if (navigator.msSaveBlob) {
  218. return navigator.msSaveBlob(blob, imgName);
  219. }
  220. });
  221. triggerDownload[0].click();
  222. triggerDownload.remove();
  223. };
  224. }
  225.  
  226. })();