🎉 欢迎访问GreasyFork.Org 镜像站!本镜像站由公众号【爱吃馍】搭建,用于分享脚本。联系邮箱📮

Greasy fork 爱吃馍镜像

유튜브 뮤직에서 듣기 버튼 추가

유튜브 재생바에 유튜브 뮤직에서 이어서 듣기 버튼추가

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

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

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

// ==UserScript==
// @name         유튜브 뮤직에서 듣기 버튼 추가
// @namespace    https://greasyfork.org/scripts/540872
// @version      1.0
// @description  유튜브 재생바에 유튜브 뮤직에서 이어서 듣기 버튼추가
// @match        https://www.youtube.com/watch*
// @author       다크초코
// @license MIT
// ==/UserScript==

(function () {
  const BTN_CLASS = 'yt-music-btn';

    function buildIcon() {
        const NS = 'http://www.w3.org/2000/svg';
        const svg = document.createElementNS(NS, 'svg');
        svg.setAttribute('viewBox', '0 0 36 36');
        svg.setAttribute('width', '100%');
        svg.setAttribute('height', '100%');

        svg.style.display = 'block';
        svg.style.position = 'relative';
        svg.style.top = '-5px';
        const bg = document.createElementNS(NS, 'circle');
        bg.setAttribute('cx', 18);
        bg.setAttribute('cy', 18);
        bg.setAttribute('r', 13);
        bg.setAttribute('fill', '#FF0000');

        const ring = document.createElementNS(NS, 'circle');
        ring.setAttribute('cx', 18);
        ring.setAttribute('cy', 18);
        ring.setAttribute('r', 9);
        ring.setAttribute('fill', 'none');
        ring.setAttribute('stroke', '#FFFFFF');
        ring.setAttribute('stroke-width', 1);

        const tri = document.createElementNS(NS, 'polygon');
        tri.setAttribute('points', '16,13 16,23 23,18');
        tri.setAttribute('fill', '#FFFFFF');

        svg.append(bg, ring, tri);
        return svg;
    }





  function createBtn() {
    const btn = document.createElement('button');
    btn.className = `ytp-button ${BTN_CLASS}`;
    btn.title = 'YT Music에서 이어서 듣기';
    btn.style.width = '36px';
    btn.style.height = '36px';
    btn.style.lineHeight = '0';
    btn.appendChild(buildIcon());

    btn.addEventListener('click', () => {
      const video = document.querySelector('video');
      if (!video) return;
      const t = Math.floor(video.currentTime);
      const v = new URLSearchParams(location.search).get('v');
      if (!v) return;
      video.pause();
      window.open(`https://music.youtube.com/watch?v=${v}&t=${t}&autoplay=1`, '_blank');
    });
    return btn;
  }

  function inject() {
    const host = document.querySelector('.ytp-chrome-controls .ytp-right-controls');
    if (!host || host.querySelector('.' + BTN_CLASS)) return false;
    host.prepend(createBtn());
    return true;
  }

  new MutationObserver(inject).observe(document, {childList: true, subtree: true});
  window.addEventListener('yt-navigate-finish', () => setTimeout(inject));
  const backup = setInterval(() => inject() && clearInterval(backup), 3000);
})();