Neura

The ultimate YouTube tool by Kan and Cybr

目前為 2024-12-23 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Neura
// @namespace    .gg/Neura
// @version      1.1
// @description  The ultimate YouTube tool by Kan and Cybr
// @author       Cybr
// @license      MIT
// @match        https://*.youtube.com/*
// @grant        GM_addStyle
// ==/UserScript==

(function() {
    var downloadBaseURL = "//yt1s.com/youtube-to-mp3?q=";
    var buttonID = "neuraDownloadButton";
    var buttonContainer = "#owner";

    GM_addStyle(`
        #${buttonID} {
            background-color: #800080; /* Purple background */
            color: white;
            border: none;
            margin-left: 8px;
            padding: 0 16px;
            border-radius: 18px;
            font-size: 14px;
            font-family: Roboto, sans-serif;
            font-weight: bold;
            display: inline-flex;
            align-items: center;
            height: 36px;
            cursor: pointer;
        }
        #${buttonID}:hover {
            background-color: #9932CC; /* Lighter purple on hover */
        }
        /* YouTube menu purple styling */
        #masthead-container, 
        ytd-masthead, 
        tp-yt-app-header {
            background-color: #800080 !important;
        }
    `);

    function observeElement(selector) {
        return new Promise(resolve => {
            if (document.querySelector(selector)) {
                resolve(document.querySelector(selector));
            }
            const observer = new MutationObserver(() => {
                if (document.querySelector(selector)) {
                    resolve(document.querySelector(selector));
                    observer.disconnect();
                }
            });
            observer.observe(document.body, { childList: true, subtree: true });
        });
    }

    function addDownloadButton() {
        observeElement(buttonContainer).then(container => {
            if (!container || document.querySelector(`#${buttonID}`)) return;

            const downloadButton = document.createElement('a');
            downloadButton.id = buttonID;
            downloadButton.href = `${downloadBaseURL + encodeURIComponent(window.location)}`;
            downloadButton.target = '_blank';
            downloadButton.textContent = 'Download by Neura';

            container.appendChild(downloadButton);
        });
    }

    function updateButtonURL() {
        const button = document.querySelector(`#${buttonID}`);
        if (button) button.href = `${downloadBaseURL + encodeURIComponent(window.location)}`;
    }

    let buttonAdded = false;
    function checkAndAddButton() {
        if (window.location.pathname === '/watch' && !buttonAdded) {
            addDownloadButton();
            buttonAdded = true;
            setTimeout(updateButtonURL, 2000);
        }
    }

    window.addEventListener("yt-navigate-finish", () => {
        buttonAdded = false;
        checkAndAddButton();
    });

    checkAndAddButton();

    // Adblocker Code
    let ogVolume = 1, pbRate = 1, manualPause = false;

    document.addEventListener('keydown', (event) => {
        if (event.code === 'Space') {
            manualPause = true;
        }
    });

    document.addEventListener('play', () => {
        manualPause = false;
    });

    document.addEventListener('pause', () => {
        manualPause = true;
    });

    const manip = (actions) => {
        actions.forEach(({ selector, action, func }) => {
            let elements = document.querySelectorAll(selector);
            elements.forEach(element => {
                if(element!==null && element!==undefined){
                    if(element.style.display!=="none"){
                        if (action === 'remove') {
                            element.remove();
                        } else if (action === 'hide') {
                            element.style.display = "none";
                        } else if (action === 'click') {
                            element.click();
                        } else if (action === 'remove-run') {
                            element.remove();
                            eval(func);
                        }
                    }
                }
            });
        });
    };

    const playVid = () => {
        const video = document.querySelector("video");
        if(video!==null){
            if(!video.playing && !manualPause && video.currentTime<1){
                video.play();
            }
        }
    };

    Object.defineProperty(HTMLMediaElement.prototype, 'playing', {
        get: function(){
            return !!(this.currentTime > 0 && !this.paused && !this.ended && this.readyState > 2);
        }
    });

    const rev = 
        `ytd-rich-item-renderer:has(ytd-ad-slot-renderer),
        #player-ads,
        #panels:has(ytd-ads-engagement-panel-content-renderer),
        ytd-ad-slot-renderer,
        #masthead-ad,
        ytd-reel-video-renderer:has(ytd-ad-slot-renderer),
        tp-yt-paper-dialog:has(#feedback.ytd-enforcement-message-view-model),
        .yt-mealbar-promo-renderer {
            visibility: hidden;
            height: 0;
            margin: 0;
            padding: 0;
        }`;

    const styleSheet = document.createElement('style');
    styleSheet.type = 'text/css';
    styleSheet.innerText = rev;
    document.head.appendChild(styleSheet);

    setInterval(() => {
        try{

            manip([
                { selector: "tp-yt-paper-dialog:has(#feedback.ytd-enforcement-message-view-model)", action: 'remove-run', func: playVid()},
                { selector: ".ytp-ad-overlay-close-button", action: 'click' },
                { selector: ".style-scope.ytd-watch-next-secondary-results-renderer.sparkles-light-cta.GoogleActiveViewElement", action: 'hide' },
                { selector: ".ytp-ad-message-container", action: 'hide' },
                { selector: ".style-scope.ytd-companion-slot-renderer", action: 'remove' },
                { selector: "#masthead-ad", action: 'remove' },
                { selector: "ytd-ad-slot-renderer", action: 'remove' },
                { selector: "ytd-reel-shelf-renderer", action: 'remove' },
                { selector: "ytd-player-legacy-desktop-watch-ads-renderer", action: 'hide'},
                { selector: ".ytp-ad-player-overlay-layout", action: 'hide' },
                { selector: "ytd-reel-video-renderer:has(.ytd-ad-slot-renderer)", action: "remove"},
                { selector: "ytd-in-feed-ad-layout-renderer", action: 'remove' },
                { selector: "ytd-engagement-panel-section-list-renderer[target-id='engagement-panel-ads']", action: 'hide' },
                { selector: "ytd-popup-container:has(a[href='/premium'])", action: 'hide' },
                { selector: "yt-mealbar-promo-renderer", action: 'hide' }
            ]);

            let videoStream = document.querySelector("video"),
                skipAdButton = document.querySelector(".ytp-skip-ad-button,.ytp-ad-skip-button,.ytp-ad-skip-button-modern");

            if (videoStream) {
                let ad = document.querySelector(".video-ads.ytp-ad-module").firstChild || document.querySelector(".ytp-exp-ppp-update.ad-created.ad-showing.ad-interrupting");
                if (ad !== null) {
                    if(ad.childElementCount > 0){
                        videoStream.playbackRate = 16;
                        if (!isNaN(videoStream.duration) && isFinite(videoStream.duration) &&
                            !isNaN(videoStream.currentTime) && isFinite(videoStream.currentTime)) {
                            videoStream.currentTime += videoStream.duration;
                        }
                        videoStream.muted = true;
                    }else{
                        pbRate = videoStream.playbackRate;
                        videoStream.muted = false;
                    }
                }else{
                    pbRate = videoStream.playbackRate;
                    videoStream.muted = false;
                }
            }

            if (skipAdButton !== null) {
                skipAdButton.click();
                simulateClick(skipAdButton);
                simulateNativeTouch(skipAdButton);
            }

        }catch(e){}

    }, 10);

})();

QingJ © 2025

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