Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const CopyVideos = (function () {
- const htmlQueryToCheckDownloads = '.link a'
- function getElements (strQueryElements) {
- return document.querySelectorAll(strQueryElements)
- }
- function interruptAndShowMessage (strMessage = 'Pressione <ENTER> para continuar.') {
- alert(strMessage)
- console.info(strMessage)
- }
- function emitError (strFunctionName) {
- const message = `Cant execute ${strFunctionName}`
- interruptAndShowMessage(message)
- console.error(message)
- }
- function interruptAndGenerateTextToCopy (strTextToCopy, strTipText = 'Copie o texto abaixo.') {
- prompt(strTipText, strTextToCopy)
- console.info(strTipText, strTextToCopy)
- }
- function isUrlFromAVideo (strUrl) {
- return strUrl.href.indexOf('video') > -1
- }
- function withEachElement (listOfNodesElements, fnCallback) {
- for (let i = 0, qt = listOfNodesElements.length; i < qt; i++) {
- let elementNode = listOfNodesElements[i]
- fnCallback(elementNode)
- }
- }
- function setup () {
- function getPageTitle () {
- const pageTitle = document.title
- if (pageTitle) {
- return pageTitle
- }
- emitError ('getPageTitle')
- return ''
- }
- function generateFolderTitle () {
- interruptAndGenerateTextToCopy(getPageTitle(), 'Nome da pasta. Pressione <ENTER> para continuar.')
- interruptAndShowMessage()
- }
- function init () {
- generateFolderTitle()
- }
- init()
- }
- function startAllDownloads () {
- const links = getElements(htmlQueryToCheckDownloads)
- let totalDownloadVideos = 0
- if (!links.length) {
- emitError ('startAllDownloads')
- return false
- }
- withEachElement(links, element => {
- if (isUrlFromAVideo(element)) {
- totalDownloadVideos++
- element.click()
- }
- })
- interruptAndShowMessage(`Foram gerados ${totalDownloadVideos} downloads nesta página. Pressione <ENTER> para continuar.`)
- }
- function init () {
- setup()
- startAllDownloads()
- }
- return {
- start: init
- }
- })()
- CopyVideos.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement