Last active
April 7, 2021 03:10
-
-
Save pedropedruzzi/f25a010f8a787352575d8f312433979b to your computer and use it in GitHub Desktop.
Greasemonkey script que permite download de legendas a partir dos resultados de busca do site legendas.tv. Instruções: 1. Instale o Greasemonkey (Firefox) ou Tampermonkey (Chrome ou Firefox). 2. Clique em https://gist.githubusercontent.com/pedropedruzzi/f25a010f8a787352575d8f312433979b/raw/download-na-busca-do-legendas-tv.user.js
This file contains hidden or 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 Download na busca do legendas.tv | |
// @namespace http://tampermonkey.net/ | |
// @version 0.4 | |
// @description Permite download de legendas a partir dos resultados de busca do site legendas.tv | |
// @author Pedro Pedruzzi | |
// @match http://legendas.tv/busca/* | |
// @match https://legendas.tv/busca/* | |
// @grant none | |
// @downloadURL https://gist.githubusercontent.com/pedropedruzzi/f25a010f8a787352575d8f312433979b/raw/download-na-busca-do-legendas-tv.user.js | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
window.addEventListener('load', tryInstallObserver, false); | |
function tryInstallObserver() { | |
console.debug('tryInstallObserver()'); | |
if (document.querySelector("a[href^='/login']")) { | |
console.debug("download won't work until the user is signed in. aborting"); | |
return; | |
} | |
const targetElement = document.getElementById('resultado_busca'); | |
if (targetElement == null) { | |
console.debug('no #resultado_busca element yet'); | |
window.requestAnimationFrame(tryInstallObserver); | |
return; | |
} | |
console.debug('tryInstallObserver: ready to install observer'); | |
const observer = new MutationObserver(function(mutationsList, observer) { | |
for (let mutation of mutationsList) { | |
if (mutation.addedNodes.length > 0) { | |
console.debug("mutation detected"); | |
addDownloadLinks(); | |
} | |
} | |
}); | |
observer.observe(targetElement, { childList: true }); | |
addDownloadLinks(); // ensure initial set of links are displayed | |
} | |
function addDownloadLinks() { | |
var links = document.querySelectorAll("a[href^='/download/']"); | |
console.debug('found links:', links.length); | |
for (var i = 0; i < links.length; i++) { | |
var link = links[i]; | |
if (link.parentNode.querySelector("a.seta") == null) { // do nothing when there's already a download link there | |
var downloadId = link.getAttribute('href').match(/\/download\/([^\/]*)\//)[1]; | |
link.parentNode.appendChild(createDownloadLink(downloadId)); | |
} | |
} | |
return links.length; | |
} | |
function createDownloadLink(downloadId) { | |
var el = document.createElement("a"); | |
el.setAttribute('href', '/downloadarquivo/' + downloadId); | |
el.setAttribute('title', 'Baixar esta legenda agora'); | |
el.setAttribute('style', 'float:right; position:static'); | |
el.setAttribute('class', 'seta'); | |
// old text style | |
//el.appendChild(document.createTextNode("download")); | |
//el.setAttribute('style', 'float:right; background: #4885c4; padding: 0px 12px 0px; color: white; font-weight: normal; font-size: 13px'); | |
return el; | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Perfeito, muito obrigado :)
Seu userscript é um dos melhores que já vi, economiza muitíssimo do tempo ao baixar legendas