Added preview bar with the sponsors

This commit is contained in:
Ajay Ramachandran
2019-08-12 19:34:44 -04:00
parent 640ad58c65
commit 5feed6bfcc
4 changed files with 113 additions and 0 deletions

View File

@@ -1,3 +1,21 @@
#previewbar {
overflow: visible;
padding: 0;
margin: 0;
position: absolute;
width: 100%;
pointer-events: none;
height: 100%;
transform: scaleY(0.6) translateY(-30%) translateY(1.5px);
z-index: 40;
}
.previewbar {
display: inline-block;
height: 100%;
}
.popup { .popup {
z-index: 10; z-index: 10;
width: 100%; width: 100%;

View File

@@ -19,6 +19,10 @@ var channelURL;
//is this channel whitelised from getting sponsors skipped //is this channel whitelised from getting sponsors skipped
var channelWhitelisted = false; var channelWhitelisted = false;
// create preview bar
let progressBar = document.getElementsByClassName("ytp-progress-bar-container")[0] || document.getElementsByClassName("no-model cue-range-markers")[0];
var previewBar = new PreviewBar(progressBar);
if(id = getYouTubeVideoID(document.URL)){ // Direct Links if(id = getYouTubeVideoID(document.URL)){ // Direct Links
videoIDChange(id); videoIDChange(id);
} }
@@ -310,6 +314,10 @@ function sponsorsLookup(id) {
sponsorTimes = JSON.parse(xmlhttp.responseText).sponsorTimes; sponsorTimes = JSON.parse(xmlhttp.responseText).sponsorTimes;
UUIDs = JSON.parse(xmlhttp.responseText).UUIDs; UUIDs = JSON.parse(xmlhttp.responseText).UUIDs;
//update the preview bar
//leave the type blank for now until categories are added
previewBar.set(sponsorTimes, [], v.duration);
getChannelID(); getChannelID();
sponsorLookupRetries = 0; sponsorLookupRetries = 0;

View File

@@ -11,6 +11,7 @@
"all_frames": true, "all_frames": true,
"js": [ "js": [
"config.js", "config.js",
"utils/previewBar.js",
"utils.js", "utils.js",
"content.js", "content.js",
"popup.js" "popup.js"

86
utils/previewBar.js Normal file
View File

@@ -0,0 +1,86 @@
/*
This is based on code from VideoSegments.
https://github.com/videosegments/videosegments/commits/f1e111bdfe231947800c6efdd51f62a4e7fef4d4/segmentsbar/segmentsbar.js
*/
'use strict';
let barTypes = {
"undefined": {
color: "#00d400",
opacity: "0.5"
},
"sponsor": {
color: "#00d400",
opacity: "0.5"
}
};
class PreviewBar {
constructor(parent) {
this.container = document.createElement('ul');
this.container.id = 'previewbar';
this.parent = parent;
this.bars = []
this.updatePosition();
}
updatePosition() {
//below the seek bar
// this.parent.insertAdjacentElement("afterEnd", this.container);
//on the seek bar
this.parent.insertAdjacentElement("afterBegin", this.container);
}
updateColor(segment, color, opacity) {
let bars = document.querySelectorAll('[data-vs-segment-type=' + segment + ']');
for (let bar of bars) {
bar.style.backgroundColor = color;
bar.style.opacity = opacity;
}
}
set(timestamps, types, duration) {
while (this.container.firstChild) {
this.container.removeChild(this.container.firstChild);
}
if (!timestamps || !types) {
return;
}
// to avoid rounding error resulting in width more than 100%
duration = Math.floor(duration * 100) / 100;
let width;
for (let i = 0; i < timestamps.length; i++) {
width = (timestamps[i][1] - timestamps[i][0]) / duration * 100;
width = Math.floor(width * 100) / 100;
let bar = this.createBar();
bar.setAttribute('data-vs-segment-type', types[i]);
bar.style.backgroundColor = barTypes[types[i]].color;
bar.style.opacity = barTypes[types[i]].opacity;
bar.style.width = width + '%';
bar.style.left = (timestamps[i][0] / duration * 100) + "%";
bar.style.position = "absolute"
this.container.insertAdjacentElement('beforeEnd', bar);
this.bars[i] = bar;
}
}
createBar() {
let bar = document.createElement('li');
bar.classList.add('previewbar');
bar.innerHTML = '&nbsp;';
return bar;
}
remove() {
this.container.remove();
this.container = undefined;
}
}