Merge pull request #1 from ajayyy/experimental

Visual Upgrade and controls on the YouTube Player
This commit is contained in:
Ajay Ramachandran
2019-07-12 22:55:43 -04:00
committed by GitHub
18 changed files with 661 additions and 102 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
content-config.js content-config.js
ignored

View File

@@ -1,3 +1,6 @@
![Logo](icons/LogoSponsorBlocker256px.png)
<br/><sub>Logo by [@munadikieh](https://github.com/munadikieh)</sub>
# SponsorBlocker # SponsorBlocker
SponsorBlocker is an extension that will skip over sponsored segments of YouTube videos. SponsorBlocker is a crowdsourced browser extension that let's anyone submit the start and end time's of sponsored segments of YouTube videos. Once one person submits this information, everyone else with this extension will skip right over the sponsored segment. SponsorBlocker is an extension that will skip over sponsored segments of YouTube videos. SponsorBlocker is a crowdsourced browser extension that let's anyone submit the start and end time's of sponsored segments of YouTube videos. Once one person submits this information, everyone else with this extension will skip right over the sponsored segment.

View File

@@ -1,5 +1,8 @@
var previousVideoID = null var previousVideoID = null
//the id of this user, randomly generated once per install
var userID = null;
chrome.tabs.onUpdated.addListener( // On tab update chrome.tabs.onUpdated.addListener( // On tab update
function(tabId, changeInfo, tab) { function(tabId, changeInfo, tab) {
if (changeInfo != undefined && changeInfo.url != undefined) { if (changeInfo != undefined && changeInfo.url != undefined) {
@@ -16,8 +19,6 @@ chrome.tabs.onUpdated.addListener( // On tab update
} }
); );
chrome.runtime.onMessage.addListener(function (request, sender, callback) { chrome.runtime.onMessage.addListener(function (request, sender, callback) {
if (request.message == "submitTimes") { if (request.message == "submitTimes") {
submitTimes(request.videoID); submitTimes(request.videoID);
@@ -25,13 +26,59 @@ chrome.runtime.onMessage.addListener(function (request, sender, callback) {
callback({ callback({
success: true success: true
}); });
} else if(request.message == "ytvideoid") { } else if (request.message == "ytvideoid") {
if (previousVideoID != request.videoID) { if (previousVideoID != request.videoID) {
videoIDChange(request.videoID); videoIDChange(request.videoID);
} }
} else if (request.message == "addSponsorTime") {
addSponsorTime(request.time);
} else if (request.message == "getSponsorTimes") {
getSponsorTimes(request.videoID, function(sponsorTimes) {
callback({
sponsorTimes: sponsorTimes
})
});
//this allows the callback to be called later
return true;
} }
}); });
//gets the sponsor times from memory
function getSponsorTimes(videoID, callback) {
let sponsorTimes = [];
let sponsorTimeKey = "sponsorTimes" + videoID;
chrome.storage.local.get([sponsorTimeKey], function(result) {
let sponsorTimesStorage = result[sponsorTimeKey];
if (sponsorTimesStorage != undefined && sponsorTimesStorage.length > 0) {
sponsorTimes = sponsorTimesStorage;
}
callback(sponsorTimes)
});
}
function addSponsorTime(time) {
getSponsorTimes(previousVideoID, function(sponsorTimes) {
//add to sponsorTimes
if (sponsorTimes.length > 0 && sponsorTimes[sponsorTimes.length - 1].length < 2) {
//it is an end time
sponsorTimes[sponsorTimes.length - 1][1] = parseInt(time);
} else {
//it is a start time
let sponsorTimesIndex = sponsorTimes.length;
sponsorTimes[sponsorTimesIndex] = [];
sponsorTimes[sponsorTimesIndex][0] = parseInt(time);
}
//save this info
let sponsorTimeKey = "sponsorTimes" + previousVideoID;
chrome.storage.local.set({[sponsorTimeKey]: sponsorTimes});
});
}
function submitTimes(videoID) { function submitTimes(videoID) {
//get the video times from storage //get the video times from storage
let sponsorTimeKey = 'sponsorTimes' + videoID; let sponsorTimeKey = 'sponsorTimes' + videoID;
@@ -42,9 +89,13 @@ function submitTimes(videoID) {
//submit these times //submit these times
for (let i = 0; i < sponsorTimes.length; i++) { for (let i = 0; i < sponsorTimes.length; i++) {
let xmlhttp = new XMLHttpRequest(); let xmlhttp = new XMLHttpRequest();
let userIDStorage = getUserID(function(userIDStorage) {
//submit the sponsorTime //submit the sponsorTime
xmlhttp.open('GET', 'http://localhost/api/postVideoSponsorTimes?videoID=' + videoID + "&startTime=" + sponsorTimes[i][0] + "&endTime=" + sponsorTimes[i][1], true); xmlhttp.open('GET', 'http://localhost/api/postVideoSponsorTimes?videoID=' + videoID + "&startTime=" + sponsorTimes[i][0] + "&endTime=" + sponsorTimes[i][1]
+ "&userID=" + userIDStorage, true);
xmlhttp.send(); xmlhttp.send();
});
} }
} }
}); });
@@ -64,7 +115,7 @@ function videoIDChange(currentVideoID) {
type: "basic", type: "basic",
title: "Do you want to submit the sponsor times for watch?v=" + previousVideoID + "?", title: "Do you want to submit the sponsor times for watch?v=" + previousVideoID + "?",
message: "You seem to have left some sponsor times unsubmitted. Go back to that page to submit them (they are not deleted).", message: "You seem to have left some sponsor times unsubmitted. Go back to that page to submit them (they are not deleted).",
iconUrl: "icon.png" iconUrl: "./icons/LogoSponsorBlocker256px.png"
}); });
} }
@@ -72,13 +123,38 @@ function videoIDChange(currentVideoID) {
previousVideoID = currentVideoID; previousVideoID = currentVideoID;
}); });
} else { } else {
console.log(currentVideoID)
previousVideoID = currentVideoID; previousVideoID = currentVideoID;
} }
} }
function getUserID(callback) {
if (userID != null) {
callback(userID);
}
//if it is not cached yet, grab it from storage
chrome.storage.local.get(["userID"], function(result) {
let userIDStorage = result.userID;
if (userIDStorage != undefined) {
userID = userIDStorage;
callback(userID);
} else {
//generate a userID
userID = generateUUID();
//save this UUID
chrome.storage.local.set({"userID": userID});
callback(userID);
}
});
}
function getYouTubeVideoID(url) { // Return video id or false function getYouTubeVideoID(url) { // Return video id or false
var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/; var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
var match = url.match(regExp); var match = url.match(regExp);
return (match && match[7].length == 11) ? match[7] : false; return (match && match[7].length == 11) ? match[7] : false;
} }
//uuid generator function from https://gist.github.com/jed/982883
function generateUUID(a){return a?(a^Math.random()*16>>a/4).toString(16):([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,generateUUID)}

85
content.css Normal file
View File

@@ -0,0 +1,85 @@
.sponsorSkipObject {
font-family: 'Source Sans Pro', sans-serif;
}
#sponsorSkipLogo {
height: 64px;
position: absolute;
top: 0;
bottom: 0;
margin: auto;
margin-left: 10px;
}
#sponsorSkipNotice {
min-height: 125px;
min-width: 400px;
background-color: rgba(255, 217, 217, 0.8);
position: absolute;
z-index: 1;
border: 3px solid rgba(0, 0, 0, 0.8);
}
#sponsorSkipMessage {
font-size: 18px;
color: #000000;
text-align: center;
margin-top: 10px;
font-weight: bold;
}
#sponsorSkipInfo {
font-size: 10px;
color: #000000;
text-align: center;
}
.sponsorSkipButton {
background-color:#ec1c1c;
-moz-border-radius:28px;
-webkit-border-radius:28px;
border-radius:28px;
border:1px solid #d31919;
display:inline-block;
cursor:pointer;
color:#ffffff;
font-size:14px;
padding:4px 15px;
text-decoration:none;
text-shadow:0px 0px 0px #662727;
margin-top: 5px;
margin-right: 15px;
}
.sponsorSkipButton:hover {
background-color:#bf2a2a;
}
.sponsorSkipButton:active {
position:relative;
top:1px;
}
.sponsorSkipDontShowButton {
-moz-box-shadow:inset 0px 1px 0px 0px #cf866c;
-webkit-box-shadow:inset 0px 1px 0px 0px #cf866c;
box-shadow:inset 0px 1px 0px 0px #cf866c;
background-color:#d0451b;
-moz-border-radius:3px;
-webkit-border-radius:3px;
border-radius:3px;
border:1px solid #942911;
display:inline-block;
cursor:pointer;
color:#ffffff;
font-size:13px;
padding:6px 24px;
text-decoration:none;
text-shadow:0px 1px 0px #854629;
}
.sponsorSkipDontShowButton:hover {
background-color:#bc3315;
}
.sponsorSkipDontShowButton:active {
position:relative;
top:1px;
}

