aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAjay Ramachandran <[email protected]>2019-08-19 19:21:19 -0400
committerAjay Ramachandran <[email protected]>2019-08-19 19:21:19 -0400
commitdb4182d074d1d8830ff6fc5bdf4c92390a2cf42d (patch)
tree998865643332be3936a79bb3fd2e540090529edb
parentcc2d1405b62efcc65b17fec10271d1621e9287ae (diff)
downloadSponsorBlock-db4182d074d1d8830ff6fc5bdf4c92390a2cf42d.tar.gz
SponsorBlock-db4182d074d1d8830ff6fc5bdf4c92390a2cf42d.zip
Fixed indentation
-rw-r--r--_locales/en/messages.json238
-rw-r--r--background.js326
-rw-r--r--content.js1542
-rw-r--r--popup.css60
-rw-r--r--popup.js2164
5 files changed, 2165 insertions, 2165 deletions
diff --git a/_locales/en/messages.json b/_locales/en/messages.json
index 04454097..4d0fea81 100644
--- a/_locales/en/messages.json
+++ b/_locales/en/messages.json
@@ -1,124 +1,124 @@
{
- "Name": {
- "message": "SponsorBlock",
- "description": "Name of the extension."
- },
- "fullName": {
- "message": "SponsorBlock for YouTube - Skip Sponsorships",
- "description": "Name of the extension."
- },
+ "Name": {
+ "message": "SponsorBlock",
+ "description": "Name of the extension."
+ },
+ "fullName": {
+ "message": "SponsorBlock for YouTube - Skip Sponsorships",
+ "description": "Name of the extension."
+ },
- "Description": {
- "message": "Skip over sponsorship on YouTube videos. Report sponsors on videos you watch to save the time of others.",
- "description": "Description of the extension."
- },
- "helpPage": {
- "message": "index_en.html"
- },
- "400": {
- "message": "Server said this request was invalid"
- },
- "429": {
- "message": "You have submitted too many sponsor times for this one video, are you sure there are this many?"
- },
- "409": {
- "message": "This has already been submitted before"
- },
- "502": {
- "message": "It seems the server is down. Contact the dev to inform them."
- },
- "channelWhitelisted": {
- "message": "Channel Whitelisted!"
- },
- "Sponsor": {
- "message": "Sponsor"
- },
- "Sponsors": {
- "message": "Sponsors"
- },
+ "Description": {
+ "message": "Skip over sponsorship on YouTube videos. Report sponsors on videos you watch to save the time of others.",
+ "description": "Description of the extension."
+ },
+ "helpPage": {
+ "message": "index_en.html"
+ },
+ "400": {
+ "message": "Server said this request was invalid"
+ },
+ "429": {
+ "message": "You have submitted too many sponsor times for this one video, are you sure there are this many?"
+ },
+ "409": {
+ "message": "This has already been submitted before"
+ },
+ "502": {
+ "message": "It seems the server is down. Contact the dev to inform them."
+ },
+ "channelWhitelisted": {
+ "message": "Channel Whitelisted!"
+ },
+ "Sponsor": {
+ "message": "Sponsor"
+ },
+ "Sponsors": {
+ "message": "Sponsors"
+ },
"Segment": {
- "message": "sponsor segment"
- },
- "Segments": {
- "message": "sponsor segments"
- },
- "noticeTitle": {
- "message": "Sponsor Skipped"
- },
- "reportButtonTitle": {
- "message": "Report"
- },
- "reportButtonInfo": {
- "message": "Report this sponsor submission as incorrect."
- },
- "Dismiss": {
- "message": "Dismiss"
- },
- "Loading": {
- "message": "Loading..."
- },
- "Mins": {
- "message": "Minutes"
- },
- "Secs": {
- "message": "Seconds"
- },
- "Hide": {
- "message": "Never Show"
- },
- "hitGoBack": {
- "message": "Hit unskip to get to where you came from."
- },
- "unskip": {
- "message": "Unskip"
- },
- "reskip": {
- "message": "Reskip"
- },
- "paused": {
- "message": "Paused"
- },
- "confirmMSG": {
- "message": "\n\nTo edit or delete individual values, click the info button or open the extension popup by clicking the extension icon in the top right corner."
- },
- "clearThis": {
- "message": "Are you sure you want to clear this?\n\n"
- },
- "Unknown": {
- "message": "There was an error submitting your sponsor times, please try again later."
- },
+ "message": "sponsor segment"
+ },
+ "Segments": {
+ "message": "sponsor segments"
+ },
+ "noticeTitle": {
+ "message": "Sponsor Skipped"
+ },
+ "reportButtonTitle": {
+ "message": "Report"
+ },
+ "reportButtonInfo": {
+ "message": "Report this sponsor submission as incorrect."
+ },
+ "Dismiss": {
+ "message": "Dismiss"
+ },
+ "Loading": {
+ "message": "Loading..."
+ },
+ "Mins": {
+ "message": "Minutes"
+ },
+ "Secs": {
+ "message": "Seconds"
+ },
+ "Hide": {
+ "message": "Never Show"
+ },
+ "hitGoBack": {
+ "message": "Hit unskip to get to where you came from."
+ },
+ "unskip": {
+ "message": "Unskip"
+ },
+ "reskip": {
+ "message": "Reskip"
+ },
+ "paused": {
+ "message": "Paused"
+ },
+ "confirmMSG": {
+ "message": "\n\nTo edit or delete individual values, click the info button or open the extension popup by clicking the extension icon in the top right corner."
+ },
+ "clearThis": {
+ "message": "Are you sure you want to clear this?\n\n"
+ },
+ "Unknown": {
+ "message": "There was an error submitting your sponsor times, please try again later."
+ },
- "sponsorFound": {
- "message": "This video's sponsors are in the database!"
- },
- "sponsor404": {
- "message": "No sponsors found"
- },
- "sponsorStart": {
- "message": "Sponsorship Starts Now"
- },
- "sponsorEnd": {
- "message": "Sponsorship Ends Now"
- },
- "noVideoID": {
- "message": "This probably isn't a YouTube tab, or you clicked too early. \n If you know this is a YouTube tab,\n close this popup and open it again."
- },
- "Voted": {
- "message": "Voted!"
- },
- "voteFail": {
- "message": "You have already voted this way before."
- },
- "serverDown": {
- "message": "It seems the sever is down. Contact the dev immediately."
- },
- "connectionError": {
- "message": "A connection error has occured. Error code: "
- },
- "wantToSubmit": {
- "message": "Do you want to submit the sponsor times for video id"
- },
- "leftTimes": {
- "message": "You seem to have left some sponsor times unsubmitted. Go back to that page to submit them (they are not deleted)."
- }
+ "sponsorFound": {
+ "message": "This video's sponsors are in the database!"
+ },
+ "sponsor404": {
+ "message": "No sponsors found"
+ },
+ "sponsorStart": {
+ "message": "Sponsorship Starts Now"
+ },
+ "sponsorEnd": {
+ "message": "Sponsorship Ends Now"
+ },
+ "noVideoID": {
+ "message": "This probably isn't a YouTube tab, or you clicked too early. \n If you know this is a YouTube tab,\n close this popup and open it again."
+ },
+ "Voted": {
+ "message": "Voted!"
+ },
+ "voteFail": {
+ "message": "You have already voted this way before."
+ },
+ "serverDown": {
+ "message": "It seems the sever is down. Contact the dev immediately."
+ },
+ "connectionError": {
+ "message": "A connection error has occured. Error code: "
+ },
+ "wantToSubmit": {
+ "message": "Do you want to submit the sponsor times for video id"
+ },
+ "leftTimes": {
+ "message": "You seem to have left some sponsor times unsubmitted. Go back to that page to submit them (they are not deleted)."
+ }
}
diff --git a/background.js b/background.js
index e531869d..d0efeb08 100644
--- a/background.js
+++ b/background.js
@@ -1,221 +1,221 @@
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
chrome.tabs.sendMessage(tabId, {
- message: 'update',
+ message: 'update',
});
});
chrome.runtime.onMessage.addListener(function (request, sender, callback) {
switch(request.message) {
- case "submitTimes":
+ case "submitTimes":
submitTimes(request.videoID, callback);
-
+
//this allows the callback to be called later by the submitTimes function
return true;
- case "addSponsorTime":
+ case "addSponsorTime":
addSponsorTime(request.time, request.videoID, callback);
-
+
//this allows the callback to be called later
return true;
- case "getSponsorTimes":
+ case "getSponsorTimes":
getSponsorTimes(request.videoID, function(sponsorTimes) {
- callback({
+ callback({
sponsorTimes: sponsorTimes
- })
+ })
});
-
+
//this allows the callback to be called later
return true;
- case "submitVote":
+ case "submitVote":
submitVote(request.type, request.UUID, callback);
-
+
//this allows the callback to be called later
return true;
- case "alertPrevious":
+ case "alertPrevious":
chrome.notifications.create("stillThere" + Math.random(), {
- type: "basic",
- title: "Do you want to submit the sponsor times for video id " + request.previousVideoID + "?",
- message: "You seem to have left some sponsor times unsubmitted. Go back to that page to submit them (they are not deleted).",
- iconUrl: "./icons/LogoSponsorBlocker256px.png"
+ type: "basic",
+ title: "Do you want to submit the sponsor times for video id " + request.previousVideoID + "?",
+ message: "You seem to have left some sponsor times unsubmitted. Go back to that page to submit them (they are not deleted).",
+ iconUrl: "./icons/LogoSponsorBlocker256px.png"
});
}
});
//add help page on install
chrome.runtime.onInstalled.addListener(function (object) {
- // TODO (shownInstallPage): remove shownInstallPage logic after sufficient amount of time,
- // so that people have time to upgrade and move to shownInstallPage-free code.
- chrome.storage.sync.get(["userID", "shownInstallPage"], function(result) {
- const userID = result.userID;
- // TODO (shownInstallPage): delete row below
- const shownInstallPage = result.shownInstallPage;
-
- // If there is no userID, then it is the first install.
- if (!userID){
- // Show install page, if there is no user id
- // and there is no shownInstallPage.
- // TODO (shownInstallPage): remove this if statement, but leave contents
- if (!shownInstallPage){
- //open up the install page
-
- chrome.tabs.create({url: chrome.extension.getURL("/help/"+chrome.i18n.getMessage("helpPage"))});
- }
-
- // TODO (shownInstallPage): delete if statement and contents
- // If shownInstallPage is set, remove it.
- if (!!shownInstallPage){
- chrome.storage.sync.remove("shownInstallPage");
- }
-
- //generate a userID
- const newUserID = generateUUID();
- //save this UUID
- chrome.storage.sync.set({
- "userID": newUserID,
- //the last video id loaded, to make sure it is a video id change
- "sponsorVideoID": null,
- "previousVideoID": null
- });
- }
- });
+ // TODO (shownInstallPage): remove shownInstallPage logic after sufficient amount of time,
+ // so that people have time to upgrade and move to shownInstallPage-free code.
+ chrome.storage.sync.get(["userID", "shownInstallPage"], function(result) {
+ const userID = result.userID;
+ // TODO (shownInstallPage): delete row below
+ const shownInstallPage = result.shownInstallPage;
+
+ // If there is no userID, then it is the first install.
+ if (!userID){
+ // Show install page, if there is no user id
+ // and there is no shownInstallPage.
+ // TODO (shownInstallPage): remove this if statement, but leave contents
+ if (!shownInstallPage){
+ //open up the install page
+
+ chrome.tabs.create({url: chrome.extension.getURL("/help/"+chrome.i18n.getMessage("helpPage"))});
+ }
+
+ // TODO (shownInstallPage): delete if statement and contents
+ // If shownInstallPage is set, remove it.
+ if (!!shownInstallPage){
+ chrome.storage.sync.remove("shownInstallPage");
+ }
+
+ //generate a userID
+ const newUserID = generateUUID();
+ //save this UUID
+ chrome.storage.sync.set({
+ "userID": newUserID,
+ //the last video id loaded, to make sure it is a video id change
+ "sponsorVideoID": null,
+ "previousVideoID": null
+ });
+ }
+ });
});
//gets the sponsor times from memory
function getSponsorTimes(videoID, callback) {
- let sponsorTimes = [];
- let sponsorTimeKey = "sponsorTimes" + videoID;
- chrome.storage.sync.get([sponsorTimeKey], function(result) {
- let sponsorTimesStorage = result[sponsorTimeKey];
- if (sponsorTimesStorage != undefined && sponsorTimesStorage.length > 0) {
- sponsorTimes = sponsorTimesStorage;
- }
+ let sponsorTimes = [];
+ let sponsorTimeKey = "sponsorTimes" + videoID;
+ chrome.storage.sync.get([sponsorTimeKey], function(result) {
+ let sponsorTimesStorage = result[sponsorTimeKey];
+ if (sponsorTimesStorage != undefined && sponsorTimesStorage.length > 0) {
+ sponsorTimes = sponsorTimesStorage;
+ }
- callback(sponsorTimes)
- });
+ callback(sponsorTimes)
+ });
}
function addSponsorTime(time, videoID, callback) {
- getSponsorTimes(videoID, 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] = time;
- } else {
- //it is a start time
- let sponsorTimesIndex = sponsorTimes.length;
- sponsorTimes[sponsorTimesIndex] = [];
-
- sponsorTimes[sponsorTimesIndex][0] = time;
- }
+ getSponsorTimes(videoID, 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] = time;
+ } else {
+ //it is a start time
+ let sponsorTimesIndex = sponsorTimes.length;
+ sponsorTimes[sponsorTimesIndex] = [];
+
+ sponsorTimes[sponsorTimesIndex][0] = time;
+ }
- //save this info
- let sponsorTimeKey = "sponsorTimes" + videoID;
- chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes}, callback);
- });
+ //save this info
+ let sponsorTimeKey = "sponsorTimes" + videoID;
+ chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes}, callback);
+ });
}
function submitVote(type, UUID, callback) {
- chrome.storage.sync.get(["userID"], function(result) {
- let userID = result.userID;
-
- //publish this vote
- sendRequestToServer("GET", "/api/voteOnSponsorTime?UUID=" + UUID + "&userID=" + userID + "&type=" + type, function(xmlhttp, error) {
- if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
- callback({
- successType: 1
- });
- } else if (xmlhttp.readyState == 4 && xmlhttp.status == 405) {
- //duplicate vote
- callback({
- successType: 0,
- statusCode: xmlhttp.status
- });
- } else if (error) {
- //error while connect
- callback({
- successType: -1,
- statusCode: xmlhttp.status
- });
- }
+ chrome.storage.sync.get(["userID"], function(result) {
+ let userID = result.userID;
+
+ //publish this vote
+ sendRequestToServer("GET", "/api/voteOnSponsorTime?UUID=" + UUID + "&userID=" + userID + "&type=" + type, function(xmlhttp, error) {
+ if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
+ callback({
+ successType: 1
+ });
+ } else if (xmlhttp.readyState == 4 && xmlhttp.status == 405) {
+ //duplicate vote
+ callback({
+ successType: 0,
+ statusCode: xmlhttp.status
+ });
+ } else if (error) {
+ //error while connect
+ callback({
+ successType: -1,
+ statusCode: xmlhttp.status
+ });
+ }
+ })
})
- })
}
function submitTimes(videoID, callback) {
- //get the video times from storage
- let sponsorTimeKey = 'sponsorTimes' + videoID;
- chrome.storage.sync.get([sponsorTimeKey, "userID"], function(result) {
- let sponsorTimes = result[sponsorTimeKey];
- let userID = result.userID;
-
- if (sponsorTimes != undefined && sponsorTimes.length > 0) {
- //submit these times
- for (let i = 0; i < sponsorTimes.length; i++) {
- //submit the sponsorTime
- sendRequestToServer("GET", "/api/postVideoSponsorTimes?videoID=" + videoID + "&startTime=" + sponsorTimes[i][0] + "&endTime=" + sponsorTimes[i][1]
- + "&userID=" + userID, function(xmlhttp, error) {
- if (xmlhttp.readyState == 4 && !error) {
- callback({
- statusCode: xmlhttp.status
- });
-
- if (xmlhttp.status == 200) {
- //add these to the storage log
- chrome.storage.sync.get(["sponsorTimesContributed"], function(result) {
- let currentContributionAmount = 0;
- if (result.sponsorTimesContributed != undefined) {
- //current contribution amount is known
- currentContributionAmount = result.sponsorTimesContributed;
- }
-
- //save the amount contributed
- chrome.storage.sync.set({"sponsorTimesContributed": currentContributionAmount + sponsorTimes.length});
+ //get the video times from storage
+ let sponsorTimeKey = 'sponsorTimes' + videoID;
+ chrome.storage.sync.get([sponsorTimeKey, "userID"], function(result) {
+ let sponsorTimes = result[sponsorTimeKey];
+ let userID = result.userID;
+
+ if (sponsorTimes != undefined && sponsorTimes.length > 0) {
+ //submit these times
+ for (let i = 0; i < sponsorTimes.length; i++) {
+ //submit the sponsorTime
+ sendRequestToServer("GET", "/api/postVideoSponsorTimes?videoID=" + videoID + "&startTime=" + sponsorTimes[i][0] + "&endTime=" + sponsorTimes[i][1]
+ + "&userID=" + userID, function(xmlhttp, error) {
+ if (xmlhttp.readyState == 4 && !error) {
+ callback({
+ statusCode: xmlhttp.status
+ });
+
+ if (xmlhttp.status == 200) {
+ //add these to the storage log
+ chrome.storage.sync.get(["sponsorTimesContributed"], function(result) {
+ let currentContributionAmount = 0;
+ if (result.sponsorTimesContributed != undefined) {
+ //current contribution amount is known
+ currentContributionAmount = result.sponsorTimesContributed;
+ }
+
+ //save the amount contributed
+ chrome.storage.sync.set({"sponsorTimesContributed": currentContributionAmount + sponsorTimes.length});
+ });
+ }
+ } else if (error) {
+ callback({
+ statusCode: -1
+ });
+ }
});
- }
- } else if (error) {
- callback({
- statusCode: -1
- });
}
- });
- }
- }
- });
+ }
+ });
}
function sendRequestToServer(type, address, callback) {
- let xmlhttp = new XMLHttpRequest();
+ let xmlhttp = new XMLHttpRequest();
- xmlhttp.open(type, serverAddress + address, true);
+ xmlhttp.open(type, serverAddress + address, true);
- if (callback != undefined) {
- xmlhttp.onreadystatechange = function () {
- callback(xmlhttp, false);
- };
+ if (callback != undefined) {
+ xmlhttp.onreadystatechange = function () {
+ callback(xmlhttp, false);
+ };
- xmlhttp.onerror = function(ev) {
- callback(xmlhttp, true);
- };
- }
+ xmlhttp.onerror = function(ev) {
+ callback(xmlhttp, true);
+ };
+ }
- //submit this request
- xmlhttp.send();
+ //submit this request
+ xmlhttp.send();
}
function generateUUID(length = 36) {
- let charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
- let result = "";
- let isOpera = Object.prototype.toString.call(window.opera) == '[object Opera]';
- if (window.crypto && window.crypto.getRandomValues) {
- values = new Uint32Array(length);
- window.crypto.getRandomValues(values);
- for (i = 0; i < length; i++) {
- result += charset[values[i] % charset.length];
- }
- return result;
- } else {
- for (let i = 0; i < length; i++) {
- result += charset[Math.floor(Math.random() * charset.length)];
+ let charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
+ let result = "";
+ let isOpera = Object.prototype.toString.call(window.opera) == '[object Opera]';
+ if (window.crypto && window.crypto.getRandomValues) {
+ values = new Uint32Array(length);
+ window.crypto.getRandomValues(values);
+ for (i = 0; i < length; i++) {
+ result += charset[values[i] % charset.length];
+ }
+ return result;
+ } else {
+ for (let i = 0; i < length; i++) {
+ result += charset[Math.floor(Math.random() * charset.length)];
+ }
+ return result;
}
- return result;
- }
}
diff --git a/content.js b/content.js
index dada9ed0..bd869678 100644
--- a/content.js
+++ b/content.js
@@ -34,7 +34,7 @@ var channelWhitelisted = false;
var previewBar;
if (id = getYouTubeVideoID(document.URL)) { // Direct Links
- videoIDChange(id);
+ videoIDChange(id);
}
//the last time looked at (used to see if this time is in the interval)
@@ -68,1001 +68,1001 @@ var popupInitialised = false;
//should view counts be tracked
var trackViewCount = false;
chrome.storage.sync.get(["trackViewCount"], function(result) {
- let trackViewCountStorage = result.trackViewCount;
- if (trackViewCountStorage != undefined) {
- trackViewCount = trackViewCountStorage;
- } else {
- trackViewCount = true;
- }
+ let trackViewCountStorage = result.trackViewCount;
+ if (trackViewCountStorage != undefined) {
+ trackViewCount = trackViewCountStorage;
+ } else {
+ trackViewCount = true;
+ }
});
//if the notice should not be shown
//happens when the user click's the "Don't show notice again" button
var dontShowNotice = false;
chrome.storage.sync.get(["dontShowNoticeAgain"], function(result) {
- let dontShowNoticeAgain = result.dontShowNoticeAgain;
- if (dontShowNoticeAgain != undefined) {
- dontShowNotice = dontShowNoticeAgain;
- }
+ let dontShowNoticeAgain = result.dontShowNoticeAgain;
+ if (dontShowNoticeAgain != undefined) {
+ dontShowNotice = dontShowNoticeAgain;
+ }
});
//get messages from the background script and the popup
chrome.runtime.onMessage.addListener(messageListener);
function messageListener(request, sender, sendResponse) {
- //messages from popup script
+ //messages from popup script
- if (request.message == "update") {
- if(id = getYouTubeVideoID(document.URL)){
- videoIDChange(id);
- } else {
- resetValues();
- }
- }
+ if (request.message == "update") {
+ if(id = getYouTubeVideoID(document.URL)){
+ videoIDChange(id);
+ } else {
+ resetValues();
+ }
+ }
- if (request.message == "sponsorStart") {
- sponsorMessageStarted(sendResponse);
- }
+ if (request.message == "sponsorStart") {
+ sponsorMessageStarted(sendResponse);
+ }
- if (request.message == "sponsorDataChanged") {
- updateSponsorTimesSubmitting();
- }
+ if (request.message == "sponsorDataChanged") {
+ updateSponsorTimesSubmitting();
+ }
- if (request.message == "isInfoFound") {
- //send the sponsor times along with if it's found
- sendResponse({
- found: sponsorDataFound,
- sponsorTimes: sponsorTimes,
- hiddenSponsorTimes: hiddenSponsorTimes,
- UUIDs: UUIDs
- });
-
- if (popupInitialised && document.getElementById("sponsorBlockPopupContainer") != null) {
- //the popup should be closed now that another is opening
- closeInfoMenu();
- }
-
- popupInitialised = true;
- }
+ if (request.message == "isInfoFound") {
+ //send the sponsor times along with if it's found
+ sendResponse({
+ found: sponsorDataFound,
+ sponsorTimes: sponsorTimes,
+ hiddenSponsorTimes: hiddenSponsorTimes,
+ UUIDs: UUIDs
+ });
+
+ if (popupInitialised && document.getElementById("sponsorBlockPopupContainer") != null) {
+ //the popup should be closed now that another is opening
+ closeInfoMenu();
+ }
+
+ popupInitialised = true;
+ }
- if (request.message == "getVideoID") {
- sendResponse({
- videoID: getYouTubeVideoID(document.URL)
- })
- }
+ if (request.message == "getVideoID") {
+ sendResponse({
+ videoID: getYouTubeVideoID(document.URL)
+ })
+ }
- if (request.message == "skipToTime") {
- v.currentTime = request.time;
- }
+ if (request.message == "skipToTime") {
+ v.currentTime = request.time;
+ }
- if (request.message == "getCurrentTime") {
- sendResponse({
- currentTime: v.currentTime
- });
- }
+ if (request.message == "getCurrentTime") {
+ sendResponse({
+ currentTime: v.currentTime
+ });
+ }
- if (request.message == "getChannelURL") {
- sendResponse({
- channelURL: channelURL
- })
- }
+ if (request.message == "getChannelURL") {
+ sendResponse({
+ channelURL: channelURL
+ })
+ }
- if (request.message == "isChannelWhitelisted") {
- sendResponse({
- value: channelWhitelisted
- })
- }
+ if (request.message == "isChannelWhitelisted") {
+ sendResponse({
+ value: channelWhitelisted
+ })
+ }
- if (request.message == "whitelistChange") {
- channelWhitelisted = request.value;
- sponsorsLookup(getYouTubeVideoID(document.URL));
- }
+ if (request.message == "whitelistChange") {
+ channelWhitelisted = request.value;
+ sponsorsLookup(getYouTubeVideoID(document.URL));
+ }
- if (request.message == "showNoticeAgain") {
- dontShowNotice = false;
- }
+ if (request.message == "showNoticeAgain") {
+ dontShowNotice = false;
+ }
- if (request.message == "changeStartSponsorButton") {
- changeStartSponsorButton(request.showStartSponsor, request.uploadButtonVisible);
- }
+ if (request.message == "changeStartSponsorButton") {
+ changeStartSponsorButton(request.showStartSponsor, request.uploadButtonVisible);
+ }
- if (request.message == "changeVideoPlayerControlsVisibility") {
- hideVideoPlayerControls = request.value;
+ if (request.message == "changeVideoPlayerControlsVisibility") {
+ hideVideoPlayerControls = request.value;
- updateVisibilityOfPlayerControlsButton();
- } else if (request.message == "changeInfoButtonPlayerControlsVisibility") {
- hideInfoButtonPlayerControls = request.value;
+ updateVisibilityOfPlayerControlsButton();
+ } else if (request.message == "changeInfoButtonPlayerControlsVisibility") {
+ hideInfoButtonPlayerControls = request.value;
- updateVisibilityOfPlayerControlsButton();
- } else if (request.message == "changeDeleteButtonPlayerControlsVisibility") {
- hideDeleteButtonPlayerControls = request.value;
+ updateVisibilityOfPlayerControlsButton();
+ } else if (request.message == "changeDeleteButtonPlayerControlsVisibility") {
+ hideDeleteButtonPlayerControls = request.value;
- updateVisibilityOfPlayerControlsButton();
- }
+ updateVisibilityOfPlayerControlsButton();
+ }
- if (request.message == "trackViewCount") {
- trackViewCount = request.value;
- }
+ if (request.message == "trackViewCount") {
+ trackViewCount = request.value;
+ }
}
//check for hotkey pressed
document.onkeydown = function(e){
- e = e || window.event;
- var key = e.which || e.keyCode;
-
- let video = document.getElementById("movie_player");
-
- //is the video in focus, otherwise they could be typing a comment
- if (document.activeElement === video) {
- if(key == 186){
- //semicolon
- startSponsorClicked();
- } else if (key == 222) {
- //single quote
- submitSponsorTimes();
+ e = e || window.event;
+ var key = e.which || e.keyCode;
+
+ let video = document.getElementById("movie_player");
+
+ //is the video in focus, otherwise they could be typing a comment
+ if (document.activeElement === video) {
+ if(key == 186){
+ //semicolon
+ startSponsorClicked();
+ } else if (key == 222) {
+ //single quote
+ submitSponsorTimes();
+ }
}
- }
}
function resetValues() {
- //reset last sponsor times
- lastTime = -1;
+ //reset last sponsor times
+ lastTime = -1;
- //reset sponsor times
- sponsorTimes = null;
- UUIDs = null;
- sponsorVideoID = id;
- sponsorLookupRetries = 0;
+ //reset sponsor times
+ sponsorTimes = null;
+ UUIDs = null;
+ sponsorVideoID = id;
+ sponsorLookupRetries = 0;
- //empty the preview bar
- previewBar.set([], [], 0);
+ //empty the preview bar
+ previewBar.set([], [], 0);
- //reset sponsor data found check
- sponsorDataFound = false;
+ //reset sponsor data found check
+ sponsorDataFound = false;
}
function videoIDChange(id) {
- //not a url change
- if (sponsorVideoID == id) return;
-
- if (previewBar == null) {
- //create it
- let progressBar = document.getElementsByClassName("ytp-progress-bar-container")[0] || document.getElementsByClassName("no-model cue-range-markers")[0];
- previewBar = new PreviewBar(progressBar);
- }
-
- //warn them if they had unsubmitted times
- if (previousVideoID != null) {
- //get the sponsor times from storage
- let sponsorTimeKey = 'sponsorTimes' + previousVideoID;
- chrome.storage.sync.get([sponsorTimeKey], function(result) {
- let sponsorTimes = result[sponsorTimeKey];
-
- if (sponsorTimes != undefined && sponsorTimes.length > 0) {
- //warn them that they have unsubmitted sponsor times
- chrome.runtime.sendMessage({
- message: "alertPrevious",
- previousVideoID: previousVideoID
- })
- }
-
- //set the previous video id to the currentID
- previousVideoID = id;
- });
- } else {
- //set the previous id now, don't wait for chrome.storage.get
- previousVideoID = id;
- }
-
- //close popup
- closeInfoMenu();
-
- resetValues();
-
- //see if there is a video start time
- youtubeVideoStartTime = getYouTubeVideoStartTime(document.URL);
-
- sponsorsLookup(id);
-
- //make sure everything is properly added
- updateVisibilityOfPlayerControlsButton(true);
-
- //reset sponsor times submitting
- sponsorTimesSubmitting = [];
-
- //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 != null && sponsorTimes.length > 0 && sponsorTimes[sponsorTimes.length - 1].length >= 2) {
- changeStartSponsorButton(true, true);
- } else if (sponsorTimes != null && sponsorTimes.length > 0 && sponsorTimes[sponsorTimes.length - 1].length < 2) {
- changeStartSponsorButton(false, true);
- } else {
- changeStartSponsorButton(true, false);
- }
-
- //see if this data should be saved in the sponsorTimesSubmitting variable
- if (sponsorTimes != undefined && sponsorTimes.length > 0) {
- sponsorTimesSubmitting = sponsorTimes;
- }
- }
- });
+ //not a url change
+ if (sponsorVideoID == id) return;
- //see if video controls buttons should be added
- chrome.storage.sync.get(["hideVideoPlayerControls"], function(result) {
- if (result.hideVideoPlayerControls != undefined) {
- hideVideoPlayerControls = result.hideVideoPlayerControls;
+ if (previewBar == null) {
+ //create it
+ let progressBar = document.getElementsByClassName("ytp-progress-bar-container")[0] || document.getElementsByClassName("no-model cue-range-markers")[0];
+ previewBar = new PreviewBar(progressBar);
}
- updateVisibilityOfPlayerControlsButton();
- });
- chrome.storage.sync.get(["hideInfoButtonPlayerControls"], function(result) {
- if (result.hideInfoButtonPlayerControls != undefined) {
- hideInfoButtonPlayerControls = result.hideInfoButtonPlayerControls;
+ //warn them if they had unsubmitted times
+ if (previousVideoID != null) {
+ //get the sponsor times from storage
+ let sponsorTimeKey = 'sponsorTimes' + previousVideoID;
+ chrome.storage.sync.get([sponsorTimeKey], function(result) {
+ let sponsorTimes = result[sponsorTimeKey];
+
+ if (sponsorTimes != undefined && sponsorTimes.length > 0) {
+ //warn them that they have unsubmitted sponsor times
+ chrome.runtime.sendMessage({
+ message: "alertPrevious",
+ previousVideoID: previousVideoID
+ })
+ }
+
+ //set the previous video id to the currentID
+ previousVideoID = id;
+ });
+ } else {
+ //set the previous id now, don't wait for chrome.storage.get
+ previousVideoID = id;
}
+
+ //close popup
+ closeInfoMenu();
+
+ resetValues();
+
+ //see if there is a video start time
+ youtubeVideoStartTime = getYouTubeVideoStartTime(document.URL);
+
+ sponsorsLookup(id);
+
+ //make sure everything is properly added
+ updateVisibilityOfPlayerControlsButton(true);
+
+ //reset sponsor times submitting
+ sponsorTimesSubmitting = [];
+
+ //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 != null && sponsorTimes.length > 0 && sponsorTimes[sponsorTimes.length - 1].length >= 2) {
+ changeStartSponsorButton(true, true);
+ } else if (sponsorTimes != null && sponsorTimes.length > 0 && sponsorTimes[sponsorTimes.length - 1].length < 2) {
+ changeStartSponsorButton(false, true);
+ } else {
+ changeStartSponsorButton(true, false);
+ }
+
+ //see if this data should be saved in the sponsorTimesSubmitting variable
+ if (sponsorTimes != undefined && sponsorTimes.length > 0) {
+ sponsorTimesSubmitting = sponsorTimes;
+ }
+ }
+ });
- updateVisibilityOfPlayerControlsButton();
- });
- chrome.storage.sync.get(["hideDeleteButtonPlayerControls"], function(result) {
- if (result.hideDeleteButtonPlayerControls != undefined) {
- hideDeleteButtonPlayerControls = result.hideDeleteButtonPlayerControls;
- }
+ //see if video controls buttons should be added
+ chrome.storage.sync.get(["hideVideoPlayerControls"], function(result) {
+ if (result.hideVideoPlayerControls != undefined) {
+ hideVideoPlayerControls = result.hideVideoPlayerControls;
+ }
+
+ updateVisibilityOfPlayerControlsButton();
+ });
+ chrome.storage.sync.get(["hideInfoButtonPlayerControls"], function(result) {
+ if (result.hideInfoButtonPlayerControls != undefined) {
+ hideInfoButtonPlayerControls = result.hideInfoButtonPlayerControls;
+ }
- updateVisibilityOfPlayerControlsButton(false);
- });
+ updateVisibilityOfPlayerControlsButton();
+ });
+ chrome.storage.sync.get(["hideDeleteButtonPlayerControls"], function(result) {
+ if (result.hideDeleteButtonPlayerControls != undefined) {
+ hideDeleteButtonPlayerControls = result.hideDeleteButtonPlayerControls;
+ }
+
+ updateVisibilityOfPlayerControlsButton(false);
+ });
}
function sponsorsLookup(id) {
- v = document.querySelector('video') // Youtube video player
- //there is no video here
- if (v == null) {
- setTimeout(() => sponsorsLookup(id), 100);
- return;
- }
-
- if (!durationListenerSetUp) {
- durationListenerSetUp = true;
-
- //wait until it is loaded
- v.addEventListener('durationchange', updatePreviewBar);
- }
-
- //check database for sponsor times
- sendRequestToServer('GET', "/api/getVideoSponsorTimes?videoID=" + id, function(xmlhttp) {
- if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
- sponsorDataFound = true;
-
- sponsorTimes = JSON.parse(xmlhttp.responseText).sponsorTimes;
- UUIDs = JSON.parse(xmlhttp.responseText).UUIDs;
-
- //update the preview bar
- //leave the type blank for now until categories are added
- if (lastPreviewBarUpdate == id || (lastPreviewBarUpdate == null && !isNaN(v.duration))) {
- //set it now
- //otherwise the listener can handle it
- updatePreviewBar();
- }
-
- getChannelID();
-
- sponsorLookupRetries = 0;
- } else if (xmlhttp.readyState == 4 && xmlhttp.status == 404) {
- sponsorDataFound = false;
-
- //check if this video was uploaded recently
- //use the invidious api to get the time published
- sendRequestToCustomServer('GET', "https://invidio.us/api/v1/videos/" + id, function(xmlhttp, error) {
- if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
- let unixTimePublished = JSON.parse(xmlhttp.responseText).published;
-
- //if less than 3 days old
- if ((Date.now() / 1000) - unixTimePublished < 259200) {
- setTimeout(() => sponsorsLookup(id), 10000);
- }
- }
- });
+ v = document.querySelector('video') // Youtube video player
+ //there is no video here
+ if (v == null) {
+ setTimeout(() => sponsorsLookup(id), 100);
+ return;
+ }
- sponsorLookupRetries = 0;
- } else if (xmlhttp.readyState == 4 && sponsorLookupRetries < 90) {
- //some error occurred, try again in a second
- setTimeout(() => sponsorsLookup(id), 1000);
+ if (!durationListenerSetUp) {
+ durationListenerSetUp = true;
- sponsorLookupRetries++;
+ //wait until it is loaded
+ v.addEventListener('durationchange', updatePreviewBar);
}
- });
+
+ //check database for sponsor times
+ sendRequestToServer('GET', "/api/getVideoSponsorTimes?videoID=" + id, function(xmlhttp) {
+ if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
+ sponsorDataFound = true;
+
+ sponsorTimes = JSON.parse(xmlhttp.responseText).sponsorTimes;
+ UUIDs = JSON.parse(xmlhttp.responseText).UUIDs;
+
+ //update the preview bar
+ //leave the type blank for now until categories are added
+ if (lastPreviewBarUpdate == id || (lastPreviewBarUpdate == null && !isNaN(v.duration))) {
+ //set it now
+ //otherwise the listener can handle it
+ updatePreviewBar();
+ }
+
+ getChannelID();
+
+ sponsorLookupRetries = 0;
+ } else if (xmlhttp.readyState == 4 && xmlhttp.status == 404) {
+ sponsorDataFound = false;
+
+ //check if this video was uploaded recently
+ //use the invidious api to get the time published
+ sendRequestToCustomServer('GET', "https://invidio.us/api/v1/videos/" + id, function(xmlhttp, error) {
+ if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
+ let unixTimePublished = JSON.parse(xmlhttp.responseText).published;
+
+ //if less than 3 days old
+ if ((Date.now() / 1000) - unixTimePublished < 259200) {
+ setTimeout(() => sponsorsLookup(id), 10000);
+ }
+ }
+ });
+
+ sponsorLookupRetries = 0;
+ } else if (xmlhttp.readyState == 4 && sponsorLookupRetries < 90) {
+ //some error occurred, try again in a second
+ setTimeout(() => sponsorsLookup(id), 1000);
+
+ sponsorLookupRetries++;
+ }
+ });
- //add the event to run on the videos "ontimeupdate"
- v.ontimeupdate = function () {
- sponsorCheck();
- };
+ //add the event to run on the videos "ontimeupdate"
+ v.ontimeupdate = function () {
+ sponsorCheck();
+ };
}
function updatePreviewBar() {
- previewBar.set(sponsorTimes, [], v.duration);
+ previewBar.set(sponsorTimes, [], v.duration);
- //update last video id
- lastPreviewBarUpdate = getYouTubeVideoID(document.URL);
+ //update last video id
+ lastPreviewBarUpdate = getYouTubeVideoID(document.URL);
}
function getChannelID() {
- //get channel id
- let channelContainers = document.querySelectorAll("#owner-name");
- let channelURLContainer = null;
+ //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;
+ for (let i = 0; i < channelContainers.length; i++) {
+ if (channelContainers[i].firstElementChild != null) {
+ channelURLContainer = channelContainers[i].firstElementChild;
+ }
}
- }
- if (channelContainers.length == 0) {
- //old YouTube theme
- channelContainers = document.getElementsByClassName("yt-user-info");
- if (channelContainers.length != 0) {
- channelURLContainer = channelContainers[0].firstElementChild;
+ if (channelContainers.length == 0) {
+ //old YouTube theme
+ channelContainers = document.getElementsByClassName("yt-user-info");
+ if (channelContainers.length != 0) {
+ channelURLContainer = channelContainers[0].firstElementChild;
+ }
}
- }
- if (channelURLContainer == null) {
- //try later
- setTimeout(getChannelID, 100);
- return;
- }
+ if (channelURLContainer == null) {
+ //try later
+ setTimeout(getChannelID, 100);
+ return;
+ }
- channelURL = channelURLContainer.getAttribute("href");
+ channelURL = channelURLContainer.getAttribute("href");
- //see if this is a whitelisted channel
- chrome.storage.sync.get(["whitelistedChannels"], function(result) {
- let whitelistedChannels = result.whitelistedChannels;
+ //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 = [];
+ if (whitelistedChannels != undefined && whitelistedChannels.includes(channelURL)) {
+ //reset sponsor times to nothing
+ sponsorTimes = [];
+ UUIDs = [];
- channelWhitelisted = true;
- }
- });
+ channelWhitelisted = true;
+ }
+ });
}
//video skipping
function sponsorCheck() {
- let skipHappened = false;
-
- if (sponsorTimes != null) {
- //see if any sponsor start time was just passed
- for (let i = 0; i < sponsorTimes.length; i++) {
- //if something was skipped
- if (checkSponsorTime(sponsorTimes, i, true)) {
- skipHappened = true;
- break;
- }
+ let skipHappened = false;
+
+ if (sponsorTimes != null) {
+ //see if any sponsor start time was just passed
+ for (let i = 0; i < sponsorTimes.length; i++) {
+ //if something was skipped
+ if (checkSponsorTime(sponsorTimes, i, true)) {
+ skipHappened = true;
+ break;
+ }
+ }
}
- }
-
- if (!skipHappened) {
- //check for the "preview" sponsors (currently edited by this user)
- for (let i = 0; i < sponsorTimesSubmitting.length; i++) {
- //must be a finished sponsor and be valid
- if (sponsorTimesSubmitting[i].length > 1 && sponsorTimesSubmitting[i][1] > sponsorTimesSubmitting[i][0]) {
- checkSponsorTime(sponsorTimesSubmitting, i, false);
- }
+
+ if (!skipHappened) {
+ //check for the "preview" sponsors (currently edited by this user)
+ for (let i = 0; i < sponsorTimesSubmitting.length; i++) {
+ //must be a finished sponsor and be valid
+ if (sponsorTimesSubmitting[i].length > 1 && sponsorTimesSubmitting[i][1] > sponsorTimesSubmitting[i][0]) {
+ checkSponsorTime(sponsorTimesSubmitting, i, false);
+ }
+ }
}
- }
- //don't keep track until they are loaded in
- if (sponsorTimes != null || sponsorTimesSubmitting.length > 0) {
- lastTime = v.currentTime;
- }
+ //don't keep track until they are loaded in
+ if (sponsorTimes != null || sponsorTimesSubmitting.length > 0) {
+ lastTime = v.currentTime;
+ }
}
function checkSponsorTime(sponsorTimes, index, openNotice) {
- //this means part of the video was just skipped
- if (Math.abs(v.currentTime - lastTime) > 1 && lastTime != -1) {
- //make lastTime as if the video was playing normally
- lastTime = v.currentTime - 0.0001;
- }
+ //this means part of the video was just skipped
+ if (Math.abs(v.currentTime - lastTime) > 1 && lastTime != -1) {
+ //make lastTime as if the video was playing normally
+ lastTime = v.currentTime - 0.0001;
+ }
- if (checkIfTimeToSkip(v.currentTime, sponsorTimes[index][0]) && !hiddenSponsorTimes.includes(index)) {
- //skip it
- skipToTime(v, index, sponsorTimes, openNotice);
+ if (checkIfTimeToSkip(v.currentTime, sponsorTimes[index][0]) && !hiddenSponsorTimes.includes(index)) {
+ //skip it
+ skipToTime(v, index, sponsorTimes, openNotice);
- //something was skipped
- return true;
- }
+ //something was skipped
+ return true;
+ }
- return false;
+ return false;
}
function checkIfTimeToSkip(currentVideoTime, startTime) {
- //If the sponsor time is in between these times, skip it
- //Checks if the last time skipped to is not too close to now, to make sure not to get too many
- // sponsor times in a row (from one troll)
- //the last term makes 0 second start times possible only if the video is not setup to start at a different time from zero
- return (Math.abs(currentVideoTime - startTime) < 3 && startTime >= lastTime && startTime <= currentVideoTime) ||
- (lastTime == -1 && startTime == 0 && youtubeVideoStartTime == null)
+ //If the sponsor time is in between these times, skip it
+ //Checks if the last time skipped to is not too close to now, to make sure not to get too many
+ // sponsor times in a row (from one troll)
+ //the last term makes 0 second start times possible only if the video is not setup to start at a different time from zero
+ return (Math.abs(currentVideoTime - startTime) < 3 && startTime >= lastTime && startTime <= currentVideoTime) ||
+ (lastTime == -1 && startTime == 0 && youtubeVideoStartTime == null)
}
//skip fromt he start time to the end time for a certain index sponsor time
function skipToTime(v, index, sponsorTimes, openNotice) {
- v.currentTime = sponsorTimes[index][1];
+ v.currentTime = sponsorTimes[index][1];
- lastSponsorTimeSkipped = sponsorTimes[index][0];
+ lastSponsorTimeSkipped = sponsorTimes[index][0];
- let currentUUID = UUIDs[index];
- lastSponsorTimeSkippedUUID = currentUUID;
-
- if (openNotice) {
- //send out the message saying that a sponsor message was skipped
- if (!dontShowNotice) {
- new SkipNotice(this, currentUUID);
-
- //auto-upvote this sponsor
- if (trackViewCount) {
- vote(1, currentUUID, null);
- }
+ let currentUUID = UUIDs[index];
+ lastSponsorTimeSkippedUUID = currentUUID;
+
+ if (openNotice) {
+ //send out the message saying that a sponsor message was skipped
+ if (!dontShowNotice) {
+ new SkipNotice(this, currentUUID);
+
+ //auto-upvote this sponsor
+ if (trackViewCount) {
+ vote(1, currentUUID, null);
+ }
+ }
}
- }
- //send telemetry that a this sponsor was skipped happened
- if (trackViewCount) {
- sendRequestToServer("GET", "/api/viewedVideoSponsorTime?UUID=" + currentUUID);
- }
+ //send telemetry that a this sponsor was skipped happened
+ if (trackViewCount) {
+ sendRequestToServer("GET", "/api/viewedVideoSponsorTime?UUID=" + currentUUID);
+ }
}
function unskipSponsorTime(UUID) {
- if (sponsorTimes != null) {
- //add a tiny bit of time to make sure it is not skipped again
- v.currentTime = sponsorTimes[UUIDs.indexOf(UUID)][0] + 0.001;
- }
+ if (sponsorTimes != null) {
+ //add a tiny bit of time to make sure it is not skipped again
+ v.currentTime = sponsorTimes[UUIDs.indexOf(UUID)][0] + 0.001;
+ }
}
function reskipSponsorTime(UUID) {
- if (sponsorTimes != null) {
- //add a tiny bit of time to make sure it is not skipped again
- v.currentTime = sponsorTimes[UUIDs.indexOf(UUID)][1];
- }
+ if (sponsorTimes != null) {
+ //add a tiny bit of time to make sure it is not skipped again
+ v.currentTime = sponsorTimes[UUIDs.indexOf(UUID)][1];
+ }
}
//Adds a sponsorship starts button to the player controls
function addPlayerControlsButton() {
- if (document.getElementById("startSponsorButton") != null) {
- //it's already added
- return;
- }
-
- let startSponsorButton = document.createElement("button");
- startSponsorButton.id = "startSponsorButton";
- startSponsorButton.className = "ytp-button playerButton";
- startSponsorButton.setAttribute("title", chrome.i18n.getMessage("sponsorStart"));
- startSponsorButton.addEventListener("click", startSponsorClicked);
-
- let startSponsorImage = document.createElement("img");
- startSponsorImage.id = "startSponsorImage";
- startSponsorImage.className = "playerButtonImage";
- startSponsorImage.src = chrome.extension.getURL("icons/PlayerStartIconSponsorBlocker256px.png");
-
- //add the image to the button
- startSponsorButton.appendChild(startSponsorImage);
-
- let controls = document.getElementsByClassName("ytp-right-controls");
- let referenceNode = controls[controls.length - 1];
-
- if (referenceNode == undefined) {
- //page not loaded yet
- setTimeout(addPlayerControlsButton, 100);
- return;
- }
-
- referenceNode.prepend(startSponsorButton);
+ if (document.getElementById("startSponsorButton") != null) {
+ //it's already added
+ return;
+ }
+
+ let startSponsorButton = document.createElement("button");
+ startSponsorButton.id = "startSponsorButton";
+ startSponsorButton.className = "ytp-button playerButton";
+ startSponsorButton.setAttribute("title", chrome.i18n.getMessage("sponsorStart"));
+ startSponsorButton.addEventListener("click", startSponsorClicked);
+
+ let startSponsorImage = document.createElement("img");
+ startSponsorImage.id = "startSponsorImage";
+ startSponsorImage.className = "playerButtonImage";
+ startSponsorImage.src = chrome.extension.getURL("icons/PlayerStartIconSponsorBlocker256px.png");
+
+ //add the image to the button
+ startSponsorButton.appendChild(startSponsorImage);
+
+ let controls = document.getElementsByClassName("ytp-right-controls");
+ let referenceNode = controls[controls.length - 1];
+
+ if (referenceNode == undefined) {
+ //page not loaded yet
+ setTimeout(addPlayerControlsButton, 100);
+ return;
+ }
+
+ referenceNode.prepend(startSponsorButton);
}
function removePlayerControlsButton() {
- document.getElementById("startSponsorButton").style.display = "none";
- document.getElementById("submitButton").style.display = "none";
+ document.getElementById("startSponsorButton").style.display = "none";
+ document.getElementById("submitButton").style.display = "none";
}
//adds or removes the player controls button to what it should be
function updateVisibilityOfPlayerControlsButton() {
- //not on a proper video yet
- if (!getYouTubeVideoID(document.URL)) return;
-
- addPlayerControlsButton();
- addInfoButton();
- addDeleteButton();
- addSubmitButton();
- if (hideVideoPlayerControls) {
- removePlayerControlsButton();
- }
- if (hideInfoButtonPlayerControls) {
- document.getElementById("infoButton").style.display = "none";
- }
- if (hideDeleteButtonPlayerControls) {
- document.getElementById("deleteButton").style.display = "none";
- }
+ //not on a proper video yet
+ if (!getYouTubeVideoID(document.URL)) return;
+
+ addPlayerControlsButton();
+ addInfoButton();
+ addDeleteButton();
+ addSubmitButton();
+ if (hideVideoPlayerControls) {
+ removePlayerControlsButton();
+ }
+ if (hideInfoButtonPlayerControls) {
+ document.getElementById("infoButton").style.display = "none";
+ }
+ if (hideDeleteButtonPlayerControls) {
+ document.getElementById("deleteButton").style.display = "none";
+ }
}
function startSponsorClicked() {
- //it can't update to this info yet
- closeInfoMenu();
-
- toggleStartSponsorButton();
-
- //send back current time with message
- chrome.runtime.sendMessage({
- message: "addSponsorTime",
- time: v.currentTime,
- videoID: getYouTubeVideoID(document.URL)
- }, function(response) {
- //see if the sponsorTimesSubmitting needs to be updated
- updateSponsorTimesSubmitting();
- });
+ //it can't update to this info yet
+ closeInfoMenu();
+
+ toggleStartSponsorButton();
+
+ //send back current time with message
+ chrome.runtime.sendMessage({
+ message: "addSponsorTime",
+ time: v.currentTime,
+ videoID: getYouTubeVideoID(document.URL)
+ }, function(response) {
+ //see if the sponsorTimesSubmitting needs to be updated
+ updateSponsorTimesSubmitting();
+ });
}
function updateSponsorTimesSubmitting() {
- chrome.runtime.sendMessage({
- message: "getSponsorTimes",
- videoID: getYouTubeVideoID(document.URL)
- }, function(response) {
- if (response != undefined) {
- let sponsorTimes = response.sponsorTimes;
-
- //see if this data should be saved in the sponsorTimesSubmitting variable
- if (sponsorTimes != undefined) {
- sponsorTimesSubmitting = sponsorTimes;
- }
- }
- });
+ chrome.runtime.sendMessage({
+ message: "getSponsorTimes",
+ videoID: getYouTubeVideoID(document.URL)
+ }, function(response) {
+ if (response != undefined) {
+ let sponsorTimes = response.sponsorTimes;
+
+ //see if this data should be saved in the sponsorTimesSubmitting variable
+ if (sponsorTimes != undefined) {
+ sponsorTimesSubmitting = sponsorTimes;
+ }
+ }
+ });
}
function changeStartSponsorButton(showStartSponsor, uploadButtonVisible) {
- //if it isn't visible, there is no data
- if (uploadButtonVisible && !hideDeleteButtonPlayerControls) {
- document.getElementById("deleteButton").style.display = "unset";
- } else {
- document.getElementById("deleteButton").style.display = "none";
- }
-
- if (showStartSponsor) {
- showingStartSponsor = true;
- document.getElementById("startSponsorImage").src = chrome.extension.getURL("icons/PlayerStartIconSponsorBlocker256px.png");
- document.getElementById("startSponsorButton").setAttribute("title", chrome.i18n.getMessage("sponsorStart"));
-
- if (document.getElementById("startSponsorImage").style.display != "none" && uploadButtonVisible && !hideInfoButtonPlayerControls) {
- document.getElementById("submitButton").style.display = "unset";
- } else if (!uploadButtonVisible) {
- //disable submit button
- document.getElementById("submitButton").style.display = "none";
+ //if it isn't visible, there is no data
+ if (uploadButtonVisible && !hideDeleteButtonPlayerControls) {
+ document.getElementById("deleteButton").style.display = "unset";
+ } else {
+ document.getElementById("deleteButton").style.display = "none";
}
- } else {
- showingStartSponsor = false;
- document.getElementById("startSponsorImage").src = chrome.extension.getURL("icons/PlayerStopIconSponsorBlocker256px.png");
- document.getElementById("startSponsorButton").setAttribute("title", chrome.i18n.getMessage("sponsorEND"));
- //disable submit button
- document.getElementById("submitButton").style.display = "none";
- }
+ if (showStartSponsor) {
+ showingStartSponsor = true;
+ document.getElementById("startSponsorImage").src = chrome.extension.getURL("icons/PlayerStartIconSponsorBlocker256px.png");
+ document.getElementById("startSponsorButton").setAttribute("title", chrome.i18n.getMessage("sponsorStart"));
+
+ if (document.getElementById("startSponsorImage").style.display != "none" && uploadButtonVisible && !hideInfoButtonPlayerControls) {
+ document.getElementById("submitButton").style.display = "unset";
+ } else if (!uploadButtonVisible) {
+ //disable submit button
+ document.getElementById("submitButton").style.display = "none";
+ }
+ } else {
+ showingStartSponsor = false;
+ document.getElementById("startSponsorImage").src = chrome.extension.getURL("icons/PlayerStopIconSponsorBlocker256px.png");
+ document.getElementById("startSponsorButton").setAttribute("title", chrome.i18n.getMessage("sponsorEND"));
+
+ //disable submit button
+ document.getElementById("submitButton").style.display = "none";
+ }
}
function toggleStartSponsorButton() {
- changeStartSponsorButton(!showingStartSponsor, true);
+ changeStartSponsorButton(!showingStartSponsor, true);
}
//shows the info button on the video player
function addInfoButton() {
- if (document.getElementById("infoButton") != null) {
- //it's already added
- return;
- }
+ if (document.getElementById("infoButton") != null) {
+ //it's already added
+ return;
+ }
- //make a submit button
- let infoButton = document.createElement("button");
- infoButton.id = "infoButton";
- infoButton.className = "ytp-button playerButton";
- infoButton.setAttribute("title", "Open SponsorBlock Popup");
- infoButton.addEventListener("click", openInfoMenu);
-
- let infoImage = document.createElement("img");
- infoImage.id = "infoButtonImage";
- infoImage.className = "playerButtonImage";
- infoImage.src = chrome.extension.getURL("icons/PlayerInfoIconSponsorBlocker256px.png");
-
- //add the image to the button
- infoButton.appendChild(infoImage);
-
- let controls = document.getElementsByClassName("ytp-right-controls");
- let referenceNode = controls[controls.length - 1];
-
- if (referenceNode == undefined) {
- //page not loaded yet
- setTimeout(addInfoButton, 100);
- return;
- }
-
- referenceNode.prepend(infoButton);
+ //make a submit button
+ let infoButton = document.createElement("button");
+ infoButton.id = "infoButton";
+ infoButton.className = "ytp-button playerButton";
+ infoButton.setAttribute("title", "Open SponsorBlock Popup");
+ infoButton.addEventListener("click", openInfoMenu);
+
+ let infoImage = document.createElement("img");
+ infoImage.id = "infoButtonImage";
+ infoImage.className = "playerButtonImage";
+ infoImage.src = chrome.extension.getURL("icons/PlayerInfoIconSponsorBlocker256px.png");
+
+ //add the image to the button
+ infoButton.appendChild(infoImage);
+
+ let controls = document.getElementsByClassName("ytp-right-controls");
+ let referenceNode = controls[controls.length - 1];
+
+ if (referenceNode == undefined) {
+ //page not loaded yet
+ setTimeout(addInfoButton, 100);
+ return;
+ }
+
+ referenceNode.prepend(infoButton);
}
//shows the delete button on the video player
function addDeleteButton() {
- if (document.getElementById("deleteButton") != null) {
- //it's already added
- return;
- }
+ if (document.getElementById("deleteButton") != null) {
+ //it's already added
+ return;
+ }
- //make a submit button
- let deleteButton = document.createElement("button");
- deleteButton.id = "deleteButton";
- deleteButton.className = "ytp-button playerButton";
- deleteButton.setAttribute("title", "Clear Sponsor Times");
- deleteButton.addEventListener("click", clearSponsorTimes);
- //hide it at the start
- deleteButton.style.display = "none";
-
- let deleteImage = document.createElement("img");
- deleteImage.id = "deleteButtonImage";
- deleteImage.className = "playerButtonImage";
- deleteImage.src = chrome.extension.getURL("icons/PlayerDeleteIconSponsorBlocker256px.png");
-
- //add the image to the button
- deleteButton.appendChild(deleteImage);
-
- let controls = document.getElementsByClassName("ytp-right-controls");
- let referenceNode = controls[controls.length - 1];
+ //make a submit button
+ let deleteButton = document.createElement("button");
+ deleteButton.id = "deleteButton";
+ deleteButton.className = "ytp-button playerButton";
+ deleteButton.setAttribute("title", "Clear Sponsor Times");
+ deleteButton.addEventListener("click", clearSponsorTimes);
+ //hide it at the start
+ deleteButton.style.display = "none";
+
+ let deleteImage = document.createElement("img");
+ deleteImage.id = "deleteButtonImage";
+ deleteImage.className = "playerButtonImage";
+ deleteImage.src = chrome.extension.getURL("icons/PlayerDeleteIconSponsorBlocker256px.png");
+
+ //add the image to the button
+ deleteButton.appendChild(deleteImage);
+
+ let controls = document.getElementsByClassName("ytp-right-controls");
+ let referenceNode = controls[controls.length - 1];
- if (referenceNode == undefined) {
- //page not loaded yet
- setTimeout(addDeleteButton, 100);
- return;
- }
+ if (referenceNode == undefined) {
+ //page not loaded yet
+ setTimeout(addDeleteButton, 100);
+ return;
+ }
- referenceNode.prepend(deleteButton);
+ referenceNode.prepend(deleteButton);
}
//shows the submit button on the video player
function addSubmitButton() {
- if (document.getElementById("submitButton") != null) {
- //it's already added
- return;
- }
+ if (document.getElementById("submitButton") != null) {
+ //it's already added
+ return;
+ }
- //make a submit button
- let submitButton = document.createElement("button");
- submitButton.id = "submitButton";
- submitButton.className = "ytp-button playerButton";
- submitButton.setAttribute("title", "Submit Sponsor Times");
- submitButton.addEventListener("click", submitSponsorTimes);
- //hide it at the start
- submitButton.style.display = "none";
-
- let submitImage = document.createElement("img");
- submitImage.id = "submitButtonImage";
- submitImage.className = "playerButtonImage";
- submitImage.src = chrome.extension.getURL("icons/PlayerUploadIconSponsorBlocker256px.png");
-
- //add the image to the button
- submitButton.appendChild(submitImage);
-
- let controls = document.getElementsByClassName("ytp-right-controls");
- let referenceNode = controls[controls.length - 1];
-
- if (referenceNode == undefined) {
- //page not loaded yet
- setTimeout(addSubmitButton, 100);
- return;
- }
+ //make a submit button
+ let submitButton = document.createElement("button");
+ submitButton.id = "submitButton";
+ submitButton.className = "ytp-button playerButton";
+ submitButton.setAttribute("title", "Submit Sponsor Times");
+ submitButton.addEventListener("click", submitSponsorTimes);
+ //hide it at the start
+ submitButton.style.display = "none";
+
+ let submitImage = document.createElement("img");
+ submitImage.id = "submitButtonImage";
+ submitImage.className = "playerButtonImage";
+ submitImage.src = chrome.extension.getURL("icons/PlayerUploadIconSponsorBlocker256px.png");
+
+ //add the image to the button
+ submitButton.appendChild(submitImage);
+
+ let controls = document.getElementsByClassName("ytp-right-controls");
+ let referenceNode = controls[controls.length - 1];
+
+ if (referenceNode == undefined) {
+ //page not loaded yet
+ setTimeout(addSubmitButton, 100);
+ return;
+ }
- referenceNode.prepend(submitButton);
+ referenceNode.prepend(submitButton);
}
function openInfoMenu() {
- if (document.getElementById("sponsorBlockPopupContainer") != null) {
- //it's already added
- return;
- }
-
- popupInitialised = false;
-
- //hide info button
- document.getElementById("infoButton").style.display = "none";
-
- sendRequestToCustomServer('GET', chrome.extension.getURL("popup.html"), function(xmlhttp) {
- if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
- var popup = document.createElement("div");
- popup.id = "sponsorBlockPopupContainer";
- popup.innerHTML = xmlhttp.responseText
-
- //close button
- let closeButton = document.createElement("div");
- closeButton.innerText = "Close Popup";
- closeButton.classList = "smallLink";
- closeButton.setAttribute("align", "center");
- closeButton.addEventListener("click", closeInfoMenu);
-
- //add the close button
- popup.prepend(closeButton);
+ if (document.getElementById("sponsorBlockPopupContainer") != null) {
+ //it's already added
+ return;
+ }
+
+ popupInitialised = false;
+
+ //hide info button
+ document.getElementById("infoButton").style.display = "none";
+
+ sendRequestToCustomServer('GET', chrome.extension.getURL("popup.html"), function(xmlhttp) {
+ if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
+ var popup = document.createElement("div");
+ popup.id = "sponsorBlockPopupContainer";
+ popup.innerHTML = xmlhttp.responseText
+
+ //close button
+ let closeButton = document.createElement("div");
+ closeButton.innerText = "Close Popup";
+ closeButton.classList = "smallLink";
+ closeButton.setAttribute("align", "center");
+ closeButton.addEventListener("click", closeInfoMenu);
+
+ //add the close button
+ popup.prepend(closeButton);
- let parentNode = document.getElementById("secondary");
- if (parentNode == null) {
- //old youtube theme
- parentNode = document.getElementById("watch7-sidebar-contents");
- }
+ let parentNode = document.getElementById("secondary");
+ if (parentNode == null) {
+ //old youtube theme
+ parentNode = document.getElementById("watch7-sidebar-contents");
+ }
- //make the logo source not 404
- //query selector must be used since getElementByID doesn't work on a node and this isn't added to the document yet
- let logo = popup.querySelector("#sponsorBlockPopupLogo");
- logo.src = chrome.extension.getURL("icons/LogoSponsorBlocker256px.png");
+ //make the logo source not 404
+ //query selector must be used since getElementByID doesn't work on a node and this isn't added to the document yet
+ let logo = popup.querySelector("#sponsorBlockPopupLogo");
+ logo.src = chrome.extension.getURL("icons/LogoSponsorBlocker256px.png");
- //remove the style sheet and font that are not necessary
- popup.querySelector("#sponorBlockPopupFont").remove();
- popup.querySelector("#sponorBlockStyleSheet").remove();
+ //remove the style sheet and font that are not necessary
+ popup.querySelector("#sponorBlockPopupFont").remove();
+ popup.querySelector("#sponorBlockStyleSheet").remove();
- parentNode.insertBefore(popup, parentNode.firstChild);
+ parentNode.insertBefore(popup, parentNode.firstChild);
- //run the popup init script
- runThePopup();
- }
- });
+ //run the popup init script
+ runThePopup();
+ }
+ });
}
function closeInfoMenu() {
- let popup = document.getElementById("sponsorBlockPopupContainer");
- if (popup != null) {
- popup.remove();
+ let popup = document.getElementById("sponsorBlockPopupContainer");
+ if (popup != null) {
+ popup.remove();
- //show info button
- document.getElementById("infoButton").style.display = "unset";
- }
+ //show info button
+ document.getElementById("infoButton").style.display = "unset";
+ }
}
function clearSponsorTimes() {
- //it can't update to this info yet
- closeInfoMenu();
+ //it can't update to this info yet
+ closeInfoMenu();
- let currentVideoID = getYouTubeVideoID(document.URL);
+ let currentVideoID = getYouTubeVideoID(document.URL);
- let sponsorTimeKey = 'sponsorTimes' + currentVideoID;
- chrome.storage.sync.get([sponsorTimeKey], function(result) {
- let sponsorTimes = result[sponsorTimeKey];
+ let sponsorTimeKey = 'sponsorTimes' + currentVideoID;
+ chrome.storage.sync.get([sponsorTimeKey], function(result) {
+ let sponsorTimes = result[sponsorTimeKey];
- if (sponsorTimes != undefined && sponsorTimes.length > 0) {
- let confirmMessage = chrome.i18n.getMessage("clearThis") + getSponsorTimesMessage(sponsorTimes);
- confirmMessage += chrome.i18n.getMessage("confirmMSG")
- if(!confirm(confirmMessage)) return;
+ if (sponsorTimes != undefined && sponsorTimes.length > 0) {
+ let confirmMessage = chrome.i18n.getMessage("clearThis") + getSponsorTimesMessage(sponsorTimes);
+ confirmMessage += chrome.i18n.getMessage("confirmMSG")
+ if(!confirm(confirmMessage)) return;
- //clear the sponsor times
- let sponsorTimeKey = "sponsorTimes" + currentVideoID;
- chrome.storage.sync.set({[sponsorTimeKey]: []});
+ //clear the sponsor times
+ let sponsorTimeKey = "sponsorTimes" + currentVideoID;
+ chrome.storage.sync.set({[sponsorTimeKey]: []});
- //clear sponsor times submitting
- sponsorTimesSubmitting = [];
+ //clear sponsor times submitting
+ sponsorTimesSubmitting = [];
- //set buttons to be correct
- changeStartSponsorButton(true, false);
- }
- });
+ //set buttons to be correct
+ changeStartSponsorButton(true, false);
+ }
+ });
}
//if skipNotice is null, it will not affect the UI
function vote(type, UUID, skipNotice) {
- if (skipNotice != null) {
- //add loading info
- skipNotice.addVoteButtonInfo.bind(skipNotice)("Loading...")
- skipNotice.resetNoticeInfoMessage.bind(skipNotice)();
- }
-
- chrome.runtime.sendMessage({
- message: "submitVote",
- type: type,
- UUID: UUID
- }, function(response) {
- if (response != undefined) {
- //see if it was a success or failure
- if (skipNotice != null) {
- if (response.successType == 1) {
- //success
- if (type == 0) {
- skipNotice.afterDownvote.bind(skipNotice)();
- }
- } else if (response.successType == 0) {
- //failure: duplicate vote
- skipNotice.addNoticeInfoMessage.bind(skipNotice)(chrome.i18n.getMessage("voteFail"))
- skipNotice.resetVoteButtonInfo.bind(skipNotice)();
- } else if (response.successType == -1) {
- if (response.statusCode == 502) {
- skipNotice.addNoticeInfoMessage.bind(skipNotice)(chrome.i18n.getMessage("serverDown"))
- skipNotice.resetVoteButtonInfo.bind(skipNotice)();
- } else {
- //failure: unknown error
- skipNotice.addNoticeInfoMessage.bind(skipNotice)(chrome.i18n.getMessage("connectionError") + response.statusCode);
- skipNotice.resetVoteButtonInfo.bind(skipNotice)();
- }
- }
- }
+ if (skipNotice != null) {
+ //add loading info
+ skipNotice.addVoteButtonInfo.bind(skipNotice)("Loading...")
+ skipNotice.resetNoticeInfoMessage.bind(skipNotice)();
}
- });
+
+ chrome.runtime.sendMessage({
+ message: "submitVote",
+ type: type,
+ UUID: UUID
+ }, function(response) {
+ if (response != undefined) {
+ //see if it was a success or failure
+ if (skipNotice != null) {
+ if (response.successType == 1) {
+ //success
+ if (type == 0) {
+ skipNotice.afterDownvote.bind(skipNotice)();
+ }
+ } else if (response.successType == 0) {
+ //failure: duplicate vote
+ skipNotice.addNoticeInfoMessage.bind(skipNotice)(chrome.i18n.getMessage("voteFail"))
+ skipNotice.resetVoteButtonInfo.bind(skipNotice)();
+ } else if (response.successType == -1) {
+ if (response.statusCode == 502) {
+ skipNotice.addNoticeInfoMessage.bind(skipNotice)(chrome.i18n.getMessage("serverDown"))
+ skipNotice.resetVoteButtonInfo.bind(skipNotice)();
+ } else {
+ //failure: unknown error
+ skipNotice.addNoticeInfoMessage.bind(skipNotice)(chrome.i18n.getMessage("connectionError") + response.statusCode);
+ skipNotice.resetVoteButtonInfo.bind(skipNotice)();
+ }
+ }
+ }
+ }
+ });
}
//Closes all notices that tell the user that a sponsor was just skipped
function closeAllSkipNotices(){
- let notices = document.getElementsByClassName("sponsorSkipNotice");
- for (let i = 0; i < notices.length; i++) {
- notices[i].remove();
- }
+ let notices = document.getElementsByClassName("sponsorSkipNotice");
+ for (let i = 0; i < notices.length; i++) {
+ notices[i].remove();
+ }
}
function dontShowNoticeAgain() {
- chrome.storage.sync.set({"dontShowNoticeAgain": true});
+ chrome.storage.sync.set({"dontShowNoticeAgain": true});
- dontShowNotice = true;
+ dontShowNotice = true;
- closeAllSkipNotices();
+ closeAllSkipNotices();
}
function sponsorMessageStarted(callback) {
- v = document.querySelector('video');
+ v = document.querySelector('video');
- //send back current time
- callback({
- time: v.currentTime
- })
+ //send back current time
+ callback({
+ time: v.currentTime
+ })
- //update button
- toggleStartSponsorButton();
+ //update button
+ toggleStartSponsorButton();
}
function submitSponsorTimes() {
- if (document.getElementById("submitButton").style.display == "none") {
- //don't submit, not ready
- return;
- }
+ if (document.getElementById("submitButton").style.display == "none") {
+ //don't submit, not ready
+ return;
+ }
- //it can't update to this info yet
- closeInfoMenu();
+ //it can't update to this info yet
+ closeInfoMenu();
- let currentVideoID = getYouTubeVideoID(document.URL);
+ let currentVideoID = getYouTubeVideoID(document.URL);
- let sponsorTimeKey = 'sponsorTimes' + currentVideoID;
- chrome.storage.sync.get([sponsorTimeKey], function(result) {
- let sponsorTimes = result[sponsorTimeKey];
+ let sponsorTimeKey = 'sponsorTimes' + currentVideoID;
+ chrome.storage.sync.get([sponsorTimeKey], function(result) {
+ let sponsorTimes = result[sponsorTimeKey];
- if (sponsorTimes != undefined && sponsorTimes.length > 0) {
- let confirmMessage = "Are you sure you want to submit this?\n\n" + getSponsorTimesMessage(sponsorTimes);
- confirmMessage += "\n\nTo edit or delete values, click the info button or open the extension popup by clicking the extension icon in the top right corner."
- if(!confirm(confirmMessage)) return;
+ if (sponsorTimes != undefined && sponsorTimes.length > 0) {
+ let confirmMessage = "Are you sure you want to submit this?\n\n" + getSponsorTimesMessage(sponsorTimes);
+ confirmMessage += "\n\nTo edit or delete values, click the info button or open the extension popup by clicking the extension icon in the top right corner."
+ if(!confirm(confirmMessage)) return;
- sendSubmitMessage();
- }
- });
+ sendSubmitMessage();
+ }
+ });
}
//send the message to the background js
//called after all the checks have been made that it's okay to do so
function sendSubmitMessage(){
- //add loading animation
- document.getElementById("submitButtonImage").src = chrome.extension.getURL("icons/PlayerUploadIconSponsorBlocker256px.png");
- document.getElementById("submitButton").style.animation = "rotate 1s 0s infinite";
-
- let currentVideoID = getYouTubeVideoID(document.URL);
-
- chrome.runtime.sendMessage({
- message: "submitTimes",
- videoID: currentVideoID
- }, function(response) {
- if (response != undefined) {
- if (response.statusCode == 200) {
- //hide loading message
- let submitButton = document.getElementById("submitButton");
- //finish this animation
- submitButton.style.animation = "rotate 1s";
- //when the animation is over, hide the button
- let animationEndListener = function() {
- changeStartSponsorButton(true, false);
-
- submitButton.style.animation = "none";
-
- submitButton.removeEventListener("animationend", animationEndListener);
- };
-
- submitButton.addEventListener("animationend", animationEndListener);
-
- //clear the sponsor times
- let sponsorTimeKey = "sponsorTimes" + currentVideoID;
- chrome.storage.sync.set({[sponsorTimeKey]: []});
-
- //request the sponsors from the server again
- sponsorsLookup(currentVideoID);
- } else {
- //for a more detailed error message, they should check the popup
- //show that the upload failed
- document.getElementById("submitButton").style.animation = "unset";
- document.getElementById("submitButtonImage").src = chrome.extension.getURL("icons/PlayerUploadFailedIconSponsorBlocker256px.png");
-
- if([400,429,409,502].includes(response.statusCode)) {
- alert(chrome.i18n.getMessage(response.statusCode));
- } else {
- alert(chrome.i18n.getMessage("connectionError") + response.statusCode);
+ //add loading animation
+ document.getElementById("submitButtonImage").src = chrome.extension.getURL("icons/PlayerUploadIconSponsorBlocker256px.png");
+ document.getElementById("submitButton").style.animation = "rotate 1s 0s infinite";
+
+ let currentVideoID = getYouTubeVideoID(document.URL);
+
+ chrome.runtime.sendMessage({
+ message: "submitTimes",
+ videoID: currentVideoID
+ }, function(response) {
+ if (response != undefined) {
+ if (response.statusCode == 200) {
+ //hide loading message
+ let submitButton = document.getElementById("submitButton");
+ //finish this animation
+ submitButton.style.animation = "rotate 1s";
+ //when the animation is over, hide the button
+ let animationEndListener = function() {
+ changeStartSponsorButton(true, false);
+
+ submitButton.style.animation = "none";
+
+ submitButton.removeEventListener("animationend", animationEndListener);
+ };
+
+ submitButton.addEventListener("animationend", animationEndListener);
+
+ //clear the sponsor times
+ let sponsorTimeKey = "sponsorTimes" + currentVideoID;
+ chrome.storage.sync.set({[sponsorTimeKey]: []});
+
+ //request the sponsors from the server again
+ sponsorsLookup(currentVideoID);
+ } else {
+ //for a more detailed error message, they should check the popup
+ //show that the upload failed
+ document.getElementById("submitButton").style.animation = "unset";
+ document.getElementById("submitButtonImage").src = chrome.extension.getURL("icons/PlayerUploadFailedIconSponsorBlocker256px.png");
+
+ if([400,429,409,502].includes(response.statusCode)) {
+ alert(chrome.i18n.getMessage(response.statusCode));
+ } else {
+ alert(chrome.i18n.getMessage("connectionError") + response.statusCode);
+ }
+ }
}
- }
- }
- });
+ });
}
//get the message that visually displays the video times
function getSponsorTimesMessage(sponsorTimes) {
- let sponsorTimesMessage = "";
-
- for (let i = 0; i < sponsorTimes.length; i++) {
- for (let s = 0; s < sponsorTimes[i].length; s++) {
- let timeMessage = getFormattedTime(sponsorTimes[i][s]);
- //if this is an end time
- if (s == 1) {
- timeMessage = " to " + timeMessage;
- } else if (i > 0) {
- //add commas if necessary
- timeMessage = ", " + timeMessage;
- }
-
- sponsorTimesMessage += timeMessage;
+ let sponsorTimesMessage = "";
+
+ for (let i = 0; i < sponsorTimes.length; i++) {
+ for (let s = 0; s < sponsorTimes[i].length; s++) {
+ let timeMessage = getFormattedTime(sponsorTimes[i][s]);
+ //if this is an end time
+ if (s == 1) {
+ timeMessage = " to " + timeMessage;
+ } else if (i > 0) {
+ //add commas if necessary
+ timeMessage = ", " + timeMessage;
+ }
+
+ sponsorTimesMessage += timeMessage;
+ }
}
- }
- return sponsorTimesMessage;
+ return sponsorTimesMessage;
}
//converts time in seconds to minutes:seconds
function getFormattedTime(seconds) {
- let minutes = Math.floor(seconds / 60);
- let secondsDisplay = Math.round(seconds - minutes * 60);
- if (secondsDisplay < 10) {
- //add a zero
- secondsDisplay = "0" + secondsDisplay;
- }
+ let minutes = Math.floor(seconds / 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;
}
function sendRequestToServer(type, address, callback) {
- let xmlhttp = new XMLHttpRequest();
+ let xmlhttp = new XMLHttpRequest();
- xmlhttp.open(type, serverAddress + address, true);
+ xmlhttp.open(type, serverAddress + address, true);
- if (callback != undefined) {
- xmlhttp.onreadystatechange = function () {
- callback(xmlhttp, false);
- };
+ if (callback != undefined) {
+ xmlhttp.onreadystatechange = function () {
+ callback(xmlhttp, false);
+ };
- xmlhttp.onerror = function(ev) {
- callback(xmlhttp, true);
- };
- }
+ xmlhttp.onerror = function(ev) {
+ callback(xmlhttp, true);
+ };
+ }
- //submit this request
- xmlhttp.send();
+ //submit this request
+ xmlhttp.send();
}
function sendRequestToCustomServer(type, fullAddress, callback) {
- let xmlhttp = new XMLHttpRequest();
+ let xmlhttp = new XMLHttpRequest();
- xmlhttp.open(type, fullAddress, true);
+ xmlhttp.open(type, fullAddress, true);
- if (callback != undefined) {
- xmlhttp.onreadystatechange = function () {
- callback(xmlhttp, false);
- };
+ if (callback != undefined) {
+ xmlhttp.onreadystatechange = function () {
+ callback(xmlhttp, false);
+ };
- xmlhttp.onerror = function(ev) {
- callback(xmlhttp, true);
- };
- }
+ xmlhttp.onerror = function(ev) {
+ callback(xmlhttp, true);
+ };
+ }
- //submit this request
- xmlhttp.send();
+ //submit this request
+ xmlhttp.send();
}
diff --git a/popup.css b/popup.css
index ae3f79dc..7fd31edb 100644
--- a/popup.css
+++ b/popup.css
@@ -8,24 +8,24 @@ p.popupElement {
h1.popupElement {
margin-block-start: 0.67em;
- margin-block-end: 0.67em;
- margin-inline-start: 0px;
+ margin-block-end: 0.67em;
+ margin-inline-start: 0px;
margin-inline-end: 0px;
font-weight: bold;
}
h2.popupElement {
margin-block-start: 0.83em;
- margin-block-end: 0.83em;
- margin-inline-start: 0px;
+ margin-block-end: 0.83em;
+ margin-inline-start: 0px;
margin-inline-end: 0px;
font-weight: bold;
}
h3.popupElement {
margin-block-start: 1em;
- margin-block-end: 1em;
- margin-inline-start: 0px;
+ margin-block-end: 1em;
+ margin-inline-start: 0px;
margin-inline-end: 0px;
font-weight: bold;
}
@@ -36,9 +36,9 @@ sub.popupElement {
/* end reset */
.popupElement {
- font-family: 'Source Sans Pro', sans-serif;
+ font-family: 'Source Sans Pro', sans-serif;
- color: black;
+ color: black;
}
h1.popupElement {
@@ -109,43 +109,43 @@ h1.popupElement {
padding:8px 37px;
text-decoration:none;
text-shadow:0px 0px 0px #27663c;
- }
- .whitelistButton:hover.popupElement {
+ }
+ .whitelistButton:hover.popupElement {
background-color:#218b26;
- }
- .whitelistButton:focus.popupElement {
+ }
+ .whitelistButton:focus.popupElement {
outline: none;
background-color:#218b26;
- }
- .whitelistButton:active.popupElement {
+ }
+ .whitelistButton:active.popupElement {
position:relative;
top:1px;
- }
+ }
.greenButton.popupElement {
- 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;
+ 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.popupElement {
- background-color:#bf2a2a;
+ background-color:#bf2a2a;
}
.greenButton:focus.popupElement {
outline: none;
background-color:#bf2a2a;
}
.greenButton:active.popupElement {
- position:relative;
- top:1px;
+ position:relative;
+ top:1px;
}
.dangerButton.popupElement {
diff --git a/popup.js b/popup.js
index 5a826b0a..a62f612f 100644
--- a/popup.js
+++ b/popup.js
@@ -2,1269 +2,1269 @@
//make this a function to allow this to run on the content page
function runThePopup() {
- //is it in the popup or content script
- var inPopup = true;
- if (chrome.tabs == undefined) {
- //this is on the content script, use direct communication
- chrome.tabs = {};
- chrome.tabs.sendMessage = function(id, request, callback) {
- messageListener(request, null, callback);
- }
-
- //add a dummy query method
- chrome.tabs.query = function(config, callback) {
- callback([{
- url: document.URL,
- id: -1
- }]);
- }
-
- inPopup = false;
- }
-
- var SB = {};
+ //is it in the popup or content script
+ var inPopup = true;
+ if (chrome.tabs == undefined) {
+ //this is on the content script, use direct communication
+ chrome.tabs = {};
+ chrome.tabs.sendMessage = function(id, request, callback) {
+ messageListener(request, null, callback);
+ }
+
+ //add a dummy query method
+ chrome.tabs.query = function(config, callback) {
+ callback([{
+ url: document.URL,
+ id: -1
+ }]);
+ }
+
+ inPopup = false;
+ }
+
+ var SB = {};
- ["sponsorStart",
- "whitelistChannel",
- "unwhitelistChannel",
- "clearTimes",
- "submitTimes",
- "showNoticeAgain",
- "hideVideoPlayerControls",
- "showVideoPlayerControls",
- "hideInfoButtonPlayerControls",
- "showInfoButtonPlayerControls",
- "hideDeleteButtonPlayerControls",
- "showDeleteButtonPlayerControls",
- "disableSponsorViewTracking",
- "enableSponsorViewTracking",
- "optionsButton",
- "reportAnIssue",
- // sponsorTimesContributions
- "sponsorTimesContributionsContainer",
- "sponsorTimesContributionsDisplay",
- "sponsorTimesContributionsDisplayEndWord",
- // sponsorTimesViewsDisplay
- "sponsorTimesViewsContainer",
- "sponsorTimesViewsDisplay",
- "sponsorTimesViewsDisplayEndWord",
- // discordButtons
- "discordButtonContainer",
- "hideDiscordButton",
- // submitTimesInfoMessage
- "submitTimesInfoMessageContainer",
- "submitTimesInfoMessage",
- // Username
- "setUsernameContainer",
- "setUsernameButton",
- "setUsernameStatusContainer",
- "setUsernameStatus",
- "setUsername",
- "usernameInput",
- "submitUsername",
- // More
- "submissionSection",
- "mainControls",
- "loadingIndicator",
- "videoFound",
- "sponsorMessageTimes",
- "downloadedSponsorMessageTimes",
- ].forEach(id => SB[id] = document.getElementById(id));
+ ["sponsorStart",
+ "whitelistChannel",
+ "unwhitelistChannel",
+ "clearTimes",
+ "submitTimes",
+ "showNoticeAgain",
+ "hideVideoPlayerControls",
+ "showVideoPlayerControls",
+ "hideInfoButtonPlayerControls",
+ "showInfoButtonPlayerControls",
+ "hideDeleteButtonPlayerControls",
+ "showDeleteButtonPlayerControls",
+ "disableSponsorViewTracking",
+ "enableSponsorViewTracking",
+ "optionsButton",
+ "reportAnIssue",
+ // sponsorTimesContributions
+ "sponsorTimesContributionsContainer",
+ "sponsorTimesContributionsDisplay",
+ "sponsorTimesContributionsDisplayEndWord",
+ // sponsorTimesViewsDisplay
+ "sponsorTimesViewsContainer",
+ "sponsorTimesViewsDisplay",
+ "sponsorTimesViewsDisplayEndWord",
+ // discordButtons
+ "discordButtonContainer",
+ "hideDiscordButton",
+ // submitTimesInfoMessage
+ "submitTimesInfoMessageContainer",
+ "submitTimesInfoMessage",
+ // Username
+ "setUsernameContainer",
+ "setUsernameButton",
+ "setUsernameStatusContainer",
+ "setUsernameStatus",
+ "setUsername",
+ "usernameInput",
+ "submitUsername",
+ // More
+ "submissionSection",
+ "mainControls",
+ "loadingIndicator",
+ "videoFound",
+ "sponsorMessageTimes",
+ "downloadedSponsorMessageTimes",
+ ].forEach(id => SB[id] = document.getElementById(id));
- //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);
- SB.hideVideoPlayerControls.addEventListener("click", hideVideoPlayerControls);
- SB.showVideoPlayerControls.addEventListener("click", showVideoPlayerControls);
- SB.hideInfoButtonPlayerControls.addEventListener("click", hideInfoButtonPlayerControls);
- SB.showInfoButtonPlayerControls.addEventListener("click", showInfoButtonPlayerControls);
- SB.hideDeleteButtonPlayerControls.addEventListener("click", hideDeleteButtonPlayerControls);
- SB.showDeleteButtonPlayerControls.addEventListener("click", showDeleteButtonPlayerControls);
- SB.disableSponsorViewTracking.addEventListener("click", disableSponsorViewTracking);
- SB.enableSponsorViewTracking.addEventListener("click", enableSponsorViewTracking);
- SB.setUsernameButton.addEventListener("click", setUsernameButton);
- SB.submitUsername.addEventListener("click", submitUsername);
- SB.optionsButton.addEventListener("click", openOptions);
- SB.reportAnIssue.addEventListener("click", reportAnIssue);
- SB.hideDiscordButton.addEventListener("click", hideDiscordButton);
+ //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);
+ SB.hideVideoPlayerControls.addEventListener("click", hideVideoPlayerControls);
+ SB.showVideoPlayerControls.addEventListener("click", showVideoPlayerControls);
+ SB.hideInfoButtonPlayerControls.addEventListener("click", hideInfoButtonPlayerControls);
+ SB.showInfoButtonPlayerControls.addEventListener("click", showInfoButtonPlayerControls);
+ SB.hideDeleteButtonPlayerControls.addEventListener("click", hideDeleteButtonPlayerControls);
+ SB.showDeleteButtonPlayerControls.addEventListener("click", showDeleteButtonPlayerControls);
+ SB.disableSponsorViewTracking.addEventListener("click", disableSponsorViewTracking);
+ SB.enableSponsorViewTracking.addEventListener("click", enableSponsorViewTracking);
+ SB.setUsernameButton.addEventListener("click", setUsernameButton);
+ SB.submitUsername.addEventListener("click", submitUsername);
+ SB.optionsButton.addEventListener("click", openOptions);
+ SB.reportAnIssue.addEventListener("click", reportAnIssue);
+ SB.hideDiscordButton.addEventListener("click", hideDiscordButton);
- //if true, the button now selects the end time
- let startTimeChosen = false;
-
- //the start and end time pairs (2d)
- let sponsorTimes = [];
-
- //current video ID of this tab
- let currentVideoID = null;
-
- //is this a YouTube tab?
- let isYouTubeTab = false;
-
- //see if discord link can be shown
- chrome.storage.sync.get(["hideDiscordLink"], function(result) {
- let hideDiscordLink = result.hideDiscordLink;
- if (hideDiscordLink == undefined || !hideDiscordLink) {
- chrome.storage.sync.get(["hideDiscordLaunches"], function(result) {
- let hideDiscordLaunches = result.hideDiscordLaunches;
- //only if less than 5 launches
- if (hideDiscordLaunches == undefined || hideDiscordLaunches < 10) {
- SB.discordButtonContainer.style.display = null;
+ //if true, the button now selects the end time
+ let startTimeChosen = false;
+
+ //the start and end time pairs (2d)
+ let sponsorTimes = [];
+
+ //current video ID of this tab
+ let currentVideoID = null;
+
+ //is this a YouTube tab?
+ let isYouTubeTab = false;
+
+ //see if discord link can be shown
+ chrome.storage.sync.get(["hideDiscordLink"], function(result) {
+ let hideDiscordLink = result.hideDiscordLink;
+ if (hideDiscordLink == undefined || !hideDiscordLink) {
+ chrome.storage.sync.get(["hideDiscordLaunches"], function(result) {
+ let hideDiscordLaunches = result.hideDiscordLaunches;
+ //only if less than 5 launches
+ if (hideDiscordLaunches == undefined || hideDiscordLaunches < 10) {
+ SB.discordButtonContainer.style.display = null;
- if (hideDiscordLaunches == undefined) {
- hideDiscordButton = 1;
- }
+ if (hideDiscordLaunches == undefined) {
+ hideDiscordButton = 1;
+ }
- chrome.storage.sync.set({"hideDiscordLaunches": hideDiscordButton + 1});
- }
- });
- }
- });
-
- //if the don't show notice again letiable is true, an option to
- // disable should be available
- chrome.storage.sync.get(["dontShowNoticeAgain"], function(result) {
- let dontShowNoticeAgain = result.dontShowNoticeAgain;
- if (dontShowNoticeAgain != undefined && dontShowNoticeAgain) {
- SB.showNoticeAgain.style.display = "unset";
- }
- });
-
- //show proper video player controls options
- chrome.storage.sync.get(["hideVideoPlayerControls"], function(result) {
- let hideVideoPlayerControls = result.hideVideoPlayerControls;
- if (hideVideoPlayerControls != undefined && hideVideoPlayerControls) {
- SB.hideVideoPlayerControls.style.display = "none";
- SB.showVideoPlayerControls.style.display = "unset";
- }
- });
- chrome.storage.sync.get(["hideInfoButtonPlayerControls"], function(result) {
- let hideInfoButtonPlayerControls = result.hideInfoButtonPlayerControls;
- if (hideInfoButtonPlayerControls != undefined && hideInfoButtonPlayerControls) {
- SB.hideInfoButtonPlayerControls.style.display = "none";
- SB.showInfoButtonPlayerControls.style.display = "unset";
- }
- });
- chrome.storage.sync.get(["hideDeleteButtonPlayerControls"], function(result) {
- let hideDeleteButtonPlayerControls = result.hideDeleteButtonPlayerControls;
- if (hideDeleteButtonPlayerControls != undefined && hideDeleteButtonPlayerControls) {
- SB.hideDeleteButtonPlayerControls.style.display = "none";
- SB.showDeleteButtonPlayerControls.style.display = "unset";
- }
- });
-
- //show proper tracking option
- chrome.storage.sync.get(["trackViewCount"], function(result) {
- let trackViewCount = result.trackViewCount;
- if (trackViewCount != undefined && !trackViewCount) {
- SB.disableSponsorViewTracking.style.display = "none";
- SB.enableSponsorViewTracking.style.display = "unset";
- }
- });
-
- //get the amount of times this user has contributed and display it to thank them
- chrome.storage.sync.get(["sponsorTimesContributed"], function(result) {
- if (result.sponsorTimesContributed != undefined) {
- if (result.sponsorTimesContributed > 1) {
- SB.sponsorTimesContributionsDisplayEndWord.innerText = chrome.i18n.getMessage("Sponsors");
- } else {
- SB.sponsorTimesContributionsDisplayEndWord.innerText = chrome.i18n.getMessage("Sponsor");
- }
- SB.sponsorTimesContributionsDisplay.innerText = result.sponsorTimesContributed;
- SB.sponsorTimesContributionsContainer.style.display = "unset";
-
- //get the userID
- chrome.storage.sync.get(["userID"], function(result) {
- let userID = result.userID;
- if (userID != undefined) {
- //there are probably some views on these submissions then
- //get the amount of views from the sponsors submitted
- sendRequestToServer("GET", "/api/getViewsForUser?userID=" + userID, function(xmlhttp) {
- if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
- let viewCount = JSON.parse(xmlhttp.responseText).viewCount;
- if (viewCount != 0) {
- if (viewCount > 1) {
- SB.sponsorTimesViewsDisplayEndWord.innerText = chrome.i18n.getMessage("Segments");
- } else {
- SB.sponsorTimesViewsDisplayEndWord.innerText = chrome.i18n.getMessage("Segment");
+ chrome.storage.sync.set({"hideDiscordLaunches": hideDiscordButton + 1});
}
+ });
+ }
+ });
- SB.sponsorTimesViewsDisplay.innerText = viewCount;
- SB.sponsorTimesViewsContainer.style.display = "unset";
- }
+ //if the don't show notice again letiable is true, an option to
+ // disable should be available
+ chrome.storage.sync.get(["dontShowNoticeAgain"], function(result) {
+ let dontShowNoticeAgain = result.dontShowNoticeAgain;
+ if (dontShowNoticeAgain != undefined && dontShowNoticeAgain) {
+ SB.showNoticeAgain.style.display = "unset";
+ }
+ });
+
+ //show proper video player controls options
+ chrome.storage.sync.get(["hideVideoPlayerControls"], function(result) {
+ let hideVideoPlayerControls = result.hideVideoPlayerControls;
+ if (hideVideoPlayerControls != undefined && hideVideoPlayerControls) {
+ SB.hideVideoPlayerControls.style.display = "none";
+ SB.showVideoPlayerControls.style.display = "unset";
+ }
+ });
+ chrome.storage.sync.get(["hideInfoButtonPlayerControls"], function(result) {
+ let hideInfoButtonPlayerControls = result.hideInfoButtonPlayerControls;
+ if (hideInfoButtonPlayerControls != undefined && hideInfoButtonPlayerControls) {
+ SB.hideInfoButtonPlayerControls.style.display = "none";
+ SB.showInfoButtonPlayerControls.style.display = "unset";
+ }
+ });
+ chrome.storage.sync.get(["hideDeleteButtonPlayerControls"], function(result) {
+ let hideDeleteButtonPlayerControls = result.hideDeleteButtonPlayerControls;
+ if (hideDeleteButtonPlayerControls != undefined && hideDeleteButtonPlayerControls) {
+ SB.hideDeleteButtonPlayerControls.style.display = "none";
+ SB.showDeleteButtonPlayerControls.style.display = "unset";
+ }
+ });
+
+ //show proper tracking option
+ chrome.storage.sync.get(["trackViewCount"], function(result) {
+ let trackViewCount = result.trackViewCount;
+ if (trackViewCount != undefined && !trackViewCount) {
+ SB.disableSponsorViewTracking.style.display = "none";
+ SB.enableSponsorViewTracking.style.display = "unset";
+ }
+ });
+
+ //get the amount of times this user has contributed and display it to thank them
+ chrome.storage.sync.get(["sponsorTimesContributed"], function(result) {
+ if (result.sponsorTimesContributed != undefined) {
+ if (result.sponsorTimesContributed > 1) {
+ SB.sponsorTimesContributionsDisplayEndWord.innerText = chrome.i18n.getMessage("Sponsors");
+ } else {
+ SB.sponsorTimesContributionsDisplayEndWord.innerText = chrome.i18n.getMessage("Sponsor");
}
- });
+ SB.sponsorTimesContributionsDisplay.innerText = result.sponsorTimesContributed;
+ SB.sponsorTimesContributionsContainer.style.display = "unset";
+
+ //get the userID
+ chrome.storage.sync.get(["userID"], function(result) {
+ let userID = result.userID;
+ if (userID != undefined) {
+ //there are probably some views on these submissions then
+ //get the amount of views from the sponsors submitted
+ sendRequestToServer("GET", "/api/getViewsForUser?userID=" + userID, function(xmlhttp) {
+ if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
+ let viewCount = JSON.parse(xmlhttp.responseText).viewCount;
+ if (viewCount != 0) {
+ if (viewCount > 1) {
+ SB.sponsorTimesViewsDisplayEndWord.innerText = chrome.i18n.getMessage("Segments");
+ } else {
+ SB.sponsorTimesViewsDisplayEndWord.innerText = chrome.i18n.getMessage("Segment");
+ }
+
+ SB.sponsorTimesViewsDisplay.innerText = viewCount;
+ SB.sponsorTimesViewsContainer.style.display = "unset";
+ }
+ }
+ });
+ }
+ });
}
- });
- }
- });
+ });
- chrome.tabs.query({
- active: true,
- currentWindow: true
- }, onTabs);
+ chrome.tabs.query({
+ active: true,
+ currentWindow: true
+ }, onTabs);
- function onTabs(tabs) {
+ function onTabs(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {message: 'getVideoID'}, function(result) {
- if (result != undefined && result.videoID) {
+ if (result != undefined && result.videoID) {
currentVideoID = result.videoID;
loadTabData(tabs);
- } else if (result == undefined && chrome.runtime.lastError) {
+ } else if (result == undefined && chrome.runtime.lastError) {
//this isn't a YouTube video then, or at least the content script is not loaded
displayNoVideo();
- }
+ }
});
- }
-
- function loadTabData(tabs) {
- if (!currentVideoID) {
- //this isn't a YouTube video then
- displayNoVideo();
- return;
}
- //load video times for this video
- let sponsorTimeKey = "sponsorTimes" + currentVideoID;
- chrome.storage.sync.get([sponsorTimeKey], function(result) {
- let sponsorTimesStorage = result[sponsorTimeKey];
- if (sponsorTimesStorage != undefined && sponsorTimesStorage.length > 0) {
- if (sponsorTimesStorage[sponsorTimesStorage.length - 1] != undefined && sponsorTimesStorage[sponsorTimesStorage.length - 1].length < 2) {
- startTimeChosen = true;
- SB.sponsorStart.innerHTML = chrome.i18n.getMessage("sponsorEnd");
+ function loadTabData(tabs) {
+ if (!currentVideoID) {
+ //this isn't a YouTube video then
+ displayNoVideo();
+ return;
}
- sponsorTimes = sponsorTimesStorage;
+ //load video times for this video
+ let sponsorTimeKey = "sponsorTimes" + currentVideoID;
+ chrome.storage.sync.get([sponsorTimeKey], function(result) {
+ let sponsorTimesStorage = result[sponsorTimeKey];
+ if (sponsorTimesStorage != undefined && sponsorTimesStorage.length > 0) {
+ if (sponsorTimesStorage[sponsorTimesStorage.length - 1] != undefined && sponsorTimesStorage[sponsorTimesStorage.length - 1].length < 2) {
+ startTimeChosen = true;
+ SB.sponsorStart.innerHTML = chrome.i18n.getMessage("sponsorEnd");
+ }
- displaySponsorTimes();
+ sponsorTimes = sponsorTimesStorage;
- //show submission section
- SB.submissionSection.style.display = "unset";
+ displaySponsorTimes();
- showSubmitTimesIfNecessary();
- }
- });
+ //show submission section
+ SB.submissionSection.style.display = "unset";
+
+ showSubmitTimesIfNecessary();
+ }
+ });
- //check if this video's sponsors are known
- chrome.tabs.sendMessage(
- tabs[0].id,
- {message: 'isInfoFound'},
- infoFound
- );
- }
-
- function infoFound(request) {
- if(chrome.runtime.lastError) {
- //This page doesn't have the injected content script, or at least not yet
- displayNoVideo();
- return;
+ //check if this video's sponsors are known
+ chrome.tabs.sendMessage(
+ tabs[0].id,
+ {message: 'isInfoFound'},
+ infoFound
+ );
}
- //if request is undefined, then the page currently being browsed is not YouTube
- if (request != undefined) {
- //this must be a YouTube video
- //set letiable
- isYouTubeTab = true;
+ 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 != undefined) {
+ //this must be a YouTube video
+ //set letiable
+ isYouTubeTab = true;
- //remove loading text
- SB.mainControls.style.display = "unset"
- SB.loadingIndicator.innerHTML = "";
+ //remove loading text
+ SB.mainControls.style.display = "unset"
+ SB.loadingIndicator.innerHTML = "";
- if (request.found) {
- SB.videoFound.innerHTML = chrome.i18n.getMessage("sponsorFound");
+ if (request.found) {
+ SB.videoFound.innerHTML = chrome.i18n.getMessage("sponsorFound");
- displayDownloadedSponsorTimes(request);
- } else {
- SB.videoFound.innerHTML = chrome.i18n.getMessage("sponsor404");
- }
- }
+ displayDownloadedSponsorTimes(request);
+ } else {
+ SB.videoFound.innerHTML = chrome.i18n.getMessage("sponsor404");
+ }
+ }
- //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";
+ //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";
- }
- });
- }
- );
- }
-
- function setVideoID(request) {
- //if request is undefined, then the page currently being browsed is not YouTube
- if (request != undefined) {
- videoID = request.videoID;
- }
- }
-
- function sendSponsorStartMessage() {
- //the content script will get the message if a YouTube page is open
- chrome.tabs.query({
- active: true,
- currentWindow: true
- }, tabs => {
- chrome.tabs.sendMessage(
- tabs[0].id,
- {from: 'popup', message: 'sponsorStart'},
- startSponsorCallback
+ SB.downloadedSponsorMessageTimes.innerText = "Channel Whitelisted!";
+ SB.downloadedSponsorMessageTimes.style.fontWeight = "bold";
+ }
+ });
+ }
);
- });
- }
+ }
- function startSponsorCallback(response) {
- let sponsorTimesIndex = sponsorTimes.length - (startTimeChosen ? 1 : 0);
+ function setVideoID(request) {
+ //if request is undefined, then the page currently being browsed is not YouTube
+ if (request != undefined) {
+ videoID = request.videoID;
+ }
+ }
- if (sponsorTimes[sponsorTimesIndex] == undefined) {
- sponsorTimes[sponsorTimesIndex] = [];
+ function sendSponsorStartMessage() {
+ //the content script will get the message if a YouTube page is open
+ chrome.tabs.query({
+ active: true,
+ currentWindow: true
+ }, tabs => {
+ chrome.tabs.sendMessage(
+ tabs[0].id,
+ {from: 'popup', message: 'sponsorStart'},
+ startSponsorCallback
+ );
+ });
}
- sponsorTimes[sponsorTimesIndex][startTimeChosen ? 1 : 0] = response.time;
+ function startSponsorCallback(response) {
+ let sponsorTimesIndex = sponsorTimes.length - (startTimeChosen ? 1 : 0);
- let sponsorTimeKey = "sponsorTimes" + currentVideoID;
- let localStartTimeChosen = startTimeChosen;
- chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes}, function() {
- //send a message to the client script
- if (localStartTimeChosen) {
- chrome.tabs.query({
- active: true,
- currentWindow: true
- }, tabs => {
- chrome.tabs.sendMessage(
- tabs[0].id,
- {message: "sponsorDataChanged"}
- );
- });
- }
- });
+ if (sponsorTimes[sponsorTimesIndex] == undefined) {
+ sponsorTimes[sponsorTimesIndex] = [];
+ }
- updateStartTimeChosen();
+ sponsorTimes[sponsorTimesIndex][startTimeChosen ? 1 : 0] = response.time;
+
+ let sponsorTimeKey = "sponsorTimes" + currentVideoID;
+ let localStartTimeChosen = startTimeChosen;
+ chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes}, function() {
+ //send a message to the client script
+ if (localStartTimeChosen) {
+ chrome.tabs.query({
+ active: true,
+ currentWindow: true
+ }, tabs => {
+ chrome.tabs.sendMessage(
+ tabs[0].id,
+ {message: "sponsorDataChanged"}
+ );
+ });
+ }
+ });
- //display video times on screen
- displaySponsorTimes();
+ updateStartTimeChosen();
- //show submission section
- SB.submissionSection.style.display = "unset";
+ //display video times on screen
+ displaySponsorTimes();
- showSubmitTimesIfNecessary();
- }
+ //show submission section
+ SB.submissionSection.style.display = "unset";
- //display the video times from the array
- function displaySponsorTimes() {
- //remove all children
- while (SB.sponsorMessageTimes.firstChild) {
- SB.sponsorMessageTimes.removeChild(SB.sponsorMessageTimes.firstChild);
+ showSubmitTimesIfNecessary();
}
+
+ //display the video times from the array
+ function displaySponsorTimes() {
+ //remove all children
+ while (SB.sponsorMessageTimes.firstChild) {
+ SB.sponsorMessageTimes.removeChild(SB.sponsorMessageTimes.firstChild);
+ }
- //add sponsor times
- SB.sponsorMessageTimes.appendChild(getSponsorTimesMessageDiv(sponsorTimes));
- }
-
- //display the video times from the array at the top, in a different section
- function displayDownloadedSponsorTimes(request) {
- if (request.sponsorTimes != undefined) {
- //set it to the message
- if (SB.downloadedSponsorMessageTimes.innerText != chrome.i18n.getMessage("channelWhitelisted")) {
- SB.downloadedSponsorMessageTimes.innerText = getSponsorTimesMessage(request.sponsorTimes);
- }
+ //add sponsor times
+ SB.sponsorMessageTimes.appendChild(getSponsorTimesMessageDiv(sponsorTimes));
+ }
+
+ //display the video times from the array at the top, in a different section
+ function displayDownloadedSponsorTimes(request) {
+ if (request.sponsorTimes != undefined) {
+ //set it to the message
+ if (SB.downloadedSponsorMessageTimes.innerText != chrome.i18n.getMessage("channelWhitelisted")) {
+ SB.downloadedSponsorMessageTimes.innerText = getSponsorTimesMessage(request.sponsorTimes);
+ }
- //add them as buttons to the issue reporting container
- let container = document.getElementById("issueReporterTimeButtons");
- for (let i = 0; i < request.sponsorTimes.length; i++) {
- let sponsorTimeButton = document.createElement("button");
- sponsorTimeButton.className = "warningButton popupElement";
+ //add them as buttons to the issue reporting container
+ let container = document.getElementById("issueReporterTimeButtons");
+ for (let i = 0; i < request.sponsorTimes.length; i++) {
+ let sponsorTimeButton = document.createElement("button");
+ sponsorTimeButton.className = "warningButton popupElement";
- let extraInfo = "";
- if (request.hiddenSponsorTimes.includes(i)) {
- //this one is hidden
- extraInfo = " (hidden)";
- }
+ let extraInfo = "";
+ if (request.hiddenSponsorTimes.includes(i)) {
+ //this one is hidden
+ extraInfo = " (hidden)";
+ }
- sponsorTimeButton.innerText = getFormattedTime(request.sponsorTimes[i][0]) + " to " + getFormattedTime(request.sponsorTimes[i][1]) + extraInfo;
+ sponsorTimeButton.innerText = getFormattedTime(request.sponsorTimes[i][0]) + " to " + getFormattedTime(request.sponsorTimes[i][1]) + extraInfo;
- let votingButtons = document.createElement("div");
-
- let UUID = request.UUIDs[i];
-
- //thumbs up and down buttons
- let voteButtonsContainer = document.createElement("div");
- voteButtonsContainer.id = "sponsorTimesVoteButtonsContainer" + UUID;
- voteButtonsContainer.setAttribute("align", "center");
- voteButtonsContainer.style.display = "none"
-
- let upvoteButton = document.createElement("img");
- upvoteButton.id = "sponsorTimesUpvoteButtonsContainer" + UUID;
- upvoteButton.className = "voteButton popupElement";
- upvoteButton.src = chrome.extension.getURL("icons/upvote.png");
- upvoteButton.addEventListener("click", () => vote(1, UUID));
-
- let downvoteButton = document.createElement("img");
- downvoteButton.id = "sponsorTimesDownvoteButtonsContainer" + UUID;
- downvoteButton.className = "voteButton popupElement";
- downvoteButton.src = chrome.extension.getURL("icons/downvote.png");
- downvoteButton.addEventListener("click", () => vote(0, UUID));
-
- //add thumbs up and down buttons to the container
- voteButtonsContainer.appendChild(document.createElement("br"));
- voteButtonsContainer.appendChild(document.createElement("br"));
- voteButtonsContainer.appendChild(upvoteButton);
- voteButtonsContainer.appendChild(downvoteButton);
-
- //add click listener to open up vote panel
- sponsorTimeButton.addEventListener("click", function() {
- voteButtonsContainer.style.display = "unset";
- });
+ let votingButtons = document.createElement("div");
+
+ let UUID = request.UUIDs[i];
+
+ //thumbs up and down buttons
+ let voteButtonsContainer = document.createElement("div");
+ voteButtonsContainer.id = "sponsorTimesVoteButtonsContainer" + UUID;
+ voteButtonsContainer.setAttribute("align", "center");
+ voteButtonsContainer.style.display = "none"
+
+ let upvoteButton = document.createElement("img");
+ upvoteButton.id = "sponsorTimesUpvoteButtonsContainer" + UUID;
+ upvoteButton.className = "voteButton popupElement";
+ upvoteButton.src = chrome.extension.getURL("icons/upvote.png");
+ upvoteButton.addEventListener("click", () => vote(1, UUID));
+
+ let downvoteButton = document.createElement("img");
+ downvoteButton.id = "sponsorTimesDownvoteButtonsContainer" + UUID;
+ downvoteButton.className = "voteButton popupElement";
+ downvoteButton.src = chrome.extension.getURL("icons/downvote.png");
+ downvoteButton.addEventListener("click", () => vote(0, UUID));
+
+ //add thumbs up and down buttons to the container
+ voteButtonsContainer.appendChild(document.createElement("br"));
+ voteButtonsContainer.appendChild(document.createElement("br"));
+ voteButtonsContainer.appendChild(upvoteButton);
+ voteButtonsContainer.appendChild(downvoteButton);
+
+ //add click listener to open up vote panel
+ sponsorTimeButton.addEventListener("click", function() {
+ voteButtonsContainer.style.display = "unset";
+ });
- container.appendChild(sponsorTimeButton);
- container.appendChild(voteButtonsContainer);
+ container.appendChild(sponsorTimeButton);
+ container.appendChild(voteButtonsContainer);
- //if it is not the last iteration
- if (i != request.sponsorTimes.length - 1) {
- container.appendChild(document.createElement("br"));
- container.appendChild(document.createElement("br"));
+ //if it is not the last iteration
+ if (i != request.sponsorTimes.length - 1) {
+ container.appendChild(document.createElement("br"));
+ container.appendChild(document.createElement("br"));
+ }
+ }
}
- }
}
- }
-
- //get the message that visually displays the video times
- function getSponsorTimesMessage(sponsorTimes) {
- let sponsorTimesMessage = "";
-
- for (let i = 0; i < sponsorTimes.length; i++) {
- for (let s = 0; s < sponsorTimes[i].length; s++) {
- let timeMessage = getFormattedTime(sponsorTimes[i][s]);
- //if this is an end time
- if (s == 1) {
- timeMessage = " to " + timeMessage;
- } else if (i > 0) {
- //add commas if necessary
- timeMessage = ", " + timeMessage;
+
+ //get the message that visually displays the video times
+ function getSponsorTimesMessage(sponsorTimes) {
+ let sponsorTimesMessage = "";
+
+ for (let i = 0; i < sponsorTimes.length; i++) {
+ for (let s = 0; s < sponsorTimes[i].length; s++) {
+ let timeMessage = getFormattedTime(sponsorTimes[i][s]);
+ //if this is an end time
+ if (s == 1) {
+ timeMessage = " to " + timeMessage;
+ } else if (i > 0) {
+ //add commas if necessary
+ timeMessage = ", " + timeMessage;
+ }
+
+ sponsorTimesMessage += timeMessage;
+ }
}
- sponsorTimesMessage += timeMessage;
- }
+ return sponsorTimesMessage;
}
- return sponsorTimesMessage;
- }
-
- //get the message that visually displays the video times
- //this version is a div that contains each with delete buttons
- function getSponsorTimesMessageDiv(sponsorTimes) {
- // let sponsorTimesMessage = "";
- let sponsorTimesContainer = document.createElement("div");
- sponsorTimesContainer.id = "sponsorTimesContainer";
-
- for (let i = 0; i < sponsorTimes.length; i++) {
- let currentSponsorTimeContainer = document.createElement("div");
- currentSponsorTimeContainer.id = "sponsorTimeContainer" + i;
- currentSponsorTimeContainer.className = "sponsorTime popupElement";
- let currentSponsorTimeMessage = "";
-
- let deleteButton = document.createElement("span");
- deleteButton.id = "sponsorTimeDeleteButton" + i;
- deleteButton.innerText = "Delete";
- deleteButton.className = "mediumLink popupElement";
- let index = i;
- deleteButton.addEventListener("click", () => deleteSponsorTime(index));
-
- let previewButton = document.createElement("span");
- previewButton.id = "sponsorTimePreviewButton" + i;
- previewButton.innerText = "Preview";
- previewButton.className = "mediumLink popupElement";
- previewButton.addEventListener("click", () => previewSponsorTime(index));
-
- let editButton = document.createElement("span");
- editButton.id = "sponsorTimeEditButton" + i;
- editButton.innerText = "Edit";
- editButton.className = "mediumLink popupElement";
- editButton.addEventListener("click", () => editSponsorTime(index));
-
- for (let s = 0; s < sponsorTimes[i].length; s++) {
- let timeMessage = getFormattedTime(sponsorTimes[i][s]);
- //if this is an end time
- if (s == 1) {
- timeMessage = " to " + timeMessage;
- } else if (i > 0) {
- //add commas if necessary
- timeMessage = timeMessage;
- }
+ //get the message that visually displays the video times
+ //this version is a div that contains each with delete buttons
+ function getSponsorTimesMessageDiv(sponsorTimes) {
+ // let sponsorTimesMessage = "";
+ let sponsorTimesContainer = document.createElement("div");
+ sponsorTimesContainer.id = "sponsorTimesContainer";
+
+ for (let i = 0; i < sponsorTimes.length; i++) {
+ let currentSponsorTimeContainer = document.createElement("div");
+ currentSponsorTimeContainer.id = "sponsorTimeContainer" + i;
+ currentSponsorTimeContainer.className = "sponsorTime popupElement";
+ let currentSponsorTimeMessage = "";
+
+ let deleteButton = document.createElement("span");
+ deleteButton.id = "sponsorTimeDeleteButton" + i;
+ deleteButton.innerText = "Delete";
+ deleteButton.className = "mediumLink popupElement";
+ let index = i;
+ deleteButton.addEventListener("click", () => deleteSponsorTime(index));
+
+ let previewButton = document.createElement("span");
+ previewButton.id = "sponsorTimePreviewButton" + i;
+ previewButton.innerText = "Preview";
+ previewButton.className = "mediumLink popupElement";
+ previewButton.addEventListener("click", () => previewSponsorTime(index));
+
+ let editButton = document.createElement("span");
+ editButton.id = "sponsorTimeEditButton" + i;
+ editButton.innerText = "Edit";
+ editButton.className = "mediumLink popupElement";
+ editButton.addEventListener("click", () => editSponsorTime(index));
+
+ for (let s = 0; s < sponsorTimes[i].length; s++) {
+ let timeMessage = getFormattedTime(sponsorTimes[i][s]);
+ //if this is an end time
+ if (s == 1) {
+ timeMessage = " to " + timeMessage;
+ } else if (i > 0) {
+ //add commas if necessary
+ timeMessage = timeMessage;
+ }
- currentSponsorTimeMessage += timeMessage;
- }
+ currentSponsorTimeMessage += timeMessage;
+ }
- currentSponsorTimeContainer.innerText = currentSponsorTimeMessage;
+ currentSponsorTimeContainer.innerText = currentSponsorTimeMessage;
- sponsorTimesContainer.appendChild(currentSponsorTimeContainer);
- sponsorTimesContainer.appendChild(deleteButton);
+ sponsorTimesContainer.appendChild(currentSponsorTimeContainer);
+ sponsorTimesContainer.appendChild(deleteButton);
- //only if it is a complete sponsor time
- if (sponsorTimes[i].length > 1) {
- sponsorTimesContainer.appendChild(previewButton);
- sponsorTimesContainer.appendChild(editButton);
+ //only if it is a complete sponsor time
+ if (sponsorTimes[i].length > 1) {
+ sponsorTimesContainer.appendChild(previewButton);
+ sponsorTimesContainer.appendChild(editButton);
- currentSponsorTimeContainer.addEventListener("click", () => editSponsorTime(index));
- }
- }
+ currentSponsorTimeContainer.addEventListener("click", () => editSponsorTime(index));
+ }
+ }
- return sponsorTimesContainer;
- }
-
- function previewSponsorTime(index) {
- let skipTime = sponsorTimes[index][0];
+ return sponsorTimesContainer;
+ }
- if (document.getElementById("startTimeMinutes" + index) != null) {
- //edit is currently open, use that time
+ function previewSponsorTime(index) {
+ let skipTime = sponsorTimes[index][0];
- skipTime = getSponsorTimeEditTimes("startTime", index);
+ if (document.getElementById("startTimeMinutes" + index) != null) {
+ //edit is currently open, use that time
- //save the edit
- saveSponsorTimeEdit(index, false);
- }
+ skipTime = getSponsorTimeEditTimes("startTime", index);
- chrome.tabs.query({
- active: true,
- currentWindow: true
- }, tabs => {
- chrome.tabs.sendMessage(
- tabs[0].id, {
- message: "skipToTime",
- time: skipTime - 2
+ //save the edit
+ saveSponsorTimeEdit(index, false);
}
- );
- });
- }
-
- function editSponsorTime(index) {
- if (document.getElementById("startTimeMinutes" + index) != null) {
- //already open
- return;
+
+ chrome.tabs.query({
+ active: true,
+ currentWindow: true
+ }, tabs => {
+ chrome.tabs.sendMessage(
+ tabs[0].id, {
+ message: "skipToTime",
+ time: skipTime - 2
+ }
+ );
+ });
}
+
+ function editSponsorTime(index) {
+ if (document.getElementById("startTimeMinutes" + index) != null) {
+ //already open
+ return;
+ }
- //hide submit button
- document.getElementById("submitTimesContainer").style.display = "none";
+ //hide submit button
+ document.getElementById("submitTimesContainer").style.display = "none";
- let sponsorTimeContainer = document.getElementById("sponsorTimeContainer" + index);
+ let sponsorTimeContainer = document.getElementById("sponsorTimeContainer" + index);
- //the button to set the current time
- let startTimeNowButton = document.createElement("span");
- startTimeNowButton.id = "startTimeNowButton" + index;
- startTimeNowButton.innerText = "(Now)";
- startTimeNowButton.className = "tinyLink popupElement";
- startTimeNowButton.addEventListener("click", () => setEditTimeToCurrentTime("startTime", index));
+ //the button to set the current time
+ let startTimeNowButton = document.createElement("span");
+ startTimeNowButton.id = "startTimeNowButton" + index;
+ startTimeNowButton.innerText = "(Now)";
+ startTimeNowButton.className = "tinyLink popupElement";
+ startTimeNowButton.addEventListener("click", () => setEditTimeToCurrentTime("startTime", index));
- //get sponsor time minutes and seconds boxes
- let startTimeMinutes = document.createElement("input");
- startTimeMinutes.id = "startTimeMinutes" + index;
- startTimeMinutes.className = "sponsorTime popupElement";
- startTimeMinutes.type = "text";
- startTimeMinutes.value = getTimeInMinutes(sponsorTimes[index][0]);
- startTimeMinutes.style.width = "45px";
+ //get sponsor time minutes and seconds boxes
+ let startTimeMinutes = document.createElement("input");
+ startTimeMinutes.id = "startTimeMinutes" + index;
+ startTimeMinutes.className = "sponsorTime popupElement";
+ startTimeMinutes.type = "text";
+ startTimeMinutes.value = getTimeInMinutes(sponsorTimes[index][0]);
+ startTimeMinutes.style.width = "45px";
- let startTimeSeconds = document.createElement("input");
- startTimeSeconds.id = "startTimeSeconds" + index;
- startTimeSeconds.className = "sponsorTime popupElement";
- startTimeSeconds.type = "text";
- startTimeSeconds.value = getTimeInFormattedSeconds(sponsorTimes[index][0]);
- startTimeSeconds.style.width = "60px";
+ let startTimeSeconds = document.createElement("input");
+ startTimeSeconds.id = "startTimeSeconds" + index;
+ startTimeSeconds.className = "sponsorTime popupElement";
+ startTimeSeconds.type = "text";
+ startTimeSeconds.value = getTimeInFormattedSeconds(sponsorTimes[index][0]);
+ startTimeSeconds.style.width = "60px";
- let endTimeMinutes = document.createElement("input");
- endTimeMinutes.id = "endTimeMinutes" + index;
- endTimeMinutes.className = "sponsorTime popupElement";
- endTimeMinutes.type = "text";
- endTimeMinutes.value = getTimeInMinutes(sponsorTimes[index][1]);
- endTimeMinutes.style.width = "45px";
+ let endTimeMinutes = document.createElement("input");
+ endTimeMinutes.id = "endTimeMinutes" + index;
+ endTimeMinutes.className = "sponsorTime popupElement";
+ endTimeMinutes.type = "text";
+ endTimeMinutes.value = getTimeInMinutes(sponsorTimes[index][1]);
+ endTimeMinutes.style.width = "45px";
- let endTimeSeconds = document.createElement("input");
- endTimeSeconds.id = "endTimeSeconds" + index;
- endTimeSeconds.className = "sponsorTime popupElement";
- endTimeSeconds.type = "text";
- endTimeSeconds.value = getTimeInFormattedSeconds(sponsorTimes[index][1]);
- endTimeSeconds.style.width = "60px";
+ let endTimeSeconds = document.createElement("input");
+ endTimeSeconds.id = "endTimeSeconds" + index;
+ endTimeSeconds.className = "sponsorTime popupElement";
+ endTimeSeconds.type = "text";
+ endTimeSeconds.value = getTimeInFormattedSeconds(sponsorTimes[index][1]);
+ endTimeSeconds.style.width = "60px";
- //the button to set the current time
- let endTimeNowButton = document.createElement("span");
- endTimeNowButton.id = "endTimeNowButton" + index;
- endTimeNowButton.innerText = "(Now)";
- endTimeNowButton.className = "tinyLink popupElement";
- endTimeNowButton.addEventListener("click", () => setEditTimeToCurrentTime("endTime", index));
-
- let colonText = document.createElement("span");
- colonText.innerText = ":";
-
- let toText = document.createElement("span");
- toText.innerText = " to ";
-
- //remove all children to replace
- while (sponsorTimeContainer.firstChild) {
- sponsorTimeContainer.removeChild(sponsorTimeContainer.firstChild);
- }
+ //the button to set the current time
+ let endTimeNowButton = document.createElement("span");
+ endTimeNowButton.id = "endTimeNowButton" + index;
+ endTimeNowButton.innerText = "(Now)";
+ endTimeNowButton.className = "tinyLink popupElement";
+ endTimeNowButton.addEventListener("click", () => setEditTimeToCurrentTime("endTime", index));
+
+ let colonText = document.createElement("span");
+ colonText.innerText = ":";
+
+ let toText = document.createElement("span");
+ toText.innerText = " to ";
+
+ //remove all children to replace
+ while (sponsorTimeContainer.firstChild) {
+ sponsorTimeContainer.removeChild(sponsorTimeContainer.firstChild);
+ }
- sponsorTimeContainer.appendChild(startTimeNowButton);
- sponsorTimeContainer.appendChild(startTimeMinutes);
- sponsorTimeContainer.appendChild(colonText);
- sponsorTimeContainer.appendChild(startTimeSeconds);
- sponsorTimeContainer.appendChild(toText);
- sponsorTimeContainer.appendChild(endTimeMinutes);
- sponsorTimeContainer.appendChild(colonText);
- sponsorTimeContainer.appendChild(endTimeSeconds);
- sponsorTimeContainer.appendChild(endTimeNowButton);
-
- //add save button and remove edit button
- let saveButton = document.createElement("span");
- saveButton.id = "sponsorTimeSaveButton" + index;
- saveButton.innerText = "Save";
- saveButton.className = "mediumLink popupElement";
- saveButton.addEventListener("click", () => saveSponsorTimeEdit(index));
-
- let editButton = document.getElementById("sponsorTimeEditButton" + index);
- let sponsorTimesContainer = document.getElementById("sponsorTimesContainer");
-
- sponsorTimesContainer.replaceChild(saveButton, editButton);
- }
+ sponsorTimeContainer.appendChild(startTimeNowButton);
+ sponsorTimeContainer.appendChild(startTimeMinutes);
+ sponsorTimeContainer.appendChild(colonText);
+ sponsorTimeContainer.appendChild(startTimeSeconds);
+ sponsorTimeContainer.appendChild(toText);
+ sponsorTimeContainer.appendChild(endTimeMinutes);
+ sponsorTimeContainer.appendChild(colonText);
+ sponsorTimeContainer.appendChild(endTimeSeconds);
+ sponsorTimeContainer.appendChild(endTimeNowButton);
+
+ //add save button and remove edit button
+ let saveButton = document.createElement("span");
+ saveButton.id = "sponsorTimeSaveButton" + index;
+ saveButton.innerText = "Save";
+ saveButton.className = "mediumLink popupElement";
+ saveButton.addEventListener("click", () => saveSponsorTimeEdit(index));
+
+ let editButton = document.getElementById("sponsorTimeEditButton" + index);
+ let sponsorTimesContainer = document.getElementById("sponsorTimesContainer");
+
+ sponsorTimesContainer.replaceChild(saveButton, editButton);
+ }
- function setEditTimeToCurrentTime(idStartName, index) {
- chrome.tabs.query({
- active: true,
- currentWindow: true
- }, tabs => {
- chrome.tabs.sendMessage(
- tabs[0].id,
- {message: "getCurrentTime"},
- function (response) {
- let minutes = document.getElementById(idStartName + chrome.i18n.getMessage("Mins") + index);
- let seconds = document.getElementById(idStartName + chrome.i18n.getMessage("Secs") + index);
+ function setEditTimeToCurrentTime(idStartName, index) {
+ chrome.tabs.query({
+ active: true,
+ currentWindow: true
+ }, tabs => {
+ chrome.tabs.sendMessage(
+ tabs[0].id,
+ {message: "getCurrentTime"},
+ function (response) {
+ let minutes = document.getElementById(idStartName + chrome.i18n.getMessage("Mins") + index);
+ let seconds = document.getElementById(idStartName + chrome.i18n.getMessage("Secs") + index);
- minutes.value = getTimeInMinutes(response.currentTime);
- seconds.value = getTimeInFormattedSeconds(response.currentTime);
+ minutes.value = getTimeInMinutes(response.currentTime);
+ seconds.value = getTimeInFormattedSeconds(response.currentTime);
+ });
});
- });
- }
+ }
- //id start name is whether it is the startTime or endTime
- //gives back the time in seconds
- function getSponsorTimeEditTimes(idStartName, index) {
- let minutes = document.getElementById(idStartName + chrome.i18n.getMessage("Mins") + index);
- let seconds = document.getElementById(idStartName + chrome.i18n.getMessage("Secs") + index);
+ //id start name is whether it is the startTime or endTime
+ //gives back the time in seconds
+ function getSponsorTimeEditTimes(idStartName, index) {
+ let minutes = document.getElementById(idStartName + chrome.i18n.getMessage("Mins") + index);
+ let seconds = document.getElementById(idStartName + chrome.i18n.getMessage("Secs") + index);
- return parseInt(minutes.value) * 60 + parseFloat(seconds.value);
- }
-
- function saveSponsorTimeEdit(index, closeEditMode = true) {
- sponsorTimes[index][0] = getSponsorTimeEditTimes("startTime", index);
- sponsorTimes[index][1] = getSponsorTimeEditTimes("endTime", index);
-
- //save this
- let sponsorTimeKey = "sponsorTimes" + currentVideoID;
- chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes}, function() {
- chrome.tabs.query({
- active: true,
- currentWindow: true
- }, tabs => {
- chrome.tabs.sendMessage(
- tabs[0].id,
- {message: "sponsorDataChanged"}
- );
- });
- });
-
- if (closeEditMode) {
- displaySponsorTimes();
-
- showSubmitTimesIfNecessary();
+ return parseInt(minutes.value) * 60 + parseFloat(seconds.value);
}
- }
-
- //deletes the sponsor time submitted at an index
- function deleteSponsorTime(index) {
- //if it is not a complete sponsor time
- if (sponsorTimes[index].length < 2) {
- chrome.tabs.query({
- active: true,
- currentWindow: true
- }, function(tabs) {
- chrome.tabs.sendMessage(tabs[0].id, {
- message: "changeStartSponsorButton",
- showStartSponsor: true,
- uploadButtonVisible: false
+
+ function saveSponsorTimeEdit(index, closeEditMode = true) {
+ sponsorTimes[index][0] = getSponsorTimeEditTimes("startTime", index);
+ sponsorTimes[index][1] = getSponsorTimeEditTimes("endTime", index);
+
+ //save this
+ let sponsorTimeKey = "sponsorTimes" + currentVideoID;
+ chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes}, function() {
+ chrome.tabs.query({
+ active: true,
+ currentWindow: true
+ }, tabs => {
+ chrome.tabs.sendMessage(
+ tabs[0].id,
+ {message: "sponsorDataChanged"}
+ );
+ });
});
- });
- resetStartTimeChosen();
+ if (closeEditMode) {
+ displaySponsorTimes();
+
+ showSubmitTimesIfNecessary();
+ }
}
- sponsorTimes.splice(index, 1);
+ //deletes the sponsor time submitted at an index
+ function deleteSponsorTime(index) {
+ //if it is not a complete sponsor time
+ if (sponsorTimes[index].length < 2) {
+ chrome.tabs.query({
+ active: true,
+ currentWindow: true
+ }, function(tabs) {
+ chrome.tabs.sendMessage(tabs[0].id, {
+ message: "changeStartSponsorButton",
+ showStartSponsor: true,
+ uploadButtonVisible: false
+ });
+ });
- //save this
- let sponsorTimeKey = "sponsorTimes" + currentVideoID;
- chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes}, function() {
- chrome.tabs.query({
- active: true,
- currentWindow: true
- }, tabs => {
- chrome.tabs.sendMessage(
- tabs[0].id,
- {message: "sponsorDataChanged"}
- );
- });
- });
+ resetStartTimeChosen();
+ }
- //update display
- displaySponsorTimes();
-
- //if they are all removed
- if (sponsorTimes.length == 0) {
- //update chrome tab
- chrome.tabs.query({
- active: true,
- currentWindow: true
- }, function(tabs) {
- chrome.tabs.sendMessage(tabs[0].id, {
- message: "changeStartSponsorButton",
- showStartSponsor: true,
- uploadButtonVisible: false
- });
- });
+ sponsorTimes.splice(index, 1);
- //hide submission section
- document.getElementById("submissionSection").style.display = "none";
- }
- }
-
- function clearTimes() {
- //send new sponsor time state to tab
- if (sponsorTimes.length > 0) {
- chrome.tabs.query({
- active: true,
- currentWindow: true
- }, function(tabs) {
- chrome.tabs.sendMessage(tabs[0].id, {
- message: "changeStartSponsorButton",
- showStartSponsor: true,
- uploadButtonVisible: false
+ //save this
+ let sponsorTimeKey = "sponsorTimes" + currentVideoID;
+ chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes}, function() {
+ chrome.tabs.query({
+ active: true,
+ currentWindow: true
+ }, tabs => {
+ chrome.tabs.sendMessage(
+ tabs[0].id,
+ {message: "sponsorDataChanged"}
+ );
+ });
});
- });
+
+ //update display
+ displaySponsorTimes();
+
+ //if they are all removed
+ if (sponsorTimes.length == 0) {
+ //update chrome tab
+ chrome.tabs.query({
+ active: true,
+ currentWindow: true
+ }, function(tabs) {
+ chrome.tabs.sendMessage(tabs[0].id, {
+ message: "changeStartSponsorButton",
+ showStartSponsor: true,
+ uploadButtonVisible: false
+ });
+ });
+
+ //hide submission section
+ document.getElementById("submissionSection").style.display = "none";
+ }
}
- //reset sponsorTimes
- sponsorTimes = [];
+ function clearTimes() {
+ //send new sponsor time state to tab
+ if (sponsorTimes.length > 0) {
+ chrome.tabs.query({
+ active: true,
+ currentWindow: true
+ }, function(tabs) {
+ chrome.tabs.sendMessage(tabs[0].id, {
+ message: "changeStartSponsorButton",
+ showStartSponsor: true,
+ uploadButtonVisible: false
+ });
+ });
+ }
- let sponsorTimeKey = "sponsorTimes" + currentVideoID;
- chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes}, function() {
- chrome.tabs.query({
- active: true,
- currentWindow: true
- }, tabs => {
- chrome.tabs.sendMessage(
- tabs[0].id,
- {message: "sponsorDataChanged"}
- );
- });
- });
+ //reset sponsorTimes
+ sponsorTimes = [];
- displaySponsorTimes();
+ let sponsorTimeKey = "sponsorTimes" + currentVideoID;
+ chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes}, function() {
+ chrome.tabs.query({
+ active: true,
+ currentWindow: true
+ }, tabs => {
+ chrome.tabs.sendMessage(
+ tabs[0].id,
+ {message: "sponsorDataChanged"}
+ );
+ });
+ });
- //hide submission section
- document.getElementById("submissionSection").style.display = "none";
+ displaySponsorTimes();
- resetStartTimeChosen();
- }
+ //hide submission section
+ document.getElementById("submissionSection").style.display = "none";
- function submitTimes() {
- //make info message say loading
- SB.submitTimesInfoMessage.innerText = chrome.i18n.getMessage("Loading");
- SB.submitTimesInfoMessageContainer.style.display = "unset";
+ resetStartTimeChosen();
+ }
- if (sponsorTimes.length > 0) {
- chrome.runtime.sendMessage({
- message: "submitTimes",
- videoID: currentVideoID
- }, function(response) {
- if (response != undefined) {
- if (response.statusCode == 200) {
- //hide loading message
- SB.submitTimesInfoMessageContainer.style.display = "none";
+ function submitTimes() {
+ //make info message say loading
+ SB.submitTimesInfoMessage.innerText = chrome.i18n.getMessage("Loading");
+ SB.submitTimesInfoMessageContainer.style.display = "unset";
+
+ if (sponsorTimes.length > 0) {
+ chrome.runtime.sendMessage({
+ message: "submitTimes",
+ videoID: currentVideoID
+ }, function(response) {
+ if (response != undefined) {
+ if (response.statusCode == 200) {
+ //hide loading message
+ SB.submitTimesInfoMessageContainer.style.display = "none";
- clearTimes();
- } else {
- let errorMessage = getErrorMessage(response.statusCode);
+ clearTimes();
+ } else {
+ let errorMessage = getErrorMessage(response.statusCode);
- document.getElementById("submitTimesInfoMessage").innerText = errorMessage;
- document.getElementById("submitTimesInfoMessageContainer").style.display = "unset";
+ document.getElementById("submitTimesInfoMessage").innerText = errorMessage;
+ document.getElementById("submitTimesInfoMessageContainer").style.display = "unset";
- SB.submitTimesInfoMessageContainer.style.display = "unset";
- }
+ SB.submitTimesInfoMessageContainer.style.display = "unset";
+ }
+ }
+ });
}
- });
}
- }
- function showNoticeAgain() {
- chrome.storage.sync.set({"dontShowNoticeAgain": false});
+ function showNoticeAgain() {
+ chrome.storage.sync.set({"dontShowNoticeAgain": false});
- chrome.tabs.query({
- active: true,
- currentWindow: true
- }, function(tabs) {
- chrome.tabs.sendMessage(tabs[0].id, {
- message: "showNoticeAgain"
- });
- });
+ chrome.tabs.query({
+ active: true,
+ currentWindow: true
+ }, function(tabs) {
+ chrome.tabs.sendMessage(tabs[0].id, {
+ message: "showNoticeAgain"
+ });
+ });
- SB.showNoticeAgain.style.display = "none";
- }
+ SB.showNoticeAgain.style.display = "none";
+ }
- function hideVideoPlayerControls() {
- chrome.storage.sync.set({"hideVideoPlayerControls": true});
+ function hideVideoPlayerControls() {
+ chrome.storage.sync.set({"hideVideoPlayerControls": true});
- chrome.tabs.query({
- active: true,
- currentWindow: true
- }, function(tabs) {
- chrome.tabs.sendMessage(tabs[0].id, {
- message: "changeVideoPlayerControlsVisibility",
- value: true
- });
- });
+ chrome.tabs.query({
+ active: true,
+ currentWindow: true
+ }, function(tabs) {
+ chrome.tabs.sendMessage(tabs[0].id, {
+ message: "changeVideoPlayerControlsVisibility",
+ value: true
+ });
+ });
+
+ SB.hideVideoPlayerControls.style.display = "none";
+ SB.showVideoPlayerControls.style.display = "unset";
+ }
- SB.hideVideoPlayerControls.style.display = "none";
- SB.showVideoPlayerControls.style.display = "unset";
- }
+ function showVideoPlayerControls() {
+ chrome.storage.sync.set({"hideVideoPlayerControls": false});
- function showVideoPlayerControls() {
- chrome.storage.sync.set({"hideVideoPlayerControls": false});
+ chrome.tabs.query({
+ active: true,
+ currentWindow: true
+ }, function(tabs) {
+ chrome.tabs.sendMessage(tabs[0].id, {
+ message: "changeVideoPlayerControlsVisibility",
+ value: false
+ });
+ });
- chrome.tabs.query({
- active: true,
- currentWindow: true
- }, function(tabs) {
- chrome.tabs.sendMessage(tabs[0].id, {
- message: "changeVideoPlayerControlsVisibility",
- value: false
- });
- });
+ SB.hideVideoPlayerControls.style.display = "unset";
+ SB.showVideoPlayerControls.style.display = "none";
+ }
- SB.hideVideoPlayerControls.style.display = "unset";
- SB.showVideoPlayerControls.style.display = "none";
- }
+ function hideInfoButtonPlayerControls() {
+ chrome.storage.sync.set({"hideInfoButtonPlayerControls": true});
- function hideInfoButtonPlayerControls() {
- chrome.storage.sync.set({"hideInfoButtonPlayerControls": true});
+ chrome.tabs.query({
+ active: true,
+ currentWindow: true
+ }, function(tabs) {
+ chrome.tabs.sendMessage(tabs[0].id, {
+ message: "changeInfoButtonPlayerControlsVisibility",
+ value: true
+ });
+ });
- chrome.tabs.query({
- active: true,
- currentWindow: true
- }, function(tabs) {
- chrome.tabs.sendMessage(tabs[0].id, {
- message: "changeInfoButtonPlayerControlsVisibility",
- value: true
- });
- });
+ SB.hideInfoButtonPlayerControls.style.display = "none";
+ SB.showInfoButtonPlayerControls.style.display = "unset";
+ }
- SB.hideInfoButtonPlayerControls.style.display = "none";
- SB.showInfoButtonPlayerControls.style.display = "unset";
- }
+ function showInfoButtonPlayerControls() {
+ chrome.storage.sync.set({"hideInfoButtonPlayerControls": false});
- function showInfoButtonPlayerControls() {
- chrome.storage.sync.set({"hideInfoButtonPlayerControls": false});
+ chrome.tabs.query({
+ active: true,
+ currentWindow: true
+ }, function(tabs) {
+ chrome.tabs.sendMessage(tabs[0].id, {
+ message: "changeVideoPlayerCochangeInfoButtonPlayerControlsVisibilityntrolsVisibility",
+ value: false
+ });
+ });
- chrome.tabs.query({
- active: true,
- currentWindow: true
- }, function(tabs) {
- chrome.tabs.sendMessage(tabs[0].id, {
- message: "changeVideoPlayerCochangeInfoButtonPlayerControlsVisibilityntrolsVisibility",
- value: false
- });
- });
+ SB.hideInfoButtonPlayerControls.style.display = "unset";
+ SB.showInfoButtonPlayerControls.style.display = "none";
+ }
- SB.hideInfoButtonPlayerControls.style.display = "unset";
- SB.showInfoButtonPlayerControls.style.display = "none";
- }
+ function hideDeleteButtonPlayerControls() {
+ chrome.storage.sync.set({"hideDeleteButtonPlayerControls": true});
- function hideDeleteButtonPlayerControls() {
- chrome.storage.sync.set({"hideDeleteButtonPlayerControls": true});
+ chrome.tabs.query({
+ active: true,
+ currentWindow: true
+ }, function(tabs) {
+ chrome.tabs.sendMessage(tabs[0].id, {
+ message: "changeDeleteButtonPlayerControlsVisibility",
+ value: true
+ });
+ });
- chrome.tabs.query({
- active: true,
- currentWindow: true
- }, function(tabs) {
- chrome.tabs.sendMessage(tabs[0].id, {
- message: "changeDeleteButtonPlayerControlsVisibility",
- value: true
- });
- });
+ SB.hideDeleteButtonPlayerControls.style.display = "none";
+ SB.showDeleteButtonPlayerControls.style.display = "unset";
+ }
- SB.hideDeleteButtonPlayerControls.style.display = "none";
- SB.showDeleteButtonPlayerControls.style.display = "unset";
- }
+ function showDeleteButtonPlayerControls() {
+ chrome.storage.sync.set({"hideDeleteButtonPlayerControls": false});
- function showDeleteButtonPlayerControls() {
- chrome.storage.sync.set({"hideDeleteButtonPlayerControls": false});
+ chrome.tabs.query({
+ active: true,
+ currentWindow: true
+ }, function(tabs) {
+ chrome.tabs.sendMessage(tabs[0].id, {
+ message: "changeVideoPlayerCochangeDeleteButtonPlayerControlsVisibilityntrolsVisibility",
+ value: false
+ });
+ });
- chrome.tabs.query({
- active: true,
- currentWindow: true
- }, function(tabs) {
- chrome.tabs.sendMessage(tabs[0].id, {
- message: "changeVideoPlayerCochangeDeleteButtonPlayerControlsVisibilityntrolsVisibility",
- value: false
- });
- });
+ SB.hideDeleteButtonPlayerControls.style.display = "unset";
+ SB.showDeleteButtonPlayerControls.style.display = "none";
+ }
- SB.hideDeleteButtonPlayerControls.style.display = "unset";
- SB.showDeleteButtonPlayerControls.style.display = "none";
- }
+ function disableSponsorViewTracking() {
+ chrome.storage.sync.set({"trackViewCount": false});
- function disableSponsorViewTracking() {
- chrome.storage.sync.set({"trackViewCount": false});
+ chrome.tabs.query({
+ active: true,
+ currentWindow: true
+ }, function(tabs) {
+ chrome.tabs.sendMessage(tabs[0].id, {
+ message: "trackViewCount",
+ value: false
+ });
+ });
- chrome.tabs.query({
- active: true,
- currentWindow: true
- }, function(tabs) {
- chrome.tabs.sendMessage(tabs[0].id, {
- message: "trackViewCount",
- value: false
- });
- });
+ SB.disableSponsorViewTracking.style.display = "none";
+ SB.enableSponsorViewTracking.style.display = "unset";
+ }
- SB.disableSponsorViewTracking.style.display = "none";
- SB.enableSponsorViewTracking.style.display = "unset";
- }
+ function enableSponsorViewTracking() {
+ chrome.storage.sync.set({"trackViewCount": true});
- function enableSponsorViewTracking() {
- chrome.storage.sync.set({"trackViewCount": true});
+ chrome.tabs.query({
+ active: true,
+ currentWindow: true
+ }, function(tabs) {
+ chrome.tabs.sendMessage(tabs[0].id, {
+ message: "trackViewCount",
+ value: true
+ });
+ });
- chrome.tabs.query({
- active: true,
- currentWindow: true
- }, function(tabs) {
- chrome.tabs.sendMessage(tabs[0].id, {
- message: "trackViewCount",
- value: true
- });
- });
+ SB.enableSponsorViewTracking.style.display = "none";
+ SB.disableSponsorViewTracking.style.display = "unset";
+ }
- SB.enableSponsorViewTracking.style.display = "none";
- SB.disableSponsorViewTracking.style.display = "unset";
- }
-
- function updateStartTimeChosen() {
- //update startTimeChosen letiable
- if (!startTimeChosen) {
- startTimeChosen = true;
- SB.sponsorStart.innerHTML = chrome.i18n.getMessage("sponsorEnd");
- } else {
- resetStartTimeChosen();
+ function updateStartTimeChosen() {
+ //update startTimeChosen letiable
+ if (!startTimeChosen) {
+ startTimeChosen = true;
+ SB.sponsorStart.innerHTML = chrome.i18n.getMessage("sponsorEnd");
+ } else {
+ resetStartTimeChosen();
+ }
}
- }
-
- //set it to false
- function resetStartTimeChosen() {
- startTimeChosen = false;
- SB.sponsorStart.innerHTML = "SP_START";
- }
-
- //hides and shows the submit times button when needed
- 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("submitTimesContainer").style.display = "unset";
- } else {
- //hide submit times button
- document.getElementById("submitTimesContainer").style.display = "none";
+
+ //set it to false
+ function resetStartTimeChosen() {
+ startTimeChosen = false;
+ SB.sponsorStart.innerHTML = "SP_START";
}
- }
- //make the options div visible
- function openOptions() {
- document.getElementById("optionsButtonContainer").style.display = "none";
- document.getElementById("options").style.display = "unset";
- }
+ //hides and shows the submit times button when needed
+ 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("submitTimesContainer").style.display = "unset";
+ } else {
+ //hide submit times button
+ document.getElementById("submitTimesContainer").style.display = "none";
+ }
+ }
+
+ //make the options div visible
+ function openOptions() {
+ document.getElementById("optionsButtonContainer").style.display = "none";
+ document.getElementById("options").style.display = "unset";
+ }
- //make the options username setting option visible
- function setUsernameButton() {
- //get the userID
- chrome.storage.sync.get(["userID"], function(result) {
- //get username from the server
- sendRequestToServer("GET", "/api/getUsername?userID=" + result.userID, function (xmlhttp, error) {
- if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
- SB.usernameInput.value = JSON.parse(xmlhttp.responseText).userName;
+ //make the options username setting option visible
+ function setUsernameButton() {
+ //get the userID
+ chrome.storage.sync.get(["userID"], function(result) {
+ //get username from the server
+ sendRequestToServer("GET", "/api/getUsername?userID=" + result.userID, function (xmlhttp, error) {
+ if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
+ SB.usernameInput.value = JSON.parse(xmlhttp.responseText).userName;
- SB.submitUsername.style.display = "unset";
- SB.usernameInput.style.display = "unset";
+ SB.submitUsername.style.display = "unset";
+ SB.usernameInput.style.display = "unset";
- SB.setUsernameContainer.style.display = "none";
- SB.setUsername.style.display = "unset";
- } else {
- SB.setUsername.style.display = "unset";
- SB.submitUsername.style.display = "none";
- SB.usernameInput.style.display = "none";
+ SB.setUsernameContainer.style.display = "none";
+ SB.setUsername.style.display = "unset";
+ } else {
+ SB.setUsername.style.display = "unset";
+ SB.submitUsername.style.display = "none";
+ SB.usernameInput.style.display = "none";
- SB.setUsernameStatus.innerText = "Couldn't connect to server. Error code: " + xmlhttp.status;
- }
- });
- });
- }
+ SB.setUsernameStatus.innerText = "Couldn't connect to server. Error code: " + xmlhttp.status;
+ }
+ });
+ });
+ }
- //submit the new username
- function submitUsername() {
- //add loading indicator
- SB.setUsernameStatusContainer.style.display = "unset";
- SB.setUsernameStatus.innerText = "Loading...";
+ //submit the new username
+ function submitUsername() {
+ //add loading indicator
+ SB.setUsernameStatusContainer.style.display = "unset";
+ SB.setUsernameStatus.innerText = "Loading...";
- //get the userID
- chrome.storage.sync.get(["userID"], function(result) {
- sendRequestToServer("POST", "/api/setUsername?userID=" + result.userID + "&username=" + SB.usernameInput.value, function (xmlhttp, error) {
- if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
- //submitted
- SB.submitUsername.style.display = "none";
- SB.usernameInput.style.display = "none";
+ //get the userID
+ chrome.storage.sync.get(["userID"], function(result) {
+ sendRequestToServer("POST", "/api/setUsername?userID=" + result.userID + "&username=" + SB.usernameInput.value, function (xmlhttp, error) {
+ if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
+ //submitted
+ SB.submitUsername.style.display = "none";
+ SB.usernameInput.style.display = "none";
- SB.setUsernameStatus.innerText = "Success!";
- } else if (xmlhttp.readyState == 4 && xmlhttp.status == 400) {
- SB.setUsernameStatus.innerText = "Bad Request";
- } else {
- SB.setUsernameStatus.innerText = getErrorMessage(EN_US, xmlhttp.status);
- }
- });
- });
+ SB.setUsernameStatus.innerText = "Success!";
+ } else if (xmlhttp.readyState == 4 && xmlhttp.status == 400) {
+ SB.setUsernameStatus.innerText = "Bad Request";
+ } else {
+ SB.setUsernameStatus.innerText = getErrorMessage(EN_US, xmlhttp.status);
+ }
+ });
+ });
- SB.setUsernameContainer.style.display = "none";
- SB.setUsername.style.display = "unset";
- }
-
- //this is not a YouTube video page
- function displayNoVideo() {
- document.getElementById("loadingIndicator").innerText = chrome.i18n.getMessage("noVideoID");
- }
-
- function reportAnIssue() {
- document.getElementById("issueReporterContainer").style.display = "unset";
- SB.reportAnIssue.style.display = "none";
- }
-
- function addVoteMessage(message, UUID) {
- let container = document.getElementById("sponsorTimesVoteButtonsContainer" + UUID);
- //remove all children
- while (container.firstChild) {
- container.removeChild(container.firstChild);
+ SB.setUsernameContainer.style.display = "none";
+ SB.setUsername.style.display = "unset";
}
- let thanksForVotingText = document.createElement("h2");
- thanksForVotingText.innerText = message;
- //there are already breaks there
- thanksForVotingText.style.marginBottom = "0px";
-
- container.appendChild(thanksForVotingText);
- }
-
- function vote(type, UUID) {
- //add loading info
- addVoteMessage("Loading...", UUID)
-
- //send the vote message to the tab
- chrome.runtime.sendMessage({
- message: "submitVote",
- type: type,
- UUID: UUID
- }, function(response) {
- if (response != undefined) {
- //see if it was a success or failure
- if (response.successType == 1) {
- //success
- addVoteMessage(chrome.i18n.getMessage("Voted"), UUID)
- } else if (response.successType == 0) {
- //failure: duplicate vote
- addVoteMessage(chrome.i18n.getMessage("voteFail"), UUID)
- } else if (response.successType == -1) {
- if (response.statusCode == 502) {
- addVoteMessage(chrome.i18n.getMessage("serverDown"), UUID)
- } else {
- //failure: unknown error
- addVoteMessage(chrome.i18n.getMessage("connectionError") + response.statusCode, UUID)
- }
+ //this is not a YouTube video page
+ function displayNoVideo() {
+ document.getElementById("loadingIndicator").innerText = chrome.i18n.getMessage("noVideoID");
+ }
+
+ function reportAnIssue() {
+ document.getElementById("issueReporterContainer").style.display = "unset";
+ SB.reportAnIssue.style.display = "none";
+ }
+
+ function addVoteMessage(message, UUID) {
+ let container = document.getElementById("sponsorTimesVoteButtonsContainer" + UUID);
+ //remove all children
+ while (container.firstChild) {
+ container.removeChild(container.firstChild);
}
- }
- });
- }
- function hideDiscordButton() {
- chrome.storage.sync.set({"hideDiscordLink": false});
+ let thanksForVotingText = document.createElement("h2");
+ thanksForVotingText.innerText = message;
+ //there are already breaks there
+ thanksForVotingText.style.marginBottom = "0px";
- SB.discordButtonContainer.style.display = "none";
- }
+ container.appendChild(thanksForVotingText);
+ }
+
+ function vote(type, UUID) {
+ //add loading info
+ addVoteMessage("Loading...", UUID)
+
+ //send the vote message to the tab
+ chrome.runtime.sendMessage({
+ message: "submitVote",
+ type: type,
+ UUID: UUID
+ }, function(response) {
+ if (response != undefined) {
+ //see if it was a success or failure
+ if (response.successType == 1) {
+ //success
+ addVoteMessage(chrome.i18n.getMessage("Voted"), UUID)
+ } else if (response.successType == 0) {
+ //failure: duplicate vote
+ addVoteMessage(chrome.i18n.getMessage("voteFail"), UUID)
+ } else if (response.successType == -1) {
+ if (response.statusCode == 502) {
+ addVoteMessage(chrome.i18n.getMessage("serverDown"), UUID)
+ } else {
+ //failure: unknown error
+ addVoteMessage(chrome.i18n.getMessage("connectionError") + response.statusCode, UUID)
+ }
+ }
+ }
+ });
+ }
- //converts time in seconds to minutes:seconds
- function getFormattedTime(seconds) {
- let minutes = Math.floor(seconds / 60);
- let secondsDisplay = Math.round(seconds - minutes * 60);
- if (secondsDisplay < 10) {
- //add a zero
- secondsDisplay = "0" + secondsDisplay;
+ function hideDiscordButton() {
+ chrome.storage.sync.set({"hideDiscordLink": false});
+
+ SB.discordButtonContainer.style.display = "none";
}
- let formatted = minutes+ ":" + secondsDisplay;
+ //converts time in seconds to minutes:seconds
+ function getFormattedTime(seconds) {
+ let minutes = Math.floor(seconds / 60);
+ let secondsDisplay = Math.round(seconds - minutes * 60);
+ if (secondsDisplay < 10) {
+ //add a zero
+ secondsDisplay = "0" + secondsDisplay;
+ }
+
+ let formatted = minutes+ ":" + secondsDisplay;
- return formatted;
- }
+ 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 = [];
- }
+ 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);
+ //add on this channel
+ whitelistedChannels.push(response.channelURL);
- //change button
- SB.whitelistChannel.style.display = "none";
- SB.unwhitelistChannel.style.display = "unset";
+ //change button
+ SB.whitelistChannel.style.display = "none";
+ SB.unwhitelistChannel.style.display = "unset";
- SB.downloadedSponsorMessageTimes.innerText = "Channel Whitelisted!";
- SB.downloadedSponsorMessageTimes.style.fontWeight = "bold";
+ SB.downloadedSponsorMessageTimes.innerText = "Channel Whitelisted!";
+ SB.downloadedSponsorMessageTimes.style.fontWeight = "bold";
- //save this
- chrome.storage.sync.set({whitelistedChannels: whitelistedChannels});
+ //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
- });
- }
+ //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 = [];
- }
+ 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);
+ //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";
+ //change button
+ SB.whitelistChannel.style.display = "unset";
+ SB.unwhitelistChannel.style.display = "none";
- SB.downloadedSponsorMessageTimes.innerText = "";
- SB.downloadedSponsorMessageTimes.style.fontWeight = "unset";
+ SB.downloadedSponsorMessageTimes.innerText = "";
+ SB.downloadedSponsorMessageTimes.style.fontWeight = "unset";
- //save this
- chrome.storage.sync.set({whitelistedChannels: whitelistedChannels});
+ //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
- });
- }
+ //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) {
- let minutes = Math.floor(seconds / 60);
+ //converts time in seconds to minutes
+ function getTimeInMinutes(seconds) {
+ let minutes = Math.floor(seconds / 60);
- return minutes;
- }
+ return minutes;
+ }
- //converts time in seconds to seconds past the last minute
- function getTimeInFormattedSeconds(seconds) {
- let secondsFormatted = (seconds % 60).toFixed(3);
+ //converts time in seconds to seconds past the last minute
+ function getTimeInFormattedSeconds(seconds) {
+ let secondsFormatted = (seconds % 60).toFixed(3);
- if (secondsFormatted < 10) {
- secondsFormatted = "0" + secondsFormatted;
- }
+ if (secondsFormatted < 10) {
+ secondsFormatted = "0" + secondsFormatted;
+ }
- return secondsFormatted;
- }
+ return secondsFormatted;
+ }
- function sendRequestToServer(type, address, callback) {
- let xmlhttp = new XMLHttpRequest();
+ function sendRequestToServer(type, address, callback) {
+ let xmlhttp = new XMLHttpRequest();
- xmlhttp.open(type, serverAddress + address, true);
+ xmlhttp.open(type, serverAddress + address, true);
- if (callback != undefined) {
- xmlhttp.onreadystatechange = function () {
- callback(xmlhttp, false);
- };
+ if (callback != undefined) {
+ xmlhttp.onreadystatechange = function () {
+ callback(xmlhttp, false);
+ };
- xmlhttp.onerror = function(ev) {
- callback(xmlhttp, true);
- };
- }
+ xmlhttp.onerror = function(ev) {
+ callback(xmlhttp, true);
+ };
+ }
- //submit this request
- xmlhttp.send();
- }
+ //submit this request
+ xmlhttp.send();
+ }
//end of function
}
if (chrome.tabs != undefined) {
- //add the width restriction (because Firefox)
- document.getElementById("sponorBlockStyleSheet").sheet.insertRule('.popupBody { width: 300 }', 0);
+ //add the width restriction (because Firefox)
+ document.getElementById("sponorBlockStyleSheet").sheet.insertRule('.popupBody { width: 300 }', 0);
- //this means it is actually opened in the popup
- runThePopup();
+ //this means it is actually opened in the popup
+ runThePopup();
}