fixed some stuff with thumbnail loading

This commit is contained in:
Maxim Stewart 2018-06-03 22:53:28 -05:00
parent 2d4710070b
commit 47349f2246
3 changed files with 220 additions and 218 deletions

View File

@ -12,5 +12,5 @@ Better Youtube + works to improve the Youtube experience by providing quick acce
# Download # Download
https://addons.mozilla.org/en-US/firefox/addon/better-youtube-plus/ https://addons.mozilla.org/en-US/firefox/addon/better-youtube-plus/
# Version: 1.2.5 # Version: 1.2.6
Added quick access to the Youtube video slug. Added quick access to the Youtube video slug.

View File

@ -1,7 +1,7 @@
{ {
"manifest_version": 2, "manifest_version": 2,
"name": "Better Youtube +", "name": "Better Youtube +",
"version": "1.2.5", "version": "1.2.6",
"description": "Enhancements for Youtube to have a better experience.", "description": "Enhancements for Youtube to have a better experience.",
"applications": { "applications": {

View File

@ -1,246 +1,248 @@
// Declare variables function betterYoutubePlus() {
var slugInputTag, ytThumbImgMenu, ytEnhancerMenu; // Menu systems
var ytThumbnailBttn, ytMaxDefaultImg, ytHqDefaultImg, // Buttons & Images
ytLoopBttn, ytFloatBttn, ytAMaxDefaultImg, ytAHqDefaultImg;
var mastHead, mainContentArea, playerWindow; // Youtube Player container // Declare variables
var video, containerOfPlyrWndow, poppedContainer; // Video accessor var slugInputTag, ytThumbImgMenu, ytEnhancerMenu; // Menu systems
var vdoPlyrAtts; // Player attributes var ytThumbnailBttn, ytMaxDefaultImg, ytHqDefaultImg, // Buttons & Images
var part, videoSlug, temp; // Image part ytLoopBttn, ytFloatBttn, ytAMaxDefaultImg, ytAHqDefaultImg;
var count = 0;
function preSetupProc() { var mastHead, mainContentArea, playerWindow; // Youtube Player container
console.log("Weee"); var video, containerOfPlyrWndow, poppedContainer; // Video accessor
video = document.getElementsByTagName("video")[0]; // Video Controler var vdoPlyrAtts; // Player attributes
slugInputTag = document.createElement("INPUT"); var part, videoSlug, temp; // Image part
slugInputTag.id = "slugCopyZone"; var count = 0;
slugInputTag.type = "text";
if (!document.getElementById("slugCopyZone")) { function preSetupProc() {
document.body.appendChild(slugInputTag); video = document.getElementsByTagName("video")[0]; // Video Controler
} else { slugInputTag = document.createElement("INPUT");
slugInputTag = document.getElementById("slugCopyZone"); slugInputTag.id = "slugCopyZone";
slugInputTag.type = "text";
if (!document.getElementById("slugCopyZone")) {
document.body.appendChild(slugInputTag);
} else {
slugInputTag = document.getElementById("slugCopyZone");
}
vdoPlyrAtts = video.baseURI; // Used for setting up thumbnails
slugInputTag.value = vdoPlyrAtts.slice(32, 32+11);
} }
vdoPlyrAtts = video.baseURI; // Used for setting up thumbnails function setupProc() {
vdoPlyrAtts = vdoPlyrAtts.slice(32, 32+11); poppedContainer = document.createElement("DIV");
slugInputTag.value = vdoPlyrAtts; ytThumbImgMenu = document.createElement("DIV");
ytEnhancerMenu = document.createElement("DIV");
ytThumbnailBttn = document.createElement("IMG");
ytLoopBttn = document.createElement("IMG");
ytFloatBttn = document.createElement("IMG");
ytMaxDefaultImg = document.createElement("IMG");
ytHqDefaultImg = document.createElement("IMG");
ytMqDefaultImg = document.createElement("IMG");
ytSdDefaultImg = document.createElement("IMG");
ytAMaxDefaultImg = document.createElement("A");
ytAHqDefaultImg = document.createElement("A");
ytAMedDefaultImg = document.createElement("A");
ytASdDefaultImg = document.createElement("A");
// Get nodes for page work
mastHead = document.getElementById("masthead-container")
.getElementsByClassName("style-scope ytd-masthead")[3]; // Search bar area
mainContentArea = document.getElementsByTagName("ytd-watch")[0]; // BT control insert area and bg color setup
} containerOfPlyrWndow = document.getElementById("player-container"); // Container of actual player - Used for floating window
part = "https://img.youtube.com/vi/";
function setupProc() { // Append to nodes as required
poppedContainer = document.createElement("DIV"); ytThumbnailBttn.title = "Video Thumbnails...";
ytThumbImgMenu = document.createElement("DIV"); ytLoopBttn.title = "Start Loop...";
ytEnhancerMenu = document.createElement("DIV"); ytFloatBttn.title = "Float Video Container";
ytThumbnailBttn = document.createElement("IMG");
ytLoopBttn = document.createElement("IMG");
ytFloatBttn = document.createElement("IMG");
ytMaxDefaultImg = document.createElement("IMG");
ytHqDefaultImg = document.createElement("IMG");
ytMqDefaultImg = document.createElement("IMG");
ytSdDefaultImg = document.createElement("IMG");
ytAMaxDefaultImg = document.createElement("A");
ytAHqDefaultImg = document.createElement("A");
ytAMedDefaultImg = document.createElement("A");
ytASdDefaultImg = document.createElement("A");
// Get nodes for page work ytEnhancerMenu.appendChild(ytThumbnailBttn);
mastHead = document.getElementById("masthead-container") ytEnhancerMenu.appendChild(ytLoopBttn);
.getElementsByClassName("style-scope ytd-masthead")[3]; // Search bar area ytEnhancerMenu.appendChild(ytFloatBttn);
mainContentArea = document.getElementsByTagName("ytd-watch")[0]; // BT control insert area and bg color setup
containerOfPlyrWndow = document.getElementById("top").children[0]; // Container of actual player - Used for floating window // Insert
part = "https://img.youtube.com/vi/"; document.body.appendChild(poppedContainer);
document.body.appendChild(ytThumbImgMenu);
document.body.appendChild(ytEnhancerMenu);
ytAMaxDefaultImg.appendChild(ytMaxDefaultImg);
ytAHqDefaultImg.appendChild(ytHqDefaultImg);
ytAMedDefaultImg.appendChild(ytMqDefaultImg);
ytASdDefaultImg.appendChild(ytSdDefaultImg);
ytThumbImgMenu.appendChild(ytAMaxDefaultImg);
ytThumbImgMenu.appendChild(ytAHqDefaultImg);
ytThumbImgMenu.appendChild(ytAMedDefaultImg);
ytThumbImgMenu.appendChild(ytASdDefaultImg);
// Append to nodes as required // Set onclick actions
ytThumbnailBttn.title = "Video Thumbnails..."; ytThumbnailBttn.addEventListener("click", showThumbImageVew);
ytLoopBttn.title = "Start Loop..."; ytLoopBttn.addEventListener("click", setLoop);
ytFloatBttn.title = "Float Video Container"; ytFloatBttn.addEventListener("click", toggleFloat);
video.addEventListener("wheel", manageVolume);
ytEnhancerMenu.appendChild(ytThumbnailBttn); // Dragable window for floating video
ytEnhancerMenu.appendChild(ytLoopBttn); dragVideo(poppedContainer);
ytEnhancerMenu.appendChild(ytFloatBttn);
// Insert
document.body.appendChild(poppedContainer);
document.body.appendChild(ytThumbImgMenu);
document.body.appendChild(ytEnhancerMenu);
ytAMaxDefaultImg.appendChild(ytMaxDefaultImg);
ytAHqDefaultImg.appendChild(ytHqDefaultImg);
ytAMedDefaultImg.appendChild(ytMqDefaultImg);
ytASdDefaultImg.appendChild(ytSdDefaultImg);
ytThumbImgMenu.appendChild(ytAMaxDefaultImg);
ytThumbImgMenu.appendChild(ytAHqDefaultImg);
ytThumbImgMenu.appendChild(ytAMedDefaultImg);
ytThumbImgMenu.appendChild(ytASdDefaultImg);
// Set onclick actions
ytThumbnailBttn.addEventListener("click", showThumbImageVew);
ytLoopBttn.addEventListener("click", setLoop);
ytFloatBttn.addEventListener("click", toggleFloat);
video.addEventListener("wheel", manageVolume);
// Dragable window for floating video
dragVideo(poppedContainer);
ytThumbnailBttn.src = browser.extension.getURL("/icons/thumbnailOff.png");
ytLoopBttn.src = browser.extension.getURL("/icons/loopFalse.png");
ytFloatBttn.src = browser.extension.getURL("/icons/floatPlayer.png");
// Set trget of Thumbnails of video
ytAMaxDefaultImg.target = "_blank";
ytAHqDefaultImg.target = "_blank";
ytAMedDefaultImg.target = "_blank";
ytASdDefaultImg.target = "_blank";
// Theming & Apply Styles
ytThumbImgMenu.className = "ytThumbMenuStyle";
ytMaxDefaultImg.className = "thumbImageStyle";
ytHqDefaultImg.className = "thumbImageStyle";
ytMqDefaultImg.className = "thumbImageStyle";
ytSdDefaultImg.className = "thumbImageStyle";
ytEnhancerMenu.className = "ytMenuStyle";
ytThumbnailBttn.className = "imageStyle";
ytLoopBttn.className = "imageStyle";
ytFloatBttn.className = "imageStyle";
ytEnhancerMenu.id = "enhancerMenuIDRef";
poppedContainer.id = "draggable";
poppedContainer.style.display = "none";
mastHead.style = "background: #868686;";
mainContentArea.style = "background: #868686;";
}
// Functions
function showThumbImageVew(e) {
videoSlug = vdoPlyrAtts;
if (ytThumbImgMenu.style.display == "block") {
ytThumbImgMenu.style.display = "none";
ytThumbnailBttn.src = browser.extension.getURL("/icons/thumbnailOff.png"); ytThumbnailBttn.src = browser.extension.getURL("/icons/thumbnailOff.png");
} else { ytLoopBttn.src = browser.extension.getURL("/icons/loopFalse.png");
ytAMaxDefaultImg.href = part + videoSlug + "/maxresdefault.jpg"; ytFloatBttn.src = browser.extension.getURL("/icons/floatPlayer.png");
ytAHqDefaultImg.href = part + videoSlug + "/hqdefault.jpg";
ytAMedDefaultImg.href = part + videoSlug + "/mqdefault.jpg";
ytASdDefaultImg.href = part + videoSlug + "/sddefault.jpg";
ytMaxDefaultImg.src = part + videoSlug + "/maxresdefault.jpg";
ytHqDefaultImg.src = part + videoSlug + "/hqdefault.jpg";
ytMqDefaultImg.src = part + videoSlug + "/mqdefault.jpg";
ytSdDefaultImg.src = part + videoSlug + "/sddefault.jpg";
ytMaxDefaultImg.title = "Max Resolution Default";
ytHqDefaultImg.title = "High Quality Default";
ytMqDefaultImg.title = "Medium Quality Default";
ytSdDefaultImg.title = "Standard Quality Default";
ytMaxDefaultImg.onerror = function() { ytMaxDefaultImg.src = "/icons/missing.png"; } // Set trget of Thumbnails of video
ytHqDefaultImg.onerror = function() { ytHqDefaultImg.src = "/icons/missing.png"; } ytAMaxDefaultImg.target = "_blank";
ytAMedDefaultImg.onerror = function() { ytAMedDefaultImg.src = "/icons/missing.png"; } ytAHqDefaultImg.target = "_blank";
ytASdDefaultImg.onerror = function() { ytASdDefaultImg.src = "/icons/missing.png"; } ytAMedDefaultImg.target = "_blank";
ytASdDefaultImg.target = "_blank";
ytThumbnailBttn.src = browser.extension.getURL("/icons/thumbnailOn.png"); // Theming & Apply Styles
ytThumbImgMenu.style.display = "block"; ytThumbImgMenu.className = "ytThumbMenuStyle";
} ytMaxDefaultImg.className = "thumbImageStyle";
return; ytHqDefaultImg.className = "thumbImageStyle";
} ytMqDefaultImg.className = "thumbImageStyle";
ytSdDefaultImg.className = "thumbImageStyle";
function setLoop(e) { ytEnhancerMenu.className = "ytMenuStyle";
if (video.loop == false) { ytThumbnailBttn.className = "imageStyle";
video.loop = true; ytLoopBttn.className = "imageStyle";
ytLoopBttn.title = "Stop Loop..."; ytFloatBttn.className = "imageStyle";
ytLoopBttn.src = browser.extension.getURL("/icons/loopTrue.png"); ytEnhancerMenu.id = "enhancerMenuIDRef";
} else { poppedContainer.id = "draggable";
ytLoopBttn.title = "Start Loop...";
video.loop = false;
ytLoopBttn.src = browser.extension.getURL("/icons/loopFalse.png");
}
return;
}
function toggleFloat() {
playerWindow = document.getElementById("player-container"); // Actual player
if(poppedContainer.style.display == "none"){
poppedContainer.appendChild(playerWindow);
poppedContainer.style.display = "block";
} else {
containerOfPlyrWndow.insertBefore(playerWindow, containerOfPlyrWndow.firstChild);
poppedContainer.style.display = "none"; poppedContainer.style.display = "none";
} mastHead.style = "background: #868686;";
} mainContentArea.style = "background: #868686;";
function manageVolume(e) {
var delta;
e.preventDefault(); // Keep page from scrolling while in video area
// Detect scroll direction
if (e.wheelDelta) delta = e.wheelDelta; else delta = -1 * e.deltaY;
// Vol UP || Vol DOWN
if (delta > 0) video.volume += 0.05; else if (delta < 0) video.volume -= 0.05;
}
function dragVideo(elmnt) {
var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
elmnt.onmousedown = dragMouseDown;
function dragMouseDown(e) {
e = e || window.event;
pauseEvent(e);
// get the mouse cursor position at startup:
pos3 = e.clientX;
pos4 = e.clientY;
document.onmouseup = closeDragElement;
// call a function whenever the cursor moves:
document.onmousemove = elementDrag;
} }
function elementDrag(e) { // Functions
e = e || window.event; function showThumbImageVew(e) {
pauseEvent(e); videoSlug = video.baseURI.slice(32, 32+11); // Used for setting up thumbnails
// calculate the new cursor position:
pos1 = pos3 - e.clientX; if (ytThumbImgMenu.style.display == "block") {
pos2 = pos4 - e.clientY; ytThumbImgMenu.style.display = "none";
pos3 = e.clientX; ytThumbnailBttn.src = browser.extension.getURL("/icons/thumbnailOff.png");
pos4 = e.clientY; } else {
// set the element's new position: ytAMaxDefaultImg.href = part + videoSlug + "/maxresdefault.jpg";
elmnt.style.top = (elmnt.offsetTop - pos2) + "px"; ytAHqDefaultImg.href = part + videoSlug + "/hqdefault.jpg";
elmnt.style.left = (elmnt.offsetLeft - pos1) + "px"; ytAMedDefaultImg.href = part + videoSlug + "/mqdefault.jpg";
ytASdDefaultImg.href = part + videoSlug + "/sddefault.jpg";
ytMaxDefaultImg.src = part + videoSlug + "/maxresdefault.jpg";
ytHqDefaultImg.src = part + videoSlug + "/hqdefault.jpg";
ytMqDefaultImg.src = part + videoSlug + "/mqdefault.jpg";
ytSdDefaultImg.src = part + videoSlug + "/sddefault.jpg";
ytMaxDefaultImg.title = "Max Resolution Default";
ytHqDefaultImg.title = "High Quality Default";
ytMqDefaultImg.title = "Medium Quality Default";
ytSdDefaultImg.title = "Standard Quality Default";
ytMaxDefaultImg.onerror = function() { ytMaxDefaultImg.src = "/icons/missing.png"; }
ytHqDefaultImg.onerror = function() { ytHqDefaultImg.src = "/icons/missing.png"; }
ytAMedDefaultImg.onerror = function() { ytAMedDefaultImg.src = "/icons/missing.png"; }
ytASdDefaultImg.onerror = function() { ytASdDefaultImg.src = "/icons/missing.png"; }
ytThumbnailBttn.src = browser.extension.getURL("/icons/thumbnailOn.png");
ytThumbImgMenu.style.display = "block";
}
return;
} }
function closeDragElement(e) { function setLoop(e) {
// stop moving when mouse button is released: if (video.loop == false) {
document.onmouseup = null; video.loop = true;
document.onmousemove = null; ytLoopBttn.title = "Stop Loop...";
ytLoopBttn.src = browser.extension.getURL("/icons/loopTrue.png");
} else {
ytLoopBttn.title = "Start Loop...";
video.loop = false;
ytLoopBttn.src = browser.extension.getURL("/icons/loopFalse.png");
}
return;
} }
function pauseEvent(e) { function toggleFloat() {
if(e.stopPropagation) e.stopPropagation(); playerWindow = document.getElementById("player-container").children[1]; // Actual player
if(e.preventDefault) e.preventDefault();
e.cancelBubble = true;
e.returnValue = false;
return false;
}
}
function checkPg() { if(poppedContainer.style.display == "none"){
if (!document.getElementById("enhancerMenuIDRef")) { poppedContainer.appendChild(playerWindow);
var existCondition = setInterval(function() { poppedContainer.style.display = "block";
if (document.getElementById("masthead-container")) { } else {
clearInterval(existCondition); containerOfPlyrWndow.append(playerWindow);
preSetupProc(); poppedContainer.style.display = "none";
setupProc(); }
count = 0; }
} else {
if (count == 12) { // ~ 6 sec through half sec loops function manageVolume(e) {
count = 0; var delta;
e.preventDefault(); // Keep page from scrolling while in video area
// Detect scroll direction
if (e.wheelDelta) delta = e.wheelDelta; else delta = -1 * e.deltaY;
// Vol UP || Vol DOWN
if (delta > 0) video.volume += 0.05; else if (delta < 0) video.volume -= 0.05;
}
function dragVideo(elmnt) {
var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
elmnt.onmousedown = dragMouseDown;
function dragMouseDown(e) {
e = e || window.event;
pauseEvent(e);
// get the mouse cursor position at startup:
pos3 = e.clientX;
pos4 = e.clientY;
document.onmouseup = closeDragElement;
// call a function whenever the cursor moves:
document.onmousemove = elementDrag;
}
function elementDrag(e) {
e = e || window.event;
pauseEvent(e);
// calculate the new cursor position:
pos1 = pos3 - e.clientX;
pos2 = pos4 - e.clientY;
pos3 = e.clientX;
pos4 = e.clientY;
// set the element's new position:
elmnt.style.top = (elmnt.offsetTop - pos2) + "px";
elmnt.style.left = (elmnt.offsetLeft - pos1) + "px";
}
function closeDragElement(e) {
// stop moving when mouse button is released:
document.onmouseup = null;
document.onmousemove = null;
}
function pauseEvent(e) {
if(e.stopPropagation) e.stopPropagation();
if(e.preventDefault) e.preventDefault();
e.cancelBubble = true;
e.returnValue = false;
return false;
}
}
function checkPg() {
if (!document.getElementById("enhancerMenuIDRef")) {
var existCondition = setInterval(function() {
if (document.getElementById("masthead-container")) {
clearInterval(existCondition); clearInterval(existCondition);
preSetupProc();
setupProc();
count = 0;
} else { } else {
count++; if (count == 12) { // ~ 6 sec through half sec loops
count = 0;
clearInterval(existCondition);
} else {
count++;
}
} }
} }, 500); // check every 500ms
}, 500); // check every 500ms } else {
} else { preSetupProc();
preSetupProc(); }
} }
// Start init
checkPg();
} }
// Start init betterYoutubePlus();
checkPg();