View File

@@ -1,7 +1,5 @@
if(id = getYouTubeVideoID(document.URL)){ // Direct Links if(id = getYouTubeVideoID(document.URL)){ // Direct Links
//reset sponsor data found check videoIDChange(id);
sponsorDataFound = false;
sponsorsLookup(id);
//tell background.js about this //tell background.js about this
chrome.runtime.sendMessage({ chrome.runtime.sendMessage({
@@ -26,6 +24,12 @@ var lastTime;
//used for the go back button //used for the go back button
var lastSponsorTimeSkipped = null; var lastSponsorTimeSkipped = null;
//if showing the start sponsor button or the end sponsor button on the player
var showingStartSponsor = true;
//should the video controls buttons be added
var hideVideoPlayerControls = false;
//if the notice should not be shown //if the notice should not be shown
//happens when the user click's the "Don't show notice again" button //happens when the user click's the "Don't show notice again" button
var dontShowNotice = false; var dontShowNotice = false;
@@ -40,9 +44,7 @@ chrome.runtime.onMessage.addListener( // Detect URL Changes
function(request, sender, sendResponse) { function(request, sender, sendResponse) {
//message from background script //message from background script
if (request.message == "ytvideoid") { if (request.message == "ytvideoid") {
//reset sponsor data found check videoIDChange(request.id);
sponsorDataFound = false;
sponsorsLookup(request.id);
} }
//messages from popup script //messages from popup script
@@ -67,8 +69,46 @@ chrome.runtime.onMessage.addListener( // Detect URL Changes
if (request.message == "showNoticeAgain") { if (request.message == "showNoticeAgain") {
dontShowNotice = false; dontShowNotice = false;
} }
if (request.message == "toggleStartSponsorButton") {
toggleStartSponsorButton();
}
if (request.message == "changeVideoPlayerControlsVisibility") {
hideVideoPlayerControls = request.value;
updateVisibilityOfPlayerControlsButton();
}
}); });
function videoIDChange(id) {
//reset sponsor data found check
sponsorDataFound = false;
sponsorsLookup(id);
//see if the onvideo control image needs to be changed
chrome.runtime.sendMessage({
message: "getSponsorTimes",
videoID: id
}, function(response) {
if (response != undefined) {
let sponsorTimes = response.sponsorTimes;
if (sponsorTimes != undefined && sponsorTimes.length > 0 && sponsorTimes[sponsorTimes.length - 1].length < 2) {
toggleStartSponsorButton();
}
}
});
//see if video control buttons should be added
chrome.storage.local.get(["hideVideoPlayerControls"], function(result) {
if (result.hideVideoPlayerControls != undefined) {
hideVideoPlayerControls = result.hideVideoPlayerControls;
}
updateVisibilityOfPlayerControlsButton();
});
}
function sponsorsLookup(id) { function sponsorsLookup(id) {
v = document.querySelector('video') // Youtube video player v = document.querySelector('video') // Youtube video player
let xmlhttp = new XMLHttpRequest(); let xmlhttp = new XMLHttpRequest();
@@ -108,7 +148,7 @@ function sponsorCheck(sponsorTimes) { // Video skipping
//send out the message saying that a sponsor message was skipped //send out the message saying that a sponsor message was skipped
openSkipNotice(); openSkipNotice();
setTimeout(closeSkipNotice, 2500); setTimeout(closeSkipNotice, 7000);
} }
lastTime = v.currentTime; lastTime = v.currentTime;
@@ -124,6 +164,64 @@ function goBackToPreviousTime() {
} }
} }
//Adds a sponsorship starts button to the player controls
function addPlayerControlsButton() {
let startSponsorButton = document.createElement("button");
startSponsorButton.id = "startSponsorButton";
startSponsorButton.className = "ytp-button";
startSponsorButton.setAttribute("title", "Sponsor Starts Now");
startSponsorButton.addEventListener("click", startSponsorClicked);
let startSponsorImage = document.createElement("img");
startSponsorImage.id = "startSponsorImage";
startSponsorImage.style.height = "60%";
startSponsorImage.style.top = "0";
startSponsorImage.style.bottom = "0";
startSponsorImage.style.display = "block";
startSponsorImage.style.margin = "auto";
startSponsorImage.src = chrome.extension.getURL("icons/PlayerStartIconSponsorBlocker256px.png");
//add the image to the button
startSponsorButton.appendChild(startSponsorImage);
let referenceNode = document.getElementsByClassName("ytp-right-controls")[0];
referenceNode.prepend(startSponsorButton);
}
function removePlayerControlsButton() {
document.getElementById("startSponsorButton").style.display = "none";
}
//adds or removes the player controls button to what it should be
function updateVisibilityOfPlayerControlsButton() {
if (hideVideoPlayerControls) {
removePlayerControlsButton();
} else {
addPlayerControlsButton();
}
}
function startSponsorClicked() {
toggleStartSponsorButton();
//send back current time with message
chrome.runtime.sendMessage({
message: "addSponsorTime",
time: v.currentTime
});
}
function toggleStartSponsorButton() {
if (showingStartSponsor) {
showingStartSponsor = false;
document.getElementById("startSponsorImage").src = chrome.extension.getURL("icons/PlayerStopIconSponsorBlocker256px.png");
} else {
showingStartSponsor = true;
document.getElementById("startSponsorImage").src = chrome.extension.getURL("icons/PlayerStartIconSponsorBlocker256px.png");
}
}
//Opens the notice that tells the user that a sponsor was just skipped //Opens the notice that tells the user that a sponsor was just skipped
function openSkipNotice(){ function openSkipNotice(){
if (dontShowNotice) { if (dontShowNotice) {
@@ -131,56 +229,57 @@ function openSkipNotice(){
return; return;
} }
var noticeElement = document.createElement("div"); let noticeElement = document.createElement("div");
noticeElement.id = "sponsorSkipNotice";
noticeElement.className = "sponsorSkipObject";
noticeElement.id = 'sponsorSkipNotice' let logoElement = document.createElement("img");
noticeElement.style.minHeight = "100px"; logoElement.id = "sponsorSkipLogo";
noticeElement.style.minWidth = "400px"; logoElement.src = chrome.extension.getURL("icons/LogoSponsorBlocker256px.png");
noticeElement.style.backgroundColor = "rgba(153, 153, 153, 0.8)";
noticeElement.style.fontSize = "24px";
noticeElement.style.position = "absolute"
noticeElement.style.zIndex = "1";
var noticeMessage = document.createElement("p"); let noticeMessage = document.createElement("div");
noticeMessage.id = "sponsorSkipMessage";
noticeMessage.className = "sponsorSkipObject";
noticeMessage.innerText = "Hey, you just skipped a sponsor!"; noticeMessage.innerText = "Hey, you just skipped a sponsor!";
noticeMessage.style.fontSize = "18px";
noticeMessage.style.color = "#000000";
noticeMessage.style.textAlign = "center";
noticeMessage.style.marginTop = "10px";
var buttonContainer = document.createElement("div"); let noticeInfo = document.createElement("p");
noticeInfo.id = "sponsorSkipInfo";
noticeInfo.className = "sponsorSkipObject";
noticeInfo.innerText = "This message will disapear in 7 seconds";
let buttonContainer = document.createElement("div");
buttonContainer.setAttribute("align", "center"); buttonContainer.setAttribute("align", "center");
var goBackButton = document.createElement("button"); let goBackButton = document.createElement("button");
goBackButton.innerText = "Go back"; goBackButton.innerText = "Go back";
goBackButton.style.fontSize = "13px"; goBackButton.className = "sponsorSkipObject";
goBackButton.style.color = "#000000"; goBackButton.className = "sponsorSkipButton";
goBackButton.style.marginTop = "5px";
goBackButton.addEventListener("click", goBackToPreviousTime); goBackButton.addEventListener("click", goBackToPreviousTime);
var hideButton = document.createElement("button"); let hideButton = document.createElement("button");
hideButton.innerText = "Hide"; hideButton.innerText = "Dismiss";
hideButton.style.fontSize = "13px"; hideButton.className = "sponsorSkipObject";
hideButton.style.color = "#000000"; hideButton.className = "sponsorSkipButton";
hideButton.style.marginTop = "5px";
hideButton.addEventListener("click", closeSkipNotice); hideButton.addEventListener("click", closeSkipNotice);
var dontShowAgainButton = document.createElement("button"); let dontShowAgainButton = document.createElement("button");
dontShowAgainButton.innerText = "Don't Show This Again"; dontShowAgainButton.innerText = "Don't Show This Again";
dontShowAgainButton.style.fontSize = "13px"; dontShowAgainButton.className = "sponsorSkipObject";
dontShowAgainButton.style.color = "#000000"; dontShowAgainButton.className = "sponsorSkipDontShowButton";
dontShowAgainButton.style.marginTop = "5px";
dontShowAgainButton.addEventListener("click", dontShowNoticeAgain); dontShowAgainButton.addEventListener("click", dontShowNoticeAgain);
buttonContainer.appendChild(goBackButton); buttonContainer.appendChild(goBackButton);
buttonContainer.appendChild(hideButton); buttonContainer.appendChild(hideButton);
buttonContainer.appendChild(document.createElement("br")); buttonContainer.appendChild(document.createElement("br"));
buttonContainer.appendChild(document.createElement("br"));
buttonContainer.appendChild(dontShowAgainButton); buttonContainer.appendChild(dontShowAgainButton);
noticeElement.appendChild(logoElement);
noticeElement.appendChild(noticeMessage); noticeElement.appendChild(noticeMessage);
noticeElement.appendChild(noticeInfo);
noticeElement.appendChild(buttonContainer); noticeElement.appendChild(buttonContainer);
var referenceNode = document.getElementById("info"); let referenceNode = document.getElementById("info");
if (referenceNode == null) { if (referenceNode == null) {
//old YouTube //old YouTube
referenceNode = document.getElementById("watch-header"); referenceNode = document.getElementById("watch-header");
@@ -207,13 +306,14 @@ function dontShowNoticeAgain() {
function sponsorMessageStarted() { function sponsorMessageStarted() {
let v = document.querySelector('video'); let v = document.querySelector('video');
console.log(v.currentTime)
//send back current time //send back current time
chrome.runtime.sendMessage({ chrome.runtime.sendMessage({
message: "time", message: "time",
time: v.currentTime time: v.currentTime
}); });
//update button
toggleStartSponsorButton();
} }
function getYouTubeVideoID(url) { // Returns with video id else returns false function getYouTubeVideoID(url) { // Returns with video id else returns false

Binary file not shown.

After

Width:  |  Height:  |  Size: 551 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

56
libs/Source+Sans+Pro.css Normal file
View File

@@ -0,0 +1,56 @@
/* cyrillic-ext */
@font-face {
font-family: 'Source Sans Pro';
font-style: normal;
font-weight: 400;
src: local('Source Sans Pro Regular'), local('SourceSansPro-Regular'), url(https://fonts.gstatic.com/s/sourcesanspro/v12/6xK3dSBYKcSV-LCoeQqfX1RYOo3qNa7lqDY.woff2) format('woff2');
unicode-range: U+0460-052F, U+1C80-1C88, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;
}
/* cyrillic */
@font-face {
font-family: 'Source Sans Pro';
font-style: normal;
font-weight: 400;
src: local('Source Sans Pro Regular'), local('SourceSansPro-Regular'), url(https://fonts.gstatic.com/s/sourcesanspro/v12/6xK3dSBYKcSV-LCoeQqfX1RYOo3qPK7lqDY.woff2) format('woff2');
unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
/* greek-ext */
@font-face {
font-family: 'Source Sans Pro';
font-style: normal;
font-weight: 400;
src: local('Source Sans Pro Regular'), local('SourceSansPro-Regular'), url(https://fonts.gstatic.com/s/sourcesanspro/v12/6xK3dSBYKcSV-LCoeQqfX1RYOo3qNK7lqDY.woff2) format('woff2');
unicode-range: U+1F00-1FFF;
}
/* greek */
@font-face {
font-family: 'Source Sans Pro';
font-style: normal;
font-weight: 400;
src: local('Source Sans Pro Regular'), local('SourceSansPro-Regular'), url(https://fonts.gstatic.com/s/sourcesanspro/v12/6xK3dSBYKcSV-LCoeQqfX1RYOo3qO67lqDY.woff2) format('woff2');
unicode-range: U+0370-03FF;
}
/* vietnamese */
@font-face {
font-family: 'Source Sans Pro';
font-style: normal;
font-weight: 400;
src: local('Source Sans Pro Regular'), local('SourceSansPro-Regular'), url(https://fonts.gstatic.com/s/sourcesanspro/v12/6xK3dSBYKcSV-LCoeQqfX1RYOo3qN67lqDY.woff2) format('woff2');
unicode-range: U+0102-0103, U+0110-0111, U+1EA0-1EF9, U+20AB;
}
/* latin-ext */
@font-face {
font-family: 'Source Sans Pro';
font-style: normal;
font-weight: 400;
src: local('Source Sans Pro Regular'), local('SourceSansPro-Regular'), url(https://fonts.gstatic.com/s/sourcesanspro/v12/6xK3dSBYKcSV-LCoeQqfX1RYOo3qNq7lqDY.woff2) format('woff2');
unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
/* latin */
@font-face {
font-family: 'Source Sans Pro';
font-style: normal;
font-weight: 400;
src: local('Source Sans Pro Regular'), local('SourceSansPro-Regular'), url(https://fonts.gstatic.com/s/sourcesanspro/v12/6xK3dSBYKcSV-LCoeQqfX1RYOo3qOK7l.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

View File

@@ -10,9 +10,19 @@
"js": [ "js": [
"content-config.js", "content-config.js",
"content.js" "content.js"
],
"css": [
"content.css",
"./libs/Source+Sans+Pro.css"
] ]
} }
], ],
"web_accessible_resources": [
"icons/LogoSponsorBlocker256px.png",
"icons/IconSponsorBlocker256px.png",
"icons/PlayerStartIconSponsorBlocker256px.png",
"icons/PlayerStopIconSponsorBlocker256px.png"
],
"permissions": [ "permissions": [
"tabs", "tabs",
"storage", "storage",
@@ -25,5 +35,12 @@
"background": { "background": {
"scripts":["background.js"] "scripts":["background.js"]
}, },
"icons": {
"16": "icons/IconSponsorBlocker16px.png",
"32": "icons/IconSponsorBlocker32px.png",
"64": "icons/LogoSponsorBlocker64px.png",
"128": "icons/LogoSponsorBlocker128px.png",
"256": "icons/LogoSponsorBlocker256px.png"
},
"manifest_version": 2 "manifest_version": 2
} }

101
popup.css
View File

@@ -1,7 +1,106 @@
* { * {
font-family: 'Arial'; font-family: 'Source Sans Pro', sans-serif;
}
h1 {
margin-top: 0px;
} }
body { body {
font-size: 14px;
width: 300px; width: 300px;
background-color: #ffd9d9;
}
.greenButton {
background-color:#ec1c1c;
-moz-border-radius:28px;
-webkit-border-radius:28px;
border-radius:28px;
border:1px solid #d31919;
display:inline-block;
cursor:pointer;
color:#ffffff;
font-size:16px;
padding:8px 37px;
text-decoration:none;
text-shadow:0px 0px 0px #662727;
}
.greenButton:hover {
background-color:#bf2a2a;
}
.greenButton:active {
position:relative;
top:1px;
}
.dangerButton {
-moz-box-shadow:inset 0px 1px 0px 0px #cf866c;
-webkit-box-shadow:inset 0px 1px 0px 0px #cf866c;
box-shadow:inset 0px 1px 0px 0px #cf866c;
background-color:#d0451b;
-moz-border-radius:3px;
-webkit-border-radius:3px;
border-radius:3px;
border:1px solid #942911;
display:inline-block;
cursor:pointer;
color:#ffffff;
font-size:13px;
padding:6px 24px;
text-decoration:none;
text-shadow:0px 1px 0px #854629;
}
.dangerButton:hover {
background-color:#bc3315;
}
.dangerButton:active {
position:relative;
top:1px;
}
.warningButton {
-moz-box-shadow:inset 0px 1px 0px 0px #cfbd6c;
-webkit-box-shadow:inset 0px 1px 0px 0px #cfbd6c;
box-shadow:inset 0px 1px 0px 0px #cfbd6c;
background-color:#d0821b;
-moz-border-radius:3px;
-webkit-border-radius:3px;
border-radius:3px;
border:1px solid #948b11;
display:inline-block;
cursor:pointer;
color:#ffffff;
font-size:13px;
padding:6px 24px;
text-decoration:none;
text-shadow:0px 1px 0px #856829;
}
.warningButton:hover {
background-color:#bc8215;
}
.warningButton:active {
position:relative;
top:1px;
}
.smallButton {
background-color:#f9902d;
-moz-border-radius:3px;
-webkit-border-radius:3px;
border-radius:3px;
border:1px solid #f9a72d;
display:inline-block;
cursor:pointer;
color:#ffffff;
font-size:14px;
padding:6px 10px;
text-decoration:none;
}
.smallButton:hover {
background-color:#fa9806;
}
.smallButton:active {
position:relative;
top:1px;
} }

View File

@@ -1,11 +1,14 @@
<html> <html>
<head> <head>
<title>Set Page Color Popup</title> <title>Set Page Color Popup</title>
<link rel="stylesheet" type="text/css" href="/libs/Source+Sans+Pro.css"/>
<link rel="stylesheet" type="text/css" href="popup.css"/> <link rel="stylesheet" type="text/css" href="popup.css"/>
</head> </head>
<center> <center>
<div id="app"> <div id="app">
<img src="icons/LogoSponsorBlocker256px.png" height="64px"/>
<h1>SponsorBlock</h1> <h1>SponsorBlock</h1>
<!-- Loading text --> <!-- Loading text -->
@@ -22,8 +25,6 @@
</div> </div>
<br/>
<h2>Record the times of a sponsorship</h2> <h2>Record the times of a sponsorship</h2>
<p> <p>
@@ -32,7 +33,7 @@
</p> </p>
<div> <div>
<button id="sponsorStart">Sponsorship Starts Now</button> <button id="sponsorStart" class="greenButton">Sponsorship Starts Now</button>
</div> </div>
<div id="submissionSection" style="display: none"> <div id="submissionSection" style="display: none">
@@ -43,16 +44,34 @@
</div> </div>
</b> </b>
<button id="clearTimes">Clear Times</button> <button id="clearTimes" class="smallButton">Clear Times</button>
<br/>
<br/> <br/>
<button id="submitTimes">Submit Times</button> <button id="submitTimes" style="display: none" class="smallButton">Submit Times</button>
</div> </div>
<div id="optionsButtonContainer">
<br/>
<br/> <br/>
<button id="showNoticeAgain" style="display: none">Show Notice Again</button> <button id="optionsButton" class="dangerButton">Options</button>
</div>
<div id="options" style="display: none">
<br/>
<h3>Options</h3>
<button id="hideVideoPlayerControls" class="warningButton">Hide Button On YouTube Player</button>
<button id="showVideoPlayerControls" style="display: none" class="warningButton">Show Button On YouTube Player</button>
<br/>
<br/>
<button id="showNoticeAgain" style="display: none" class="dangerButton">Show Notice Again</button>
</div>
</div> </div>
</div> </div>
</center> </center>

135
popup.js
View File

@@ -3,6 +3,9 @@ document.getElementById("sponsorStart").addEventListener("click", sendSponsorSta
document.getElementById("clearTimes").addEventListener("click", clearTimes); document.getElementById("clearTimes").addEventListener("click", clearTimes);
document.getElementById("submitTimes").addEventListener("click", submitTimes); document.getElementById("submitTimes").addEventListener("click", submitTimes);
document.getElementById("showNoticeAgain").addEventListener("click", showNoticeAgain); document.getElementById("showNoticeAgain").addEventListener("click", showNoticeAgain);
document.getElementById("hideVideoPlayerControls").addEventListener("click", hideVideoPlayerControls);
document.getElementById("showVideoPlayerControls").addEventListener("click", showVideoPlayerControls);
document.getElementById("optionsButton").addEventListener("click", openOptions);
//if true, the button now selects the end time //if true, the button now selects the end time
var startTimeChosen = false; var startTimeChosen = false;
@@ -25,13 +28,14 @@ chrome.storage.local.get(["dontShowNoticeAgain"], function(result) {
} }
}); });
//if no response comes by this point, give up //show proper video player controls option
setTimeout(function() { chrome.storage.local.get(["hideVideoPlayerControls"], function(result) {
if (!isYouTubeTab) { let hideVideoPlayerControls = result.hideVideoPlayerControls;
document.getElementById("loadingIndicator").innerHTML = "This probably isn't a YouTube tab, or you clicked too early. " + if (hideVideoPlayerControls != undefined && hideVideoPlayerControls) {
"If you know this is a YouTube tab, close this popup and open it again."; document.getElementById("hideVideoPlayerControls").style.display = "none";
document.getElementById("showVideoPlayerControls").style.display = "unset";
} }
}, 100); });
chrome.tabs.query({ chrome.tabs.query({
active: true, active: true,
@@ -42,6 +46,12 @@ function loadTabData(tabs) {
//set current videoID //set current videoID
currentVideoID = getYouTubeVideoID(tabs[0].url); currentVideoID = getYouTubeVideoID(tabs[0].url);
if (!currentVideoID) {
//this isn't a YouTube video then
displayNoVideo();
return;
}
//load video times for this video //load video times for this video
let sponsorTimeKey = "sponsorTimes" + currentVideoID; let sponsorTimeKey = "sponsorTimes" + currentVideoID;
chrome.storage.local.get([sponsorTimeKey], function(result) { chrome.storage.local.get([sponsorTimeKey], function(result) {
@@ -58,11 +68,11 @@ function loadTabData(tabs) {
//show submission section //show submission section
document.getElementById("submissionSection").style.display = "unset"; document.getElementById("submissionSection").style.display = "unset";
showSubmitTimesIfNecessary();
} }
}); });
//check if this video's sponsors are known //check if this video's sponsors are known
chrome.tabs.sendMessage( chrome.tabs.sendMessage(
tabs[0].id, tabs[0].id,
@@ -72,6 +82,12 @@ function loadTabData(tabs) {
} }
function infoFound(request) { function infoFound(request) {
if(chrome.runtime.lastError) {
//This page doesn't have the injected content script, or at least not yet
displayNoVideo();
return;
}
//if request is undefined, then the page currently being browsed is not YouTube //if request is undefined, then the page currently being browsed is not YouTube
if (request != undefined) { if (request != undefined) {
//this must be a YouTube video //this must be a YouTube video
@@ -125,20 +141,15 @@ chrome.runtime.onMessage.addListener(function (request, sender, callback) {
let sponsorTimeKey = "sponsorTimes" + currentVideoID; let sponsorTimeKey = "sponsorTimes" + currentVideoID;
chrome.storage.local.set({[sponsorTimeKey]: sponsorTimes}); chrome.storage.local.set({[sponsorTimeKey]: sponsorTimes});
//update startTimeChosen variable updateStartTimeChosen();
if (!startTimeChosen) {
startTimeChosen = true;
document.getElementById("sponsorStart").innerHTML = "Sponsorship Ends Now";
} else {
startTimeChosen = false;
document.getElementById("sponsorStart").innerHTML = "Sponsorship Starts Now";
}
//display video times on screen //display video times on screen
displaySponsorTimes(); displaySponsorTimes();
//show submission section //show submission section
document.getElementById("submissionSection").style.display = "unset"; document.getElementById("submissionSection").style.display = "unset";
showSubmitTimesIfNecessary();
} }
}); });
@@ -179,6 +190,19 @@ function getSponsorTimesMessage(sponsorTimes) {
} }
function clearTimes() { function clearTimes() {
//check if the player controls should be toggled
if (sponsorTimes.length > 0 && sponsorTimes[sponsorTimes.length - 1].length < 2) {
chrome.tabs.query({
active: true,
currentWindow: true
}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {
message: "toggleStartSponsorButton"
});
});
}
//reset sponsorTimes
sponsorTimes = []; sponsorTimes = [];
let sponsorTimeKey = "sponsorTimes" + currentVideoID; let sponsorTimeKey = "sponsorTimes" + currentVideoID;
@@ -188,6 +212,8 @@ function clearTimes() {
//hide submission section //hide submission section
document.getElementById("submissionSection").style.display = "none"; document.getElementById("submissionSection").style.display = "none";
resetStartTimeChosen();
} }
function submitTimes() { function submitTimes() {
@@ -216,10 +242,87 @@ function showNoticeAgain() {
document.getElementById("showNoticeAgain").style.display = "none"; document.getElementById("showNoticeAgain").style.display = "none";
} }
function hideVideoPlayerControls() {
chrome.storage.local.set({"hideVideoPlayerControls": true});
chrome.tabs.query({
active: true,
currentWindow: true
}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {
message: "changeVideoPlayerControlsVisibility",
value: true
});
});
document.getElementById("hideVideoPlayerControls").style.display = "none";
document.getElementById("showVideoPlayerControls").style.display = "unset";
}
function showVideoPlayerControls() {
chrome.storage.local.set({"hideVideoPlayerControls": false});
chrome.tabs.query({
active: true,
currentWindow: true
}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {
message: "changeVideoPlayerControlsVisibility",
value: false
});
});
document.getElementById("hideVideoPlayerControls").style.display = "unset";
document.getElementById("showVideoPlayerControls").style.display = "none";
}
function updateStartTimeChosen() {
//update startTimeChosen variable
if (!startTimeChosen) {
startTimeChosen = true;
document.getElementById("sponsorStart").innerHTML = "Sponsorship Ends Now";
} else {
resetStartTimeChosen();
}
}
//set it to false
function resetStartTimeChosen() {
startTimeChosen = false;
document.getElementById("sponsorStart").innerHTML = "Sponsorship Starts Now";
}
function showSubmitTimesIfNecessary() {
//check if an end time has been specified for the latest sponsor time
if (sponsorTimes.length > 0 && sponsorTimes[sponsorTimes.length - 1].length > 1) {
//show submit times button
document.getElementById("submitTimes").style.display = "unset";
} else {
document.getElementById("submitTimes").style.display = "none";
}
}
//make the options div visisble
function openOptions() {
document.getElementById("optionsButtonContainer").style.display = "none";
document.getElementById("options").style.display = "unset";
}
//this is not a YouTube video page
function displayNoVideo() {
document.getElementById("loadingIndicator").innerHTML = "This probably isn't a YouTube tab, or you clicked too early. " +
"If you know this is a YouTube tab, close this popup and open it again.";
}
//converts time in seconds to minutes:seconds //converts time in seconds to minutes:seconds
function getFormattedTime(seconds) { function getFormattedTime(seconds) {
let minutes = Math.floor(seconds / 60); let minutes = Math.floor(seconds / 60);
let secondsDisplay = Math.round(seconds - minutes * 60); let secondsDisplay = Math.round(seconds - minutes * 60);
if (secondsDisplay < 10) {
//add a zero
secondsDisplay = "0" + secondsDisplay;
}
let formatted = minutes+ ":" + secondsDisplay; let formatted = minutes+ ":" + secondsDisplay;
return formatted; return formatted;