Created
July 7, 2020 18:49
-
-
Save vsubhash/29e95f7b9cfee07fdaab11d4393a8efc to your computer and use it in GitHub Desktop.
Loads a lite version of Youtube and adds RSS, links to video pages, and downloads for video and subtitles. (Youtube stopped support for old versions of Firefox.) This script supersedes that of Youtube Annoyance Remover.
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 YoutubeLite | |
// @namespace com.vsubhash.js.YoutubeLite | |
// @description Loads a lite version of Youtube, adds video file downloads and subtitle links | |
// @include https://www.youtube.com/watch* | |
// @version 2020.07.07 | |
// @grant none | |
// ==/UserScript== | |
document.addEventListener("readystatechange", nukeYoutubeVideo, false); | |
var sVideoUrl=""; | |
try { | |
window.setTimeout(muteVideos, 1*1000); | |
window.setTimeout(muteVideos, 2*1000); | |
window.setTimeout(muteVideos, 4*1000); | |
window.setTimeout(muteVideos, 6*1000); | |
window.setTimeout(muteVideos, 8*1000); | |
window.setTimeout(muteVideos, 10*1000); | |
window.setTimeout(muteVideos, 12*1000); | |
} catch(e) { console.error("YTHR error: " + e); } | |
function onVideoPlay(aoEvent) { | |
console.log("YTHR: Video started playing"); | |
aoEvent.target.pause(); | |
console.log("YTHR: Video paused"); | |
} | |
function onVolumeChange(aoEvent) { | |
console.log("YTHR: Volume changed"); | |
aoEvent.target.volume = 0; | |
aoEvent.target.mute = true; | |
console.log("YTHR: Volume muted"); | |
} | |
function muteVideos() { | |
var oVideos = document.getElementsByTagName("video"); | |
console.log("YTHR: Found " + oVideos.length + " videos to mute."); | |
for (var i = 0; i < oVideos.length; i++) { | |
if (oVideos[i].id == "playa") { | |
continue; | |
} | |
oVideos[i].volume = 0; | |
oVideos[i].muted = true; | |
oVideos[i].pause(); | |
oVideos[i].addEventListener("playing", onVideoPlay, false); | |
oVideos[i].addEventListener("volumechange", onVolumeChange, false); | |
console.log("YTHR: Is video " + (i+1) + " muted " + oVideos[i].muted); | |
oVideos[i].removeAttribute("autoplay"); | |
oVideos[i].removeAttribute("loop"); | |
oVideos[i].removeAttribute("controls"); | |
oVideos[i].removeAttribute("controlsList"); | |
console.log("YTHR: Muting video " + (i+1)); | |
} | |
} | |
var oFrame, oDlList, oDlListItem, arSubtitles; | |
function nukeYoutubeVideo() { | |
if (document.getElementById("player")) { | |
var oVideos = document.getElementsByTagName("video"); | |
for (var i = oVideos.length-1; i >= 0; i--) { | |
if (oVideos[i].src && (sVideoUrl == "") && (oVideos[i].src.indexOf("pltype=adhost") == -1)) { | |
sVideoUrl = oVideos[i].src; | |
console.log("YTHR: Video URL found - " + sVideoUrl); | |
} | |
oVideos[i].muted = true; | |
oVideos[i].volume = 0; | |
oVideos[i].src = ""; | |
oVideos[i].load(); | |
oVideos[i].parentElement.removeChild(oVideos[i]); | |
} | |
} else { | |
console.log("YTHR: No youtube player to nuke"); | |
document.getElementsByTagName("body")[0].style="max-width: 4in; margin: 0 auto; overflow: scroll!important; "; | |
} | |
if (ytplayer.config.args.player_response) { | |
console.log("YTHR: Youtube player ready"); | |
if (document.getElementById("nooframe")) { | |
console.log("YTHR: Frame already exists"); | |
} else { | |
try { | |
console.log("YTHR: Frame not found"); | |
var playerResponse = JSON.parse(ytplayer.config.args.player_response); | |
if (playerResponse.captions) { | |
arSubtitles = playerResponse.captions.playerCaptionsTracklistRenderer.captionTracks; | |
} | |
var videoDetails = playerResponse.videoDetails; | |
var sTitle = videoDetails.title; | |
var sId = videoDetails.videoId; | |
var sDescription = videoDetails.shortDescription; | |
var sHTML = "<html><body><div id=\"nooframe\"><h1>" + videoDetails.title + "</h1>"; | |
var sBrites = "https://s.ytimg.com/yts/imgbin/www-hitchhiker-vflYQU35a.png"; | |
sHTML += "<p>RSS: <a title=\"RSS\" href=\"https://www.youtube.com/feeds/videos.xml?channel_id=" + videoDetails.channelId + "\"><img src=\"https://www.google.com/images/rss.png\" style=\"margin: 0 1em 0 0.1em; \" /></a> All videos <a title=\"All videos\" href=\"https://www.youtube.com/channel/" + videoDetails.channelId + "/videos\" style=\"width: 16px; height: 12px; background-image: url(" + sBrites + "); background-position: -64px -126px; border-style: none; margin: 0 1em 0 0.1em; display: inline-block; \" \/></a> Most popular videos: <a title=\"Most popular videos\" href=\"https://www.youtube.com/channel/" + videoDetails.channelId + "/videos?view=0&sort=p&flow=grid\" style=\"width: 16px; height: 12px; background-image: url(" + sBrites + "); background-position: -94px -476px; border-style: none; margin: 0 1em 0 0.1em; display: inline-block; \" \/></a> <b>« " + videoDetails.author + "</b></p>"; | |
if (sVideoUrl) { | |
sHTML += "<video src=\"" + sVideoUrl + "\" id=\"playa\" controls=\"controls\" style=\"width: 330px!important; height: 300px; display: block; margin: 1em auto; \" ></video>"; | |
} | |
sHTML += "<div id=\"playlist\" style=\"width: 400px; background-color: orange; border: 2px dashed navy; display: block; margin: 1em auto; padding: 0.2em; \" ></div>"; | |
sHTML += "<pre style=\"white-space: pre-wrap; max-width: 400px; \">" + videoDetails.shortDescription + "</pre>"; | |
sHTML += "</div></body></html>"; | |
document.getElementsByTagName("body")[0].innerHTML = sHTML; | |
console.log("YTHR: New frame added"); | |
if (videoDetails.thumbnail.thumbnails) { | |
console.log("YTHR: Number of formats: " + videoDetails.thumbnail.thumbnails.length); | |
document.getElementById("playlist").innerHTML = "<img style=\"float: right; margin: auto 0 1em 1em; \" src=\"" + videoDetails.thumbnail.thumbnails[0].url + "\" />"; | |
} | |
oDlList = document.createElement("ul"); | |
oDlList.setAttribute("style", "padding-left: 1em;"); | |
document.getElementById("playlist").appendChild(oDlList); | |
if (sVideoUrl) { | |
oDlListItem = document.createElement("li"); | |
oDlListItem.innerHTML = "<b>DownThemAll (*text*.mp4):<br /><a href=\"" + sVideoUrl + "\">" + sTitle + "</a></b>" | |
oDlList.appendChild(oDlListItem); | |
} | |
var arFormats = playerResponse.streamingData.formats; | |
for (i = 0; i < arFormats.length; i++) { | |
oDlListItem = document.createElement("li"); | |
var sFormat = arFormats[i].mimeType.split(';')[0]; | |
if (arFormats[i].mimeType.split(';')[0] == "video/mp4") { | |
sFormat = "M"; | |
} else if (arFormats[i].mimeType.split(';')[0] == "video/webm") { | |
sFormat = "W"; | |
} | |
console.log("YTHR: Format " + arFormats[i].quality + " - " + arFormats[i].qualityLabel + " - " + arFormats[i].mimeType.split(';')[0]); | |
oDlListItem.innerHTML = "<a title=\"" + arFormats[i].mimeType.replace(/\"/g,"") + "\" href=\"" + arFormats[i].url + "\">" + videoDetails.title + " - " + arFormats[i].qualityLabel + " " + sFormat + "</a>"; | |
oDlList.appendChild(oDlListItem); | |
} | |
if (arSubtitles) { | |
console.log("YTHR: Subtitles found: " + arSubtitles.length); | |
oDlListItem = document.createElement("li"); | |
oDlListItem.innerHTML = "<b>Subtitles:</b><br />"; | |
for (var i = 0; i < arSubtitles.length; i++) { | |
var oSubtitleTrack = arSubtitles[i]; | |
var sSubtitleUrl = oSubtitleTrack.baseUrl; | |
var sSubtitleLanguage = oSubtitleTrack.name.simpleText; | |
console.log("YTHR: Subtitle in :" + sSubtitleLanguage); | |
oDlListItem.innerHTML += ("<a href=\"" + sSubtitleUrl + "\" target=\"_blank\">" + sSubtitleLanguage + "</a>"); | |
if (i < (arSubtitles.length-1)) { | |
oDlListItem.innerHTML += ", "; | |
} | |
//https://downsub.com/?url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DMtDHqS9UHK8 | |
} | |
oDlListItem.innerHTML += (", <a href=\"https://downsub.com/?url=" + document.location + "\" target=\"_blank\">DownSub.com</a>"); | |
oDlList.appendChild(oDlListItem); | |
} else { | |
console.log("YTHR: Subtitles found: 0"); | |
} | |
oDlListItem = document.createElement("li"); | |
oDlListItem.innerHTML = "<b>Alternative:</b><br /><a href=\"https://www.hooktube.com/watch?v=" + sId + "\">Load in Hooktube.com</a>"; | |
oDlList.appendChild(oDlListItem); | |
document.getElementsByTagName("body")[0].innerHTML += ("<p>Published on: " + playerResponse.microformat.playerMicroformatRenderer.publishDate + "</p>"); | |
document.getElementsByTagName("body")[0].style="max-width: 4in; margin: 0 auto; overflow: scroll!important; "; | |
document.querySelectorAll("html > head > title")[0].innerHTML = videoDetails.title + " - YoutubeLite by V. Subhash"; | |
} catch(e) { console.error("YTHR Error: " + e); } | |
} | |
} else { | |
console.log("YTHR: Youtube player not ready"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment