在主按鈕列新增一個「儲存」快捷鍵,點擊自動展開選單並點擊儲存
当前为
// ==UserScript==
// @name YouTube 修復儲存快捷按鈕
// @namespace http://tampermonkey.net/
// @version 1.1
// @description 在主按鈕列新增一個「儲存」快捷鍵,點擊自動展開選單並點擊儲存
// @author shanlan(ChatGPT o3-mini)
// @match https://www.youtube.com/*
// @grant none
// @run-at document-end
// @license MIT
// ==/UserScript==
(function(){
'use strict';
const observer = new MutationObserver(addSaveShortcut);
observer.observe(document.body, {childList: true, subtree: true});
function addSaveShortcut(){
const topBtns = document.querySelector('#top-level-buttons-computed');
if(!topBtns || topBtns.querySelector('.yt-save-shortcut-btn')) return;
const btn = document.createElement('button');
btn.className = 'yt-spec-button-shape-next yt-spec-button-shape-next--tonal yt-spec-button-shape-next--mono yt-spec-button-shape-next--size-m yt-spec-button-shape-next--icon-leading yt-save-shortcut-btn';
btn.style.marginLeft = '8px';
btn.innerHTML = `
<div aria-hidden="true" class="yt-spec-button-shape-next__icon">
<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24" style="vertical-align:middle">
<path d="M18 4v15.06l-5.42-3.87-.58-.42-.58.42L6 19.06V4h12m1-1H5v18l7-5 7 5V3z"></path>
</svg>
</div>
<div class="yt-spec-button-shape-next__button-text-content">儲存</div>`;
btn.onclick = function(e){
e.stopPropagation();
const moreBtn = document.querySelector('ytd-menu-renderer yt-icon-button#button, ytd-menu-renderer yt-button-shape#button-shape');
if(!moreBtn) return;
moreBtn.click();
let tryCount = 0;
const tryClickSave = setInterval(()=>{
tryCount++;
const saveItem = Array.from(document.querySelectorAll('ytd-menu-popup-renderer tp-yt-paper-listbox ytd-menu-service-item-renderer'))
.find(item => item.innerText.trim().includes('儲存'));
if(saveItem){
saveItem.click();
clearInterval(tryClickSave);
}
if(tryCount > 20) clearInterval(tryClickSave);
}, 100);
};
topBtns.appendChild(btn);
}
})();
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址