Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. const CopyVideos = (function () {
  2.  
  3. const htmlQueryToCheckDownloads = '.link a'
  4.  
  5. function getElements (strQueryElements) {
  6. return document.querySelectorAll(strQueryElements)
  7. }
  8.  
  9. function interruptAndShowMessage (strMessage = 'Pressione <ENTER> para continuar.') {
  10. alert(strMessage)
  11. console.info(strMessage)
  12. }
  13.  
  14. function emitError (strFunctionName) {
  15. const message = `Cant execute ${strFunctionName}`
  16. interruptAndShowMessage(message)
  17. console.error(message)
  18. }
  19.  
  20. function interruptAndGenerateTextToCopy (strTextToCopy, strTipText = 'Copie o texto abaixo.') {
  21. prompt(strTipText, strTextToCopy)
  22. console.info(strTipText, strTextToCopy)
  23. }
  24.  
  25. function isUrlFromAVideo (strUrl) {
  26. return strUrl.href.indexOf('video') > -1
  27. }
  28.  
  29. function withEachElement (listOfNodesElements, fnCallback) {
  30. for (let i = 0, qt = listOfNodesElements.length; i < qt; i++) {
  31. let elementNode = listOfNodesElements[i]
  32. fnCallback(elementNode)
  33. }
  34. }
  35.  
  36. function setup () {
  37.  
  38. function getPageTitle () {
  39. const pageTitle = document.title
  40. if (pageTitle) {
  41. return pageTitle
  42. }
  43. emitError ('getPageTitle')
  44. return ''
  45. }
  46.  
  47. function generateFolderTitle () {
  48. interruptAndGenerateTextToCopy(getPageTitle(), 'Nome da pasta. Pressione <ENTER> para continuar.')
  49. interruptAndShowMessage()
  50. }
  51.  
  52. function init () {
  53. generateFolderTitle()
  54. }
  55.  
  56. init()
  57.  
  58. }
  59.  
  60. function startAllDownloads () {
  61.  
  62. const links = getElements(htmlQueryToCheckDownloads)
  63. let totalDownloadVideos = 0
  64.  
  65. if (!links.length) {
  66. emitError ('startAllDownloads')
  67. return false
  68. }
  69.  
  70. withEachElement(links, element => {
  71. if (isUrlFromAVideo(element)) {
  72. totalDownloadVideos++
  73. element.click()
  74. }
  75. })
  76.  
  77. interruptAndShowMessage(`Foram gerados ${totalDownloadVideos} downloads nesta página. Pressione <ENTER> para continuar.`)
  78.  
  79. }
  80.  
  81. function init () {
  82. setup()
  83. startAllDownloads()
  84. }
  85.  
  86. return {
  87. start: init
  88. }
  89.  
  90. })()
  91.  
  92.  
  93. CopyVideos.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement