아프리카TV - 참여 통계 리캡

참여 통계에 스트리머 별 총 시간을 표시합니다

// ==UserScript==
// @name         아프리카TV - 참여 통계 리캡
// @namespace    https://www.afreecatv.com/
// @version      1.0.1
// @description  참여 통계에 스트리머 별 총 시간을 표시합니다
// @author       Jebibot
// @match        *://broadstatistic.afreecatv.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=afreecatv.com
// @grant        unsafeWindow
// @license      MIT
// ==/UserScript==

(function () {
  "use strict";

  const container = document.createElement("div");
  container.id = "recap";
  container.style.height = "100%";
  const chart = document.getElementById("containchart");
  if (chart == null) {
    return;
  }
  chart.parentNode.appendChild(container);

  const oPage = unsafeWindow.oPage;
  const setMultipleChart = oPage.setMultipleChart.bind(oPage);
  oPage.setMultipleChart = (data) => {
    setMultipleChart(data);

    new unsafeWindow.Highcharts.Chart({
      chart: {
        renderTo: "recap",
        width: 900,
        height: Math.max(300, data.data_stack.length * 40),
        zoomType: "xy",
      },
      title: {
        text: null,
      },
      legend: {
        enabled: false,
      },
      xAxis: {
        type: "category",
      },
      yAxis: {
        opposite: true,
        title: {
          text: null,
        },
      },
      plotOptions: {
        series: {
          type: "bar",
          colorByPoint: true,
        },
      },
      tooltip: {
        valueDecimals: 0,
        valueSuffix: "분",
      },
      series: [
        {
          type: "bar",
          name: "시간",
          data: data.data_stack
            .map((t) => [t.bj_nick, t.data.reduce((a, b) => a + b, 0) / 60])
            .sort((a, b) => {
              if (a[0] === "기타") {
                return 1;
              } else if (b[0] === "기타") {
                return -1;
              } else {
                return b[1] - a[1];
              }
            }),
        },
      ],
    });
  };
})();