Youtube Downloader

Adds a download button (That actually looks good) that redirects to yt1s.com.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Youtube Downloader
// @namespace    http://qweren.neocities.org/
// @icon         https://upload.wikimedia.org/wikipedia/commons/thumb/0/09/YouTube_full-color_icon_%282017%29.svg/1024px-YouTube_full-color_icon_%282017%29.svg.png
// @version      Release
// @description  Adds a download button (That actually looks good) that redirects to yt1s.com.
// @author       qweren
// @match        *://www.youtube.com/watch?v=*
// @grant        none
// @run-at document-body
// @license      CC-BY-NC-SA
// ==/UserScript==

(function() {
    // Function to append the button and tooltip
    function appendButtonAndTooltip() {
        const menu = document.getElementById("top-level-buttons-computed");

        // Remove existing download button
        const existingDownloadButton = document.querySelector('.style-scope.ytd-download-button-renderer');
        if (existingDownloadButton) existingDownloadButton.remove();

        const containerDiv = document.createElement('div');
        containerDiv.className = 'tooltip-container';

        const newButton = document.createElement('button');
        newButton.style.marginLeft = "8px";
        newButton.innerHTML = `<svg height='24' viewBox='0 0 24 24' width='24' focusable='false'><path fill='white' d='M17 18v1H6v-1h11zm-.5-6.6-.7-.7-3.8 3.7V4h-1v10.4l-3.8-3.8-.7.7 5 5 5-4.9z'></path></svg>`;
        newButton.setAttribute("id", "download-button");

        const tooltip = document.createElement('tp-yt-paper-tooltip');
        tooltip.setAttribute('fit-to-visible-bounds', '');
        tooltip.setAttribute('offset', '8');
        tooltip.style = 'inset: 44px auto auto 187.258px;';
        tooltip.textContent = 'Download';
        tooltip.classList.remove('hidden');
        containerDiv.appendChild(tooltip);

        const currentLink = encodeURIComponent(window.location.href);
        const redirectURL = `https://yt1s.com/en/youtube-to-mp4?q=${currentLink}`;

        newButton.addEventListener('click', () => window.open(redirectURL, '_blank'));
        newButton.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 ';

        containerDiv.appendChild(newButton);
        menu.appendChild(containerDiv);
    }

    // Append the button and tooltip when the page loads
    setTimeout(appendButtonAndTooltip, 5000);

    setInterval(function () {
        if(document.getElementById("container")){
            if(!document.getElementById("download-button")){
                appendButtonAndTooltip();
            }
        }
    }, 6000);
})();