mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-12 22:47:18 +03:00
98
popup.js
98
popup.js
@@ -1,14 +1,29 @@
|
|||||||
|
// References
|
||||||
|
SB.sponsorStart = document.getElementById("sponsorStart");
|
||||||
|
SB.clearTimes = document.getElementById("clearTimes");
|
||||||
|
SB.submitTimes = document.getElementById("submitTimes");
|
||||||
|
SB.showNoticeAgain = document.getElementById("showNoticeAgain");
|
||||||
|
SB.hideVideoPlayerControls = document.getElementById("hideVideoPlayerControls");
|
||||||
|
SB.showVideoPlayerControls = document.getElementById("showVideoPlayerControls");
|
||||||
|
SB.disableSponsorViewTracking = document.getElementById("disableSponsorViewTracking");
|
||||||
|
SB.enableSponsorViewTracking = document.getElementById("enableSponsorViewTracking");
|
||||||
|
SB.optionsButton = document.getElementById("optionsButton");
|
||||||
|
SB.reportAnIssue = document.getElementById("reportAnIssue");
|
||||||
|
// sponsorTimesContributions
|
||||||
|
SB.sponsorTimesContributionsContainer = document.getElementById("sponsorTimesContributionsContainer");
|
||||||
|
SB.sponsorTimesContributionsDisplay = document.getElementById("sponsorTimesContributionsDisplay");
|
||||||
|
SB.sponsorTimesContributionsDisplayEndWord = document.getElementById("sponsorTimesContributionsDisplayEndWord");
|
||||||
//setup click listeners
|
//setup click listeners
|
||||||
document.getElementById("sponsorStart").addEventListener("click", sendSponsorStartMessage);
|
SB.sponsorStart.addEventListener("click", sendSponsorStartMessage);
|
||||||
document.getElementById("clearTimes").addEventListener("click", clearTimes);
|
SB.clearTimes.addEventListener("click", clearTimes);
|
||||||
document.getElementById("submitTimes").addEventListener("click", submitTimes);
|
SB.submitTimes.addEventListener("click", submitTimes);
|
||||||
document.getElementById("showNoticeAgain").addEventListener("click", showNoticeAgain);
|
SB.showNoticeAgain.addEventListener("click", showNoticeAgain);
|
||||||
document.getElementById("hideVideoPlayerControls").addEventListener("click", hideVideoPlayerControls);
|
SB.hideVideoPlayerControls.addEventListener("click", hideVideoPlayerControls);
|
||||||
document.getElementById("showVideoPlayerControls").addEventListener("click", showVideoPlayerControls);
|
SB.showVideoPlayerControls.addEventListener("click", showVideoPlayerControls);
|
||||||
document.getElementById("disableSponsorViewTracking").addEventListener("click", disableSponsorViewTracking);
|
SB.disableSponsorViewTracking.addEventListener("click", disableSponsorViewTracking);
|
||||||
document.getElementById("enableSponsorViewTracking").addEventListener("click", enableSponsorViewTracking);
|
SB.enableSponsorViewTracking.addEventListener("click", enableSponsorViewTracking);
|
||||||
document.getElementById("optionsButton").addEventListener("click", openOptions);
|
SB.optionsButton.addEventListener("click", openOptions);
|
||||||
document.getElementById("reportAnIssue").addEventListener("click", reportAnIssue);
|
SB.reportAnIssue.addEventListener("click", reportAnIssue);
|
||||||
|
|
||||||
//if true, the button now selects the end time
|
//if true, the button now selects the end time
|
||||||
var startTimeChosen = false;
|
var startTimeChosen = false;
|
||||||
@@ -27,7 +42,7 @@ var isYouTubeTab = false;
|
|||||||
chrome.storage.sync.get(["dontShowNoticeAgain"], function(result) {
|
chrome.storage.sync.get(["dontShowNoticeAgain"], function(result) {
|
||||||
let dontShowNoticeAgain = result.dontShowNoticeAgain;
|
let dontShowNoticeAgain = result.dontShowNoticeAgain;
|
||||||
if (dontShowNoticeAgain != undefined && dontShowNoticeAgain) {
|
if (dontShowNoticeAgain != undefined && dontShowNoticeAgain) {
|
||||||
document.getElementById("showNoticeAgain").style.display = "unset";
|
SB.showNoticeAgain.style.display = "unset";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -35,8 +50,8 @@ chrome.storage.sync.get(["dontShowNoticeAgain"], function(result) {
|
|||||||
chrome.storage.sync.get(["hideVideoPlayerControls"], function(result) {
|
chrome.storage.sync.get(["hideVideoPlayerControls"], function(result) {
|
||||||
let hideVideoPlayerControls = result.hideVideoPlayerControls;
|
let hideVideoPlayerControls = result.hideVideoPlayerControls;
|
||||||
if (hideVideoPlayerControls != undefined && hideVideoPlayerControls) {
|
if (hideVideoPlayerControls != undefined && hideVideoPlayerControls) {
|
||||||
document.getElementById("hideVideoPlayerControls").style.display = "none";
|
SB.hideVideoPlayerControls.style.display = "none";
|
||||||
document.getElementById("showVideoPlayerControls").style.display = "unset";
|
SB.showVideoPlayerControls.style.display = "unset";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -44,25 +59,21 @@ chrome.storage.sync.get(["hideVideoPlayerControls"], function(result) {
|
|||||||
chrome.storage.sync.get(["trackViewCount"], function(result) {
|
chrome.storage.sync.get(["trackViewCount"], function(result) {
|
||||||
let trackViewCount = result.trackViewCount;
|
let trackViewCount = result.trackViewCount;
|
||||||
if (trackViewCount != undefined && !trackViewCount) {
|
if (trackViewCount != undefined && !trackViewCount) {
|
||||||
document.getElementById("disableSponsorViewTracking").style.display = "none";
|
SB.disableSponsorViewTracking.style.display = "none";
|
||||||
document.getElementById("enableSponsorViewTracking").style.display = "unset";
|
SB.enableSponsorViewTracking.style.display = "unset";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//get the amount of times this user has contributed and display it to thank them
|
//get the amount of times this user has contributed and display it to thank them
|
||||||
chrome.storage.sync.get(["sponsorTimesContributed"], function(result) {
|
chrome.storage.sync.get(["sponsorTimesContributed"], function(result) {
|
||||||
if (result.sponsorTimesContributed != undefined) {
|
if (result.sponsorTimesContributed != undefined) {
|
||||||
let sponsorTimesContributionsContainer = document.getElementById("sponsorTimesContributionsContainer");
|
|
||||||
let sponsorTimesContributionsDisplay = document.getElementById("sponsorTimesContributionsDisplay");
|
|
||||||
let sponsorTimesContributionsDisplayEndWord = document.getElementById("sponsorTimesContributionsDisplayEndWord");
|
|
||||||
|
|
||||||
if (result.sponsorTimesContributed > 1) {
|
if (result.sponsorTimesContributed > 1) {
|
||||||
sponsorTimesContributionsDisplayEndWord.innerText = "sponsors."
|
SB.sponsorTimesContributionsDisplayEndWord.innerText = "sponsors."
|
||||||
} else {
|
} else {
|
||||||
sponsorTimesContributionsDisplayEndWord.innerText = "sponsor."
|
SB.sponsorTimesContributionsDisplayEndWord.innerText = "sponsor."
|
||||||
}
|
}
|
||||||
sponsorTimesContributionsDisplay.innerText = result.sponsorTimesContributed;
|
SB.sponsorTimesContributionsDisplay.innerText = result.sponsorTimesContributed;
|
||||||
sponsorTimesContributionsContainer.style.display = "unset";
|
SB.sponsorTimesContributionsContainer.style.display = "unset";
|
||||||
|
|
||||||
//get the userID
|
//get the userID
|
||||||
chrome.storage.sync.get(["userID"], function(result) {
|
chrome.storage.sync.get(["userID"], function(result) {
|
||||||
@@ -73,19 +84,14 @@ chrome.storage.sync.get(["sponsorTimesContributed"], function(result) {
|
|||||||
sendRequestToServer("GET", "/api/getViewsForUser?userID=" + userID, function(xmlhttp) {
|
sendRequestToServer("GET", "/api/getViewsForUser?userID=" + userID, function(xmlhttp) {
|
||||||
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
|
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
|
||||||
let viewCount = JSON.parse(xmlhttp.responseText).viewCount;
|
let viewCount = JSON.parse(xmlhttp.responseText).viewCount;
|
||||||
|
|
||||||
if (viewCount != 0) {
|
if (viewCount != 0) {
|
||||||
let sponsorTimesViewsContainer = document.getElementById("sponsorTimesViewsContainer");
|
|
||||||
let sponsorTimesViewsDisplay = document.getElementById("sponsorTimesViewsDisplay");
|
|
||||||
let sponsorTimesViewsDisplayEndWord = document.getElementById("sponsorTimesViewsDisplayEndWord");
|
|
||||||
|
|
||||||
if (viewCount > 1) {
|
if (viewCount > 1) {
|
||||||
sponsorTimesViewsDisplayEndWord.innerText = "sponsor segments."
|
SB.sponsorTimesViewsDisplayEndWord.innerText = "sponsor segments."
|
||||||
} else {
|
} else {
|
||||||
sponsorTimesViewsDisplayEndWord.innerText = "sponsor segment."
|
SB.sponsorTimesViewsDisplayEndWord.innerText = "sponsor segment."
|
||||||
}
|
}
|
||||||
sponsorTimesViewsDisplay.innerText = viewCount;
|
SB.sponsorTimesViewsDisplay.innerText = viewCount;
|
||||||
sponsorTimesViewsContainer.style.display = "unset";
|
SB.sponsorTimesViewsContainer.style.display = "unset";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -117,7 +123,7 @@ function loadTabData(tabs) {
|
|||||||
if (sponsorTimesStorage != undefined && sponsorTimesStorage.length > 0) {
|
if (sponsorTimesStorage != undefined && sponsorTimesStorage.length > 0) {
|
||||||
if (sponsorTimesStorage[sponsorTimesStorage.length - 1] != undefined && sponsorTimesStorage[sponsorTimesStorage.length - 1].length < 2) {
|
if (sponsorTimesStorage[sponsorTimesStorage.length - 1] != undefined && sponsorTimesStorage[sponsorTimesStorage.length - 1].length < 2) {
|
||||||
startTimeChosen = true;
|
startTimeChosen = true;
|
||||||
document.getElementById("sponsorStart").innerHTML = "Sponsorship Ends Now";
|
SB.sponsorStart.innerHTML = "Sponsorship Ends Now";
|
||||||
}
|
}
|
||||||
|
|
||||||
sponsorTimes = sponsorTimesStorage;
|
sponsorTimes = sponsorTimesStorage;
|
||||||
@@ -372,7 +378,7 @@ function showNoticeAgain() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById("showNoticeAgain").style.display = "none";
|
SB.showNoticeAgain.style.display = "none";
|
||||||
}
|
}
|
||||||
|
|
||||||
function hideVideoPlayerControls() {
|
function hideVideoPlayerControls() {
|
||||||
@@ -388,8 +394,8 @@ function hideVideoPlayerControls() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById("hideVideoPlayerControls").style.display = "none";
|
SB.hideVideoPlayerControls.style.display = "none";
|
||||||
document.getElementById("showVideoPlayerControls").style.display = "unset";
|
SB.showVideoPlayerControls.style.display = "unset";
|
||||||
}
|
}
|
||||||
|
|
||||||
function showVideoPlayerControls() {
|
function showVideoPlayerControls() {
|
||||||
@@ -405,8 +411,8 @@ function showVideoPlayerControls() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById("hideVideoPlayerControls").style.display = "unset";
|
SB.hideVideoPlayerControls.style.display = "unset";
|
||||||
document.getElementById("showVideoPlayerControls").style.display = "none";
|
SB.showVideoPlayerControls.style.display = "none";
|
||||||
}
|
}
|
||||||
|
|
||||||
function disableSponsorViewTracking() {
|
function disableSponsorViewTracking() {
|
||||||
@@ -422,8 +428,8 @@ function disableSponsorViewTracking() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById("disableSponsorViewTracking").style.display = "none";
|
SB.disableSponsorViewTracking.style.display = "none";
|
||||||
document.getElementById("enableSponsorViewTracking").style.display = "unset";
|
SB.enableSponsorViewTracking.style.display = "unset";
|
||||||
}
|
}
|
||||||
|
|
||||||
function enableSponsorViewTracking() {
|
function enableSponsorViewTracking() {
|
||||||
@@ -439,15 +445,15 @@ function enableSponsorViewTracking() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById("enableSponsorViewTracking").style.display = "none";
|
SB.enableSponsorViewTracking.style.display = "none";
|
||||||
document.getElementById("disableSponsorViewTracking").style.display = "unset";
|
SB.disableSponsorViewTracking.style.display = "unset";
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateStartTimeChosen() {
|
function updateStartTimeChosen() {
|
||||||
//update startTimeChosen variable
|
//update startTimeChosen variable
|
||||||
if (!startTimeChosen) {
|
if (!startTimeChosen) {
|
||||||
startTimeChosen = true;
|
startTimeChosen = true;
|
||||||
document.getElementById("sponsorStart").innerHTML = "Sponsorship Ends Now";
|
SB.sponsorStart.innerHTML = "Sponsorship Ends Now";
|
||||||
} else {
|
} else {
|
||||||
resetStartTimeChosen();
|
resetStartTimeChosen();
|
||||||
}
|
}
|
||||||
@@ -456,7 +462,7 @@ function updateStartTimeChosen() {
|
|||||||
//set it to false
|
//set it to false
|
||||||
function resetStartTimeChosen() {
|
function resetStartTimeChosen() {
|
||||||
startTimeChosen = false;
|
startTimeChosen = false;
|
||||||
document.getElementById("sponsorStart").innerHTML = "Sponsorship Starts Now";
|
SB.sponsorStart.innerHTML = "Sponsorship Starts Now";
|
||||||
}
|
}
|
||||||
|
|
||||||
//hides and shows the submit times button when needed
|
//hides and shows the submit times button when needed
|
||||||
@@ -485,7 +491,7 @@ function displayNoVideo() {
|
|||||||
|
|
||||||
function reportAnIssue() {
|
function reportAnIssue() {
|
||||||
document.getElementById("issueReporterContainer").style.display = "unset";
|
document.getElementById("issueReporterContainer").style.display = "unset";
|
||||||
document.getElementById("reportAnIssue").style.display = "none";
|
SB.reportAnIssue.style.display = "none";
|
||||||
}
|
}
|
||||||
|
|
||||||
function addVoteMessage(message, UUID) {
|
function addVoteMessage(message, UUID) {
|
||||||
@@ -566,4 +572,4 @@ function getYouTubeVideoID(url) { // Return video id or false
|
|||||||
var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
|
var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
|
||||||
var match = url.match(regExp);
|
var match = url.match(regExp);
|
||||||
return (match && match[7].length == 11) ? match[7] : false;
|
return (match && match[7].length == 11) ? match[7] : false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user