Untitled

mail@pastecode.io avatar
unknown
javascript
3 years ago
2.4 kB
2
Indexable
Never
function getSearchParameters() {
    var prmstr = window.location.search.substr(1);
    return prmstr != null && prmstr != "" ? transformToAssocArray(prmstr) : {};
}

function transformToAssocArray(prmstr) {
    var params = {};
    var prmarr = prmstr.split("&");
    for (var i = 0; i < prmarr.length; i++) {
        var tmparr = prmarr[i].split("=");
        params[tmparr[0]] = tmparr[1];
    }
    return params;
}


function getCupom() {

    cupom = document.querySelector('.ytp-cards-teaser-label').textContent.trim();

    if (cupom != "") {
        var mp3_url = 'https://media.geeksforgeeks.org/wp-content/uploads/20190531135120/beep.mp3';
        (new Audio(mp3_url)).play()
        console.log(cupom);
        document.getElementsByClassName("video-stream html5-main-video")[0].playbackRate = 1;
        return;
    } else {
        setTimeout(getCupom, 100);
    }
}

function skipVideos() {
    tempo = 1000;

    params = getSearchParameters();

    cards = document.querySelectorAll('.iv-card > .iv-click-target');

    if (cards.length > 0) {
        urlRoot = window.location.href;
        console.log(`<a href="${urlRoot}">ROOT ${document.title}</a>`)
        for (let i = 0; i < cards.length; i++) {
            cardTarget = cards[i].href;
            cardContent = cards[i].children[1].textContent;
            console.log(`<a href="${cardTarget}">${cardContent}</a>`);
            console.log("</br>")

            if (cardContent.match(/cupom/gi) || cardTarget.search("eNOqEp48CNA") != -1) {
                var mp3_url = 'https://media.geeksforgeeks.org/wp-content/uploads/20190531135120/beep.mp3';
                (new Audio(mp3_url)).play()

                document.getElementsByClassName("video-stream html5-main-video")[0].playbackRate = 10;

                console.log("######################");
                console.log("Achou vídeo, tentando recuperar cupom");
                console.log("######################");
                getCupom();
                return;
            }
        }
        document.querySelector('.ytp-next-button').click();
    } else {
        document.querySelector('.ytp-next-button').click();
    }

    if (params["list"] == "UUcmiKisvBXwAZF63qansofQ") {
        setTimeout(skipVideos, tempo);
    } else {
        return;
    }
}

skipVideos();