Last active
May 21, 2019 11:15
-
-
Save RafalJDev/d4c50e94f835074b13325a7c71515b3e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Youtube script - without sleep | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author You | |
// @match https://www.youtube.com/* | |
// @run-at document-end | |
// @grant none | |
// ==/UserScript== | |
var expandTitlesInterval | |
var handleSaveOrZapiszButtonInterval | |
var handlePopupAppearingInterval | |
(async function () { | |
expandTitlesInterval = setInterval(expandTitles, 4000) | |
handleSaveOrZapiszButtonInterval = setInterval(handleSaveOrZapiszButton, 120); | |
})(); | |
function expandTitles() { | |
var elements = document.querySelectorAll('#video-title.yt-simple-endpoint.style-scope.ytd-grid-video-renderer'); | |
elements.forEach(element => { | |
element.style.maxHeight = '7em'; | |
element.style.webkitLineClamp = '7' | |
}) | |
} | |
function handleSaveOrZapiszButton() { | |
console.log("handleSaveOrZapiszButton") | |
try { | |
var saveButton = document.getElementsByClassName('style-scope ytd-button-renderer') | |
if (saveButton[8].innerText === 'ZAPISZ') { | |
clearInterval(handleSaveOrZapiszButtonInterval) | |
click('style-scope ytd-button-renderer', 8) | |
handlePopupAppearingInterval = setInterval(handlePopupAppearing, 120) | |
} else if (saveButton[10].innerText === 'SAVE') { | |
clearInterval(handleSaveOrZapiszButtonInterval) | |
click('style-scope ytd-button-renderer', 10) | |
handlePopupAppearingInterval = setInterval(handlePopupAppearing, 120) | |
} else { | |
console.error("Cannot find save button") | |
} | |
} catch (e) { | |
console.log("handleSaveOrZapiszButton_CATCH") | |
} | |
} | |
function handlePopupAppearing() { | |
console.log("handlePopupAppearing") | |
try { | |
var popupInnerText = document.getElementsByClassName('checkbox-height style-scope ytd-playlist-add-to-option-renderer')[0].innerText | |
var hasPopupAppeared = popupInnerText === 'Watch later' || popupInnerText === 'Do obejrzenia' | |
if (hasPopupAppeared) { | |
console.log("HERE1") | |
clearInterval(handlePopupAppearingInterval) | |
console.log("HERE2") | |
handleWatchLaterCheckedButton() | |
} | |
} catch (e) { | |
console.log("handlePopupAppearing_CATCH") | |
} | |
} | |
function handleWatchLaterCheckedButton() { | |
console.log('handleWatchLaterCheckedButton') | |
var checkedAmount = document.getElementsByClassName('checked').length | |
console.log("Checked amount:" + checkedAmount); | |
if (checkedAmount == 0) { | |
click('style-scope ytd-add-to-playlist-renderer', 3) | |
} | |
} | |
function click(className, elementIndex) { | |
console.log("click_begin, className:" + className + " ,elementIndex:" + elementIndex) | |
var evt = document.createEvent("MouseEvents"); | |
evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); | |
document.getElementsByClassName(className)[elementIndex].dispatchEvent(evt); | |
console.log("click_end") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment