SLIVE - 유튜브 영상풍선 조회수, 좋아요, 싫어요(추정치) 표시

영상 정보를 가져오기 위해 Return YouTube Dislike(https://returnyoutubedislike.com/) API를 사용합니다.

当前为 2024-12-14 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         SLIVE - 유튜브 영상풍선 조회수, 좋아요, 싫어요(추정치) 표시
// @namespace    https://www.afreecatv.com/
// @version      2.0.0
// @description  영상 정보를 가져오기 위해 Return YouTube Dislike(https://returnyoutubedislike.com/) API를 사용합니다.
// @author       Jebibot
// @match        *://file.ext-sooplive.co.kr/*/4d4664eb15c038334d891ccbfc262cde/*/bj_screen.html
// @icon         https://www.google.com/s2/favicons?sz=64&domain=www.sooplive.co.kr
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
  "use strict";

  const numberFormat = Intl.NumberFormat(undefined, { notation: "compact" });
  const votesCache = new Map();

  const addInfo = async (n) => {
    try {
      const span = n.querySelector(".info span");
      if (span == null || span.querySelector("i")) {
        return;
      }
      const info = JSON.parse(n.dataset.json);
      if (info.platformType === "youtube") {
        let votes = votesCache.get(info.videoUniqueKey);
        if (votes == null) {
          const req = await fetch(
            `https://returnyoutubedislikeapi.com/votes?videoId=${info.videoUniqueKey}`
          );
          if (!req.ok) {
            throw new Error(`${req.status} ${req.statusText}`);
          }
          votes = await req.json();
          votesCache.set(info.videoUniqueKey, votes);
        }

        const i = document.createElement("i");
        i.textContent = ` 👀${numberFormat.format(
          votes.viewCount
        )} 👍${numberFormat.format(votes.likes)} 👎${numberFormat.format(
          votes.dislikes
        )}`;
        span.appendChild(i);
      }
    } catch (e) {
      console.error(e);
    }
  };

  const vodList = document.getElementById("ul_vod_list");
  const vodListObserver = new MutationObserver((mutations) => {
    for (const mutation of mutations) {
      for (const n of mutation.addedNodes) {
        if (n.tagName === "LI") {
          addInfo(n);
        }
      }
    }
  });
  vodListObserver.observe(vodList, { childList: true });

  for (const n of vodList.children) {
    addInfo(n);
  }
})();