Created
April 10, 2022 23:32
-
-
Save melchisedech333/defbe757587061945ae6af27e31b01b6 to your computer and use it in GitHub Desktop.
Download video subtitles
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
// Configs... | |
// YouTube video list. | |
var urls = ` | |
https://www.youtube.com/watch?v=ev9zrt__lec | |
`; | |
// Process... | |
$ = null; | |
(function() { | |
// Load the script | |
const script = document.createElement("script"); | |
script.src = 'https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js'; | |
script.type = 'text/javascript'; | |
script.addEventListener('load', () => { | |
console.log(`jQuery ${$.fn.jquery} has been loaded successfully!`); | |
// use jQuery below | |
$ = $; | |
entry(); | |
}); | |
document.head.appendChild(script); | |
})(); | |
var searchSubtitleInterval = null; | |
var enableRedirectInterval = null; | |
var enableRedirect = false; | |
function entry () | |
{ | |
if (window.location.href.toString().indexOf('checksub.com') == -1) | |
return false; | |
// Startup control. | |
var currentUrl = getUrlParameter('videoUrl'); | |
if (!currentUrl) { | |
urls = urls.trim(); | |
urls = urls.split("\n"); | |
window.location.href = 'https://download.checksub.com/download?videoUrl='+ urls[0]; | |
} | |
// Download control. | |
$(document).ready(function(){ | |
console.log("Verbum started!"); | |
// Search subtitle element. | |
searchSubtitleInterval = setInterval(function(){ | |
var els = $('.content'); | |
for (var a=0; a<els.length; a++) { | |
var item = els[a]; | |
var el = $(item).find('.rFlag'); | |
if (el) { | |
if (el[0]) { | |
if (el[0].innerHTML.toString().indexOf('English') != -1) { | |
var elsub = $(item).find('.rItem'); | |
var subitem = elsub[1].innerHTML.toString(); | |
if (subitem.trim().length > 0) { | |
console.log('Subtitle found!'); | |
// console.log(el[0]); | |
// console.log(elsub[1]); | |
$(elsub[1]).find('button')[0].click(); | |
setTimeout(function(){ | |
enableRedirect = true; | |
}, 3333); | |
clearInterval(searchSubtitleInterval); | |
break; | |
} | |
} | |
} | |
} | |
} | |
}, 1000); | |
// Redirect control. | |
enableRedirectInterval = setInterval(function(){ | |
if (enableRedirect == true) { | |
enableRedirect = false; | |
console.log("Redirect..."); | |
// Capture current URL. | |
var currentUrl = getUrlParameter('videoUrl'); | |
currentUrl = decodeURI(currentUrl); | |
console.log('Current URL: '+ currentUrl); | |
// Check current URL exists in configs... | |
urls = urls.trim(); | |
urls = urls.split("\n"); | |
var redirectUrl = ''; | |
for (var a=0; a<urls.length; a++) { | |
if (currentUrl == urls[a]) { | |
if (urls[a+1]) | |
redirectUrl = urls[a+1]; | |
break; | |
} | |
} | |
// Redirect. | |
if (redirectUrl.length > 0) { | |
console.log('Redirect URL: '+ redirectUrl); | |
window.location.href = 'https://download.checksub.com/download?videoUrl='+ redirectUrl; | |
} else { | |
console.log("\n\n\nFinished!\n\n\nLove Jesus!\n\n\n"); | |
} | |
clearInterval(enableRedirectInterval); | |
} | |
}, 1000); | |
}); | |
} | |
var getUrlParameter = function getUrlParameter(sParam) { | |
var url = window.location.href.toString().trim(); | |
url = decodeURI(url); | |
url = url.split('videoUrl='); | |
if (!url[1]) | |
return null; | |
url = url[1].toString().trim(); | |
return url; | |
}; | |
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
var script = document.createElement('script'); | |
script.setAttribute('type', 'text/javascript'); | |
script.src = chrome.extension.getURL('injected.js'); | |
setTimeout(function() { | |
document.head.appendChild(script); | |
}); |
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
{ | |
"manifest_version": 2, | |
"name": "Download subtitle", | |
"short_name": "DownSub", | |
"version": "1.0.0", | |
"content_scripts": [{ | |
"matches": [ | |
"*://*/*" | |
], | |
"js": [ "injector.js" ], | |
"run_at": "document_start", | |
"persistent": false | |
}], | |
"web_accessible_resources": [ | |
"injected.js" | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment