substitute marumaru video

substitute marumaru video to your desire youtube video

当前为 2024-05-18 提交的版本,查看 最新版本

// ==UserScript==
// @name         substitute marumaru video
// @name:en      substitute marumaru video
// @name:zh-TW   替換 marumaru 影片

// @description          substitute marumaru video to your desire youtube video
// @description:en       substitute marumaru video to your desire youtube video
// @description:zh-TW    替換 marumaru 播放的影片成你指定的 youtube 影片

// @license MIT
// @namespace    https://gf.qytechs.cn/users/1303696
// @version      1.0
// @author       xswzaq44321
// @match        https://www.jpmarumaru.com/tw/JPSongPlay*
// @run-at       document-end
// @icon         https://www.google.com/s2/favicons?sz=64&domain=jpmarumaru.com
// @grant        GM.getValue
// @grant        GM.setValue
// ==/UserScript==

function fromHTML(html, trim = true) {
  // Process the HTML string.
  html = trim ? html.trim() : html;
  if (!html) return null;

  // Then set up a new template element.
  const template = document.createElement('template');
  template.innerHTML = html;
  const result = template.content.children;

  // Then return either an HTMLElement or HTMLCollection,
  // based on whether the input HTML had one or more roots.
  if (result.length === 1) return result[0];
  return result;
}

(async function() {
    'use strict';
    if(!document.querySelector("#VideoID").textContent){ // probabliy no youtube player available, abort execution
        return;
    }
    const songPK = document.querySelector("#SongPK").textContent
    let state = await GM.getValue(songPK, {"instrumental": false, "VideoID": ""});
    let messages = {
        "btn": Intl.DateTimeFormat().resolvedOptions().locale == 'zh-TW' ? "切換影片" : "switch video",
        "regFail": Intl.DateTimeFormat().resolvedOptions().locale == 'zh-TW' ? "無法解析替代影片 ID" : "cannot resole video ID",
        "vidIDEmpty": Intl.DateTimeFormat().resolvedOptions().locale == 'zh-TW' ? "沒有可替換的影片 ID" : "no available video ID to substitute",
    }
    var switchBtn = fromHTML(`<a href="javascript:;" class="easyui-linkbutton l-btn l-btn-small" group="" id=""><span class="l-btn-left"><span class="l-btn-text">${state.instrumental ? "🎼" : "🎤"}${messages.btn}</span></span></a>`);
    var VideoIDInput = fromHTML(`<input style="margin:0 0 0 3px" type="text" placeholder="${state.VideoID}">`);
    var elementWrapper = fromHTML(`<div style="padding:0 0 5px 5px"></div>`);
    elementWrapper.appendChild(switchBtn);
    elementWrapper.appendChild(VideoIDInput);
    const reg = new RegExp(/(?:https?:\/\/(?:www\.)?youtube\.com\/watch\?v=|https?:\/\/youtu\.be\/|^)([A-Za-z0-9_-]{11})(?:&.*)?$/)
    switchBtn.onclick = function(){
        let VideoID = state.VideoID;
        if(VideoIDInput.value){
            let regRes = reg.exec(VideoIDInput.value);
            if(!regRes){
                alert(`${messages.regFail}`);
                return;
            }
            VideoID = regRes[1];
        }
        if(!VideoID){
            alert(`${messages.vidIDEmpty}`);
            return;
        }
        state.instrumental = !state.instrumental;
        state.VideoID = VideoID;
        GM.setValue(songPK, state);
        location.reload();
    };
    document.querySelector("#left_col > div:nth-child(2) > div.main > div.main-content.cf > div.clear").nextElementSibling.after(elementWrapper);
    if(state.instrumental && state.VideoID){
        document.querySelector("#VideoID").textContent = state.VideoID
    }
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址