diff --git a/content.js b/content.js
index 6ed587d0..395e8838 100644
--- a/content.js
+++ b/content.js
@@ -17,6 +17,12 @@ if(id = getYouTubeVideoID(document.URL)){ // Direct Links
//the video
var v;
+//the channel this video is about
+var channelURL;
+
+//is this channel whitelised from getting sponsors skipped
+var channelWhitelisted = false;
+
//the last time looked at (used to see if this time is in the interval)
var lastTime = -1;
@@ -109,6 +115,23 @@ function messageListener(request, sender, sendResponse) {
})
}
+ if (request.message == "getChannelURL") {
+ sendResponse({
+ channelURL: channelURL
+ })
+ }
+
+ if (request.message == "isChannelWhitelisted") {
+ sendResponse({
+ value: channelWhitelisted
+ })
+ }
+
+ if (request.message == "whitelistChange") {
+ channelWhitelisted = request.value;
+ sponsorsLookup(getYouTubeVideoID(document.URL));
+ }
+
if (request.message == "showNoticeAgain") {
dontShowNotice = false;
}
@@ -246,6 +269,9 @@ function sponsorsLookup(id) {
sponsorTimes = JSON.parse(xmlhttp.responseText).sponsorTimes;
UUIDs = JSON.parse(xmlhttp.responseText).UUIDs;
+
+ getChannelID();
+
} else if (xmlhttp.readyState == 4) {
sponsorDataFound = false;
@@ -270,6 +296,39 @@ function sponsorsLookup(id) {
};
}
+function getChannelID() {
+ //get channel id
+ let channelContainers = document.querySelectorAll("#owner-name");
+ let channelURLContainer = null;
+
+ for (let i = 0; i < channelContainers.length; i++) {
+ if (channelContainers[i].firstElementChild != null) {
+ channelURLContainer = channelContainers[i].firstElementChild;
+ }
+ }
+
+ if (channelURLContainer == null) {
+ //try later
+ setTimeout(getChannelID, 100);
+ return;
+ }
+
+ channelURL = channelURLContainer.getAttribute("href");
+
+ //see if this is a whitelisted channel
+ chrome.storage.sync.get(["whitelistedChannels"], function(result) {
+ let whitelistedChannels = result.whitelistedChannels;
+
+ if (whitelistedChannels != undefined && whitelistedChannels.includes(channelURL)) {
+ //reset sponsor times to nothing
+ sponsorTimes = [];
+ UUIDs = [];
+
+ channelWhitelisted = true;
+ }
+ });
+}
+
//video skipping
function sponsorCheck() {
let skipHappened = false;
diff --git a/popup.css b/popup.css
index d1efc61f..cb86b962 100644
--- a/popup.css
+++ b/popup.css
@@ -86,6 +86,32 @@ h1.popupElement {
cursor: pointer;
}
+.whitelistButton.popupElement {
+ background-color:#3acc3a;
+ -moz-border-radius:28px;
+ -webkit-border-radius:28px;
+ border-radius:28px;
+ border: none;
+ display:inline-block;
+ cursor:pointer;
+ color:#ffffff;
+ font-size:16px;
+ padding:8px 37px;
+ text-decoration:none;
+ text-shadow:0px 0px 0px #27663c;
+ }
+ .whitelistButton:hover.popupElement {
+ background-color:#218b26;
+ }
+ .whitelistButton:focus.popupElement {
+ outline: none;
+ background-color:#218b26;
+ }
+ .whitelistButton:active.popupElement {
+ position:relative;
+ top:1px;
+ }
+
.greenButton.popupElement {
background-color:#ec1c1c;
-moz-border-radius:28px;
diff --git a/popup.html b/popup.html
index acdd455c..be45142b 100644
--- a/popup.html
+++ b/popup.html
@@ -25,7 +25,18 @@
+
+
+
+
+
+
+
+
+
diff --git a/popup.js b/popup.js
index f9182448..8368f274 100644
--- a/popup.js
+++ b/popup.js
@@ -25,6 +25,8 @@ function runThePopup() {
var SB = {};
["sponsorStart",
+ "whitelistChannel",
+ "unwhitelistChannel",
"clearTimes",
"submitTimes",
"showNoticeAgain",
@@ -63,6 +65,8 @@ function runThePopup() {
//setup click listeners
SB.sponsorStart.addEventListener("click", sendSponsorStartMessage);
+ SB.whitelistChannel.addEventListener("click", whitelistChannel);
+ SB.unwhitelistChannel.addEventListener("click", unwhitelistChannel);
SB.clearTimes.addEventListener("click", clearTimes);
SB.submitTimes.addEventListener("click", submitTimes);
SB.showNoticeAgain.addEventListener("click", showNoticeAgain);
@@ -118,6 +122,26 @@ function runThePopup() {
});
}
});
+
+ //see if whitelist button should be swapped
+ chrome.tabs.query({
+ active: true,
+ currentWindow: true
+ }, tabs => {
+ chrome.tabs.sendMessage(
+ tabs[0].id,
+ {message: 'isChannelWhitelisted'},
+ function(response) {
+ if (response.value) {
+ SB.whitelistChannel.style.display = "none";
+ SB.unwhitelistChannel.style.display = "unset";
+
+ SB.downloadedSponsorMessageTimes.innerText = "Channel Whitelisted!";
+ SB.downloadedSponsorMessageTimes.style.fontWeight = "bold";
+ }
+ });
+ }
+ );
//if the don't show notice again letiable is true, an option to
// disable should be available
@@ -343,7 +367,9 @@ function runThePopup() {
function displayDownloadedSponsorTimes(request) {
if (request.sponsorTimes != undefined) {
//set it to the message
- SB.downloadedSponsorMessageTimes.innerText = getSponsorTimesMessage(request.sponsorTimes);
+ if (SB.downloadedSponsorMessageTimes.innerText != "Channel Whitelisted!") {
+ SB.downloadedSponsorMessageTimes.innerText = getSponsorTimesMessage(request.sponsorTimes);
+ }
//add them as buttons to the issue reporting container
let container = document.getElementById("issueReporterTimeButtons");
@@ -966,6 +992,103 @@ function runThePopup() {
return formatted;
}
+
+ function whitelistChannel() {
+ //get the channel url
+ chrome.tabs.query({
+ active: true,
+ currentWindow: true
+ }, tabs => {
+ chrome.tabs.sendMessage(
+ tabs[0].id,
+ {message: 'getChannelURL'},
+ function(response) {
+ //get whitelisted channels
+ chrome.storage.sync.get(["whitelistedChannels"], function(result) {
+ let whitelistedChannels = result.whitelistedChannels;
+ if (whitelistedChannels == undefined) {
+ whitelistedChannels = [];
+ }
+
+ //add on this channel
+ whitelistedChannels.push(response.channelURL);
+
+ //change button
+ SB.whitelistChannel.style.display = "none";
+ SB.unwhitelistChannel.style.display = "unset";
+
+ SB.downloadedSponsorMessageTimes.innerText = "Channel Whitelisted!";
+ SB.downloadedSponsorMessageTimes.style.fontWeight = "bold";
+
+ //save this
+ chrome.storage.sync.set({whitelistedChannels: whitelistedChannels});
+
+ //send a message to the client
+ chrome.tabs.query({
+ active: true,
+ currentWindow: true
+ }, tabs => {
+ chrome.tabs.sendMessage(
+ tabs[0].id, {
+ message: 'whitelistChange',
+ value: true
+ });
+ }
+ );
+ });
+ }
+ );
+ });
+ }
+
+ function unwhitelistChannel() {
+ //get the channel url
+ chrome.tabs.query({
+ active: true,
+ currentWindow: true
+ }, tabs => {
+ chrome.tabs.sendMessage(
+ tabs[0].id,
+ {message: 'getChannelURL'},
+ function(response) {
+ //get whitelisted channels
+ chrome.storage.sync.get(["whitelistedChannels"], function(result) {
+ let whitelistedChannels = result.whitelistedChannels;
+ if (whitelistedChannels == undefined) {
+ whitelistedChannels = [];
+ }
+
+ //remove this channel
+ let index = whitelistedChannels.indexOf(response.channelURL);
+ whitelistedChannels.splice(index, 1);
+
+ //change button
+ SB.whitelistChannel.style.display = "unset";
+ SB.unwhitelistChannel.style.display = "none";
+
+ SB.downloadedSponsorMessageTimes.innerText = "";
+ SB.downloadedSponsorMessageTimes.style.fontWeight = "unset";
+
+ //save this
+ chrome.storage.sync.set({whitelistedChannels: whitelistedChannels});
+
+ //send a message to the client
+ chrome.tabs.query({
+ active: true,
+ currentWindow: true
+ }, tabs => {
+ chrome.tabs.sendMessage(
+ tabs[0].id, {
+ message: 'whitelistChange',
+ value: false
+ });
+ }
+ );
+ });
+ }
+ );
+ });
+ }
//converts time in seconds to minutes
function getTimeInMinutes(seconds) {