Greasy Fork is available in English.

「Z-Blog」开发者工具(应用中心)

含订单搜索,附带隐藏未付订单,应用审核回显;

  1. // ==UserScript==
  2. // @name 「Z-Blog」开发者工具(应用中心)
  3. // @namespace https://www.wdssmq.com/
  4. // @version 2.1
  5. // @author 沉冰浮水
  6. // @description 含订单搜索,附带隐藏未付订单,应用审核回显;
  7. // @license MIT
  8. // @null ----------------------------
  9. // @contributionURL https://github.com/wdssmq#%E4%BA%8C%E7%BB%B4%E7%A0%81
  10. // @contributionAmount 5.93
  11. // @null ----------------------------
  12. // @link https://github.com/wdssmq/userscript
  13. // @link https://afdian.net/@wdssmq
  14. // @link https://greasyfork.org/zh-CN/users/6865-wdssmq
  15. // @null ----------------------------
  16. // @noframes
  17. // @match https://app.zblogcn.com/zb_system/admin/edit.php*id=*
  18. // @match https://app.zblogcn.com/zb_users/plugin/AppBuy/shop/main.php*
  19. // @match https://app.zblogcn.com/?id=*
  20. // @match https://user.zblogcn.com/trade/money/payout
  21. // @grant none
  22. // ==/UserScript==
  23.  
  24. /* jshint esversion: 6 */
  25.  
  26. (function () {
  27. "use strict";
  28.  
  29. const gm_name = "zbp_DevTools";
  30.  
  31. // ---------------------------------------------------
  32. const _log = (...args) => console.log(`[${gm_name}]\n`, ...args);
  33. // ---------------------------------------------------
  34. let $ = null;
  35. try {
  36. $ = window.$ || unsafeWindow.$;
  37. } catch (e) {
  38. // _error(e);
  39. }
  40. function $n(e) {
  41. return document.querySelector(e);
  42. }
  43. // ---------------------------------------------------
  44. const fnElChange = (el, fn = () => { }) => {
  45. const observer = new MutationObserver((mutationRecord, mutationObserver) => {
  46. // _log('mutationRecord = ', mutationRecord);
  47. // _log('mutationObserver === observer', mutationObserver === observer);
  48. fn(mutationRecord, mutationObserver);
  49. // mutationObserver.disconnect();
  50. });
  51. observer.observe(el, {
  52. // attributes: false,
  53. // attributeFilter: ["class"],
  54. childList: true,
  55. // characterData: false,
  56. subtree: true,
  57. });
  58. };
  59.  
  60. // 前台编辑链接
  61. (() => {
  62. if ($ === null) return;
  63. if ($(".app-content").text() === "") return false;
  64. const edtLink =
  65. "https://app.zblogcn.com/zb_system/admin/edit.php" +
  66. location.search +
  67. "&act=ArticleEdt";
  68. const domLink = $(
  69. "<a title=\"编辑\" target=\"_blank\" href=\"" + edtLink + "\">编辑</a>",
  70. );
  71. domLink
  72. .css({
  73. color: "darkgray",
  74. "font-size": "14px",
  75. "padding-left": "0.5em",
  76. })
  77. .hover(
  78. function () {
  79. $(this).css({
  80. color: "#d60000",
  81. });
  82. },
  83. function () {
  84. $(this).css({
  85. color: "darkgray",
  86. });
  87. },
  88. );
  89. $(".app-header-detail h3").append(domLink);
  90. })();
  91.  
  92. // Ajax 回显自动审核
  93. (() => {
  94. if ($ === null) return;
  95. let $p = $("#response3 dl p");
  96. if ($p.length == 0 || $p.find("a").length == 1) {
  97. return;
  98. }
  99. function fnGet(cb) {
  100. $.ajax({
  101. url: location.href,
  102. type: "get",
  103. success: function (data) {
  104. let $el = $(data).find("#response3 dl a");
  105. if ($el.attr("href")) {
  106. cb($el.attr("href"));
  107. }
  108. console.log($el.attr("href"));
  109. },
  110. });
  111. }
  112. let i = 43;
  113. let t = setInterval(() => {
  114. $p.html(`自动审核中,请稍侯${i}`);
  115. i--;
  116. if (i % 13 == 0) {
  117. fnGet((href) => {
  118. $p.html(
  119. `自动审核完毕,<a target="_blank" href="${href}">请点击此处查看。</a>`,
  120. );
  121. clearInterval(t);
  122. });
  123. }
  124. if (i == 0) {
  125. i = 47;
  126. }
  127. }, 1000);
  128. })();
  129.  
  130. (() => {
  131. if ($ === null) return;
  132. // 移除指定的节点
  133. function fnHide(t = "") {
  134. let curHtml;
  135. $("tr").each(function () {
  136. curHtml = $(this).html();
  137. if (/待付款/.test(curHtml)) $(this).remove();
  138. if (t === "all") $(this).remove();
  139. });
  140. }
  141.  
  142. // 时间对比转天数
  143. function fnTimeDiff(recent, past) {
  144. let timeDiff = recent.getTime() - past.getTime();
  145. let diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));
  146. return diffDays;
  147. }
  148.  
  149. // 初始全局变量
  150. const gobBase = {
  151. oDate: null,
  152. timeRan: {
  153. recent: null,
  154. past: null,
  155. },
  156. // 订单计数
  157. intCount: 0,
  158. // 价格总计
  159. intTOL: 0,
  160. // 金额累加,输入为金额字符串,扣除分成
  161. add(amt) {
  162. this.intTOL += parseFloat(amt) * 100 * 0.75;
  163. },
  164. diff() {
  165. const intDiff = fnTimeDiff(this.timeRan.recent, this.timeRan.past);
  166. return intDiff > 0 ? intDiff : 1;
  167. },
  168. view(t = "") {
  169. let rltNum = 0;
  170. switch (t) {
  171. case "perDay":
  172. rltNum = this.intTOL / this.diff() / 100;
  173. break;
  174. case "perMonth":
  175. rltNum = this.intTOL / this.diff() / 100 * 30;
  176. break;
  177. default:
  178. rltNum = this.intTOL / 100;
  179. break;
  180. }
  181. return rltNum.toFixed(2);
  182. },
  183. };
  184.  
  185. // 实际调用
  186. let gob;
  187.  
  188. // 搜索调用
  189. function fnSearch(q) {
  190. gob = Object.assign({}, gobBase);
  191. _log(JSON.stringify(gob));
  192. const regPat = new RegExp(q + ".+已付款", "");
  193. fnHide("all");
  194. fnAjax(1, regPat);
  195. }
  196.  
  197. // Ajax 请求
  198. function fnAjax(page, regPat) {
  199. $.ajax({
  200. url:
  201. "https://app.zblogcn.com/zb_users/plugin/AppBuy/shop/main.php?page=" +
  202. page,
  203. type: "get",
  204. success: function (data) {
  205. if (/已付款/.test(data)) {
  206. // if (/已付款/.test(data) && page < 2) {
  207. // _log($(data));
  208. let curHtml;
  209. $(data)
  210. .find("#divMain2 table tr")
  211. .each(function () {
  212. curHtml = $(this)
  213. .html()
  214. .replace(/[\n\s]+/g, " ");
  215. if (regPat.test(curHtml) === true) {
  216. // 匹配时间字符串
  217. let mltDate = curHtml.match(/<td.*>([^<]+)<\/td> <td>已付款<\/td>/);
  218. // 转换时间对象
  219. gob.oDate = new Date(Date.parse(mltDate[1]));
  220.  
  221. _log(curHtml);
  222. _log(gob.oDate);
  223.  
  224. // 日期区间
  225. if (gob.timeRan.recent === null) {
  226. gob.timeRan.recent = gob.oDate;
  227. }
  228. gob.timeRan.past = gob.oDate;
  229. // 订单计数
  230. gob.intCount++;
  231. // 匹配金额字符串
  232. // let mltAMT = curHtml.match(/<td>¥([^<]+)<\/td>/);
  233. let mltAMT = curHtml.match(/<td>¥[^<]+\(([^<]+)\)<\/td>/);
  234. // 金额累加
  235. gob.add(mltAMT[1]);
  236. // 添加节点
  237. $("table:not(#tbStatistic) tbody").append(
  238. "<tr>" + curHtml + "</tr>\n",
  239. );
  240. }
  241. });
  242. page++;
  243. fnAjax(page, regPat);
  244. $("#js-page").text(page);
  245. } else {
  246. $("#js-page").text("完成");
  247. const strTR = `<tr>
  248. <td colspan="2"></td>
  249. <td>${gob.intCount}</td>
  250. <td>${gob.view()}</td>
  251. <td colspan="2">${gob.view("perDay")}/天 | ${gob.view("perMonth")}/30 天</td>
  252. <td>天数:${gob.diff()}</td>
  253. <td></td>
  254. <td></td>
  255. </tr>`;
  256. $("table:not(#tbStatistic) tbody").prepend(
  257. strTR,
  258. );
  259. // _log(gob);
  260. } },
  261. // end success
  262. });
  263. }
  264.  
  265. // 放置搜索框
  266. $(".SubMenu").append(
  267. "<input id=\"search\" style=\"float:left;margin-right: 2px;margin-top: 2px\" type=\"text\" value=\"\">" +
  268. "<a href=\"javascript:;\" id=\"js-search\"><span class=\"m-left\">搜索</span></a>" +
  269. "<span id=\"js-page\"></span>",
  270. );
  271.  
  272. // 搜索触发
  273. $("#js-search").click(function () {
  274. const search = $("#search").val();
  275. // alert(search);
  276. fnSearch(search);
  277. });
  278. })();
  279.  
  280. (() => {
  281. const $body = $n("body");
  282. fnElChange($body, (mutationRecord, mutationObserver) => {
  283. const $input = $n(".ivu-input-number-input");
  284. const $amt = $n(".ivu-alert-message p b");
  285. if ($input === null) return;
  286. $input.value = $amt.innerText;
  287. mutationObserver.disconnect();
  288. });
  289. })();
  290.  
  291. })();