trtc-success-rate

try to take over the world!

当前为 2020-09-25 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         trtc-success-rate
// @namespace    http://tampermonkey.net/
// @version      0.5
// @description  try to take over the world!
// @author       You
// @match        https://mta.qq.com/h5/visitor/ctr_button_stat/config?app_id=500699039
// @grant        none
// ==/UserScript==

(async function() {
  'use strict';

  /**
   *
   * @param {*} arg
   * @return {*}
   */
  function parseDom(arg) {
    var objE = document.createElement('div');
    objE.innerHTML = arg;
    return objE.childNodes;
  }

  /**
   * 获取事件列表
   * @return {*}
   */
  async function getList() {
    let { data } = await fetch(
      'https://mta.qq.com/h5/visitor/ctr_button_stat/get_config_data?&app_id=500699039&rnd=1601001086951&ajax=1'
    ).then(res => res.json());
    return data
      .filter(item => item.custom_id !== 'version' && item.custom_id !== 'sdkAppID')
      .map(item => {
        const res = {};
        res[item.custom_id] = parseDom(item.control)[0].dataset.id;
        return res;
      });
  }

  /**
   *
   *
   * @param {*} timestamp
   * @return {*}
   */
  function getDate(timestamp) {
    const date = new Date(timestamp);
    return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;
  }
  /**
   *
   * @param {number} id
   * @return {*}
   */
  async function getSuccessRate(id, span = 7) {
    const now = new Date();
    const startDate = getDate(now - span * 24 * 3600 * 1000);
    const endDate = getDate(now);
    const { data } = await fetch(
      `https://mta.qq.com/h5/visitor/ctr_custom_param/get_table?start_date=${startDate}&end_date=${endDate}&app_id=500699039&custom_id=${id}&param_id=value&rnd=1601000365539&ajax=1`
    ).then(res => res.json());
    const pending = data.filter(item => item.param_value.includes('pending'))[0].btn_stat;
    const success = data.filter(item => item.param_value.includes('success'))[0].btn_stat;
    const rate = ((success / pending) * 100).toFixed(2) + '%';
    return { rate, pending, success };
  }

  const list = await getList();
  list.forEach(async (item, index) => {
    const key = Object.keys(item)[0];
    const id = item[key];
    const { rate, pending, success } = await getSuccessRate(id);
    const table = document.getElementById('div_table_table');
    table.rows[index + 1].cells[1].childNodes[0].innerHTML += `: ${rate} (${success}/${pending})`;
  });
})();