在线统计owhat集资金额

在线统计owhat集资金额

/**
 * 在线统计owhat集资金额
 * 步骤如下:
 * 1、先在PC浏览器打开ow主页或物品页 (可登录自己的ow账号)
 * 2、打开浏览器开发者工具,打开控制台(Console)页面
 * 3、执行以下代码即可实时统计(统计频率可自己调节,建议不小于30s)
 * 4、执行timer.stop()即可停止统计(刷新或关闭网页也行)
 * 
 * 更新:1、不在ow页面询问跳转ow主页
 *      2、物品页面支持获取当前物品Id
 */
const timer = (function(job) {
  let timeId = 0;
  const { host, pathname, search } = location;
  const query = new URLSearchParams(search);
  const goodsId = pathname === "/shop/shopdetail.html" && query.get("id") || 111400;
  return {
    start(intervals) {
      if (host !== "m.owhat.cn" && host !== "www.owhat.cn") {
        console.warn("请打开相关ow商品页面再执行统计,ow主页: https://www.owhat.cn");
        if(confirm("是否跳转ow主页?")) {
          location.href = "https://www.owhat.cn";
        }
        return;
      }
      console.log(`已开始统计,物品Id:${goodsId}.`);
      job(goodsId);
      intervals = intervals || 30;
      timeId && clearInterval(timeId);
      timeId = setInterval(() => job(goodsId), intervals*1000);
      return timeId;
    },
    stop(){
      timeId && clearInterval(timeId);
      console.log("已停止统计.");
    }
  }
})(async function (id) {
  const data = $.apiInit($.apimap, "goodselect", { fk_goods_id: id });
  let res = await fetch(`${location.origin}/api?requesttimestap=${new Date().getTime()}`, {
    method: "POST",
    body: $.param(data),
    headers: {
      "Content-Type": "application/x-www-form-urlencoded",
    },
    credentials: "same-origin",
  });

  if (res.status === 200) {
    let result = await res.json();
    if (
      result && result.data && 
      result.data.prices && 
      result.data.prices.length
    ) {
      let table = [];
      result.data.prices.forEach(item => {
        table.push({
          "名称": item.name,
          "单价": item.price,
          "数量": item.salestock,
          "金额": parseInt(100 * item.price * item.salestock)/100
        });
      });
      table.length && table.push({
        "名称": "总额",
        "单价": "-",
        "数量": "-",
        "金额": parseInt(100*table.reduce((r,c)=>r+c["金额"],0))/100
      });
      console.log(
        `%c截止[${new Date().toLocaleString()}]统计金额为: ¥${table[table.length-1]["金额"]}`,
        'font-size:20px;color:red;'
      );
      console.table(table);
      return;
    } else {
      console.warn("request failure.", result);
      return;
    }
  }

  console.error("request error.", res.statusText);
});

timer.start(30);//每隔30s统计一次
//timer.stop(); //停止统计

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


uuid javascript语言代码function uuid() {   return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
js关闭当前页面
二维数组动态定义,赋值。 例如创建一个N行2列的二维数组。
jQuery实现PHP的htmlspecialchars的功能
js关闭当前页面
提取网页中的表格,把输出的内容复制粘贴到表格即可
js中,将数字字符串转换成数字,parseInt不是很好的办法,因为当你忘了传第二个参数的时候,会出现一些问题
javascript 中,删除一个数组,应该使用`arr.length = 0`,而不是`delete a`
广告屏蔽检测
js根据相对url获取绝对url的一种方式
404模板
vscode settings.json
简单的数组排序
简单的数组去重
React + nodejs 提交成功界面(包含进度条)
在线统计owhat集资金额
混合数组深度去重,源自项目 gQuery.js
jsbeautify配置文件
匹配邮箱
源代码: vue特效70行代码,一片动态星空 视频地址: https://www.bilibili.com/video/BV1EJ411e7sr