Merge branch 'experimental' of https://github.com/ajayyy/SponsorBlock into experimental-ajay

# Conflicts:
#	manifest.json
This commit is contained in:
Ajay Ramachandran 2019-08-13 18:23:56 -04:00
commit ea41980fc6
7 changed files with 163 additions and 72 deletions

112
_locales/en/messages.json Normal file
View file

@ -0,0 +1,112 @@
{
"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"
},
"Segment": {
"message": "sponsor segment"
},
"Segments": {
"message": "sponsor segments"
},
"Dismiss": {
"message": "Dismiss"
},
"Loading": {
"message": "Loading..."
},
"Mins": {
"message": "Minutes"
},
"Secs": {
"message": "Seconds"
},
"Hide": {
"message": "Don't Show This Again"
},
"hitGoBack": {
"message": "Hit go back to get to where you came from."
},
"goBack": {
"message": "Go back"
},
"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": "Thanks for voting!"
},
"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)."
},
"Popup": {
"message": "popup_en.html"
}
}

View file

@ -56,7 +56,8 @@ chrome.runtime.onInstalled.addListener(function (object) {
// TODO (shownInstallPage): remove this if statement, but leave contents
if (!shownInstallPage){
//open up the install page
chrome.tabs.create({url: chrome.extension.getURL("/help/index.html")});
chrome.tabs.create({url: chrome.extension.getURL("/help/"+chrome.i18n.getMessage("helpPage"))});
}
// TODO (shownInstallPage): delete if statement and contents

View file

@ -521,7 +521,7 @@ function addPlayerControlsButton() {
let startSponsorButton = document.createElement("button");
startSponsorButton.id = "startSponsorButton";
startSponsorButton.className = "ytp-button playerButton";
startSponsorButton.setAttribute("title", "Sponsor Starts Now");
startSponsorButton.setAttribute("title", chrome.i18n.getMessage("sponsorStart"));
startSponsorButton.addEventListener("click", startSponsorClicked);
let startSponsorImage = document.createElement("img");
@ -613,7 +613,7 @@ function changeStartSponsorButton(showStartSponsor, uploadButtonVisible) {
if (showStartSponsor) {
showingStartSponsor = true;
document.getElementById("startSponsorImage").src = chrome.extension.getURL("icons/PlayerStartIconSponsorBlocker256px.png");
document.getElementById("startSponsorButton").setAttribute("title", "Sponsor Starts Now");
document.getElementById("startSponsorButton").setAttribute("title", chrome.i18n.getMessage("sponsorStart"));
if (document.getElementById("startSponsorImage").style.display != "none" && uploadButtonVisible && !hideInfoButtonPlayerControls) {
document.getElementById("submitButton").style.display = "unset";
@ -624,7 +624,7 @@ function changeStartSponsorButton(showStartSponsor, uploadButtonVisible) {
} else {
showingStartSponsor = false;
document.getElementById("startSponsorImage").src = chrome.extension.getURL("icons/PlayerStopIconSponsorBlocker256px.png");
document.getElementById("startSponsorButton").setAttribute("title", "Sponsor Ends Now");
document.getElementById("startSponsorButton").setAttribute("title", chrome.i18n.getMessage("sponsorEND"));
//disable submit button
document.getElementById("submitButton").style.display = "none";
@ -812,8 +812,8 @@ function clearSponsorTimes() {
let sponsorTimes = result[sponsorTimeKey];
if (sponsorTimes != undefined && sponsorTimes.length > 0) {
let confirmMessage = "Are you sure you want to clear this?\n\n" + getSponsorTimesMessage(sponsorTimes);
confirmMessage += "\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."
let confirmMessage = chrome.i18n.getMessage("clearThis") + getSponsorTimesMessage(sponsorTimes);
confirmMessage += chrome.i18n.getMessage("confirmMSG")
if(!confirm(confirmMessage)) return;
//clear the sponsor times
@ -894,17 +894,17 @@ function openSkipNotice(UUID){
buttonContainer.setAttribute("align", "center");
let goBackButton = document.createElement("button");
goBackButton.innerText = "Go back";
goBackButton.innerText = chrome.i18n.getMessage("goBack");
goBackButton.className = "sponsorSkipButton";
goBackButton.addEventListener("click", () => goBackToPreviousTime(UUID));
let hideButton = document.createElement("button");
hideButton.innerText = "Dismiss";
hideButton.innerText = chrome.i18n.getMessage("Dismiss");
hideButton.className = "sponsorSkipButton";
hideButton.addEventListener("click", () => closeSkipNotice(UUID));
let dontShowAgainButton = document.createElement("button");
dontShowAgainButton.innerText = "Don't Show This Again";
dontShowAgainButton.innerText = chrome.i18n.getMessage("Hide");
dontShowAgainButton.className = "sponsorSkipDontShowButton";
dontShowAgainButton.addEventListener("click", dontShowNoticeAgain);
@ -959,12 +959,12 @@ function afterDownvote(UUID) {
//add thanks for voting text
let thanksForVotingText = document.createElement("p");
thanksForVotingText.id = "sponsorTimesThanksForVotingText";
thanksForVotingText.innerText = "Thanks for voting!"
thanksForVotingText.innerText = chrome.i18n.getMessage("Voted");
//add extra info for voting
let thanksForVotingInfoText = document.createElement("p");
thanksForVotingInfoText.id = "sponsorTimesThanksForVotingInfoText";
thanksForVotingInfoText.innerText = "Hit go back to get to where you came from."
thanksForVotingInfoText.innerText = chrome.i18n.getMessage("hitGoBack");
//add element to div
document.getElementById("sponsorTimesVoteButtonsContainer" + UUID).appendChild(thanksForVotingText);
@ -1039,15 +1039,14 @@ function vote(type, UUID) {
}
} else if (response.successType == 0) {
//failure: duplicate vote
addLoadingInfo("It seems you've already voted before", UUID)
addLoadingInfo(chrome.i18n.getMessage("voteFAIL"), UUID)
} else if (response.successType == -1) {
if (response.statusCode == 502) {
addLoadingInfo("It seems the sever is down. Contact the dev immediately.", UUID)
addLoadingInfo(chrome.i18n.getMessage("serverDown"), UUID)
} else {
//failure: unknown error
addLoadingInfo("A connection error has occured. Error code: " + response.statusCode, UUID)
addLoadingInfo(chrome.i18n.getMessage("connectionError") + response.statusCode, UUID);
}
}
}
});
@ -1157,16 +1156,10 @@ function sendSubmitMessage(){
document.getElementById("submitButton").style.animation = "unset";
document.getElementById("submitButtonImage").src = chrome.extension.getURL("icons/PlayerUploadFailedIconSponsorBlocker256px.png");
if(response.statusCode == 400) {
alert("Server said this request was invalid");
} else if(response.statusCode == 429) {
alert("You have submitted too many sponsor times for this one video, are you sure there are this many?");
} else if(response.statusCode == 409) {
alert("This has already been submitted before");
} else if(response.statusCode == 502) {
alert("It seems the server is down. Contact the dev to inform them. Error code " + response.statusCode);
if([400,429,409,502].includes(response.statusCode)) {
alert(chrome.i18n.getMessage(response.statusCode));
} else {
alert("There was an error submitting your sponsor times, please try again later. Error code " + response.statusCode);
alert(chrome.i18n.getMessage("connectionError") + response.statusCode);
}
}
}

View file

@ -119,4 +119,4 @@
</center>
</body>
</body>

View file

@ -1,8 +1,9 @@
{
"name": "SponsorBlock for YouTube - Skip Sponsorships",
"short_name": "SponsorBlock",
"name": "__MSG_fullName__",
"short_name": "__MSG_Name__",
"version": "1.0.36",
"description": "Skip over sponsorship on YouTube videos. Report sponsors on videos you watch to save the time of others.",
"default_locale": "en",
"description": "__MSG_Description__",
"content_scripts": [
{
"matches": [
@ -42,8 +43,8 @@
"https://sponsor.ajay.app/*"
],
"browser_action": {
"default_title": "SponsorBlock",
"default_popup": "popup.html"
"default_title": "__MSG_Name__",
"default_popup": "__MSG_Popup__"
},
"background": {
"scripts":[

View file

@ -91,15 +91,6 @@ function runThePopup() {
SB.optionsButton.addEventListener("click", openOptions);
SB.reportAnIssue.addEventListener("click", reportAnIssue);
SB.hideDiscordButton.addEventListener("click", hideDiscordButton);
//setup error message languages
var EN_US = new Map();
EN_US.set(400, 'Server said this request was invalid"')
.set(429, 'You have submitted too many sponsor times for this one video, are you sure there are this many?')
.set(409, 'This has already been submitted before')
.set(502, 'It seems the server is down. Contact the dev to inform them.')
.set('Unknown', 'There was an error submitting your sponsor times, please try again later.');
//if true, the button now selects the end time
let startTimeChosen = false;
@ -178,9 +169,9 @@ function runThePopup() {
chrome.storage.sync.get(["sponsorTimesContributed"], function(result) {
if (result.sponsorTimesContributed != undefined) {
if (result.sponsorTimesContributed > 1) {
SB.sponsorTimesContributionsDisplayEndWord.innerText = "sponsors."
SB.sponsorTimesContributionsDisplayEndWord.innerText = chrome.i18n.getMessage("Sponsors");
} else {
SB.sponsorTimesContributionsDisplayEndWord.innerText = "sponsor."
SB.sponsorTimesContributionsDisplayEndWord.innerText = chrome.i18n.getMessage("Sponsor");
}
SB.sponsorTimesContributionsDisplay.innerText = result.sponsorTimesContributed;
SB.sponsorTimesContributionsContainer.style.display = "unset";
@ -196,9 +187,9 @@ function runThePopup() {
let viewCount = JSON.parse(xmlhttp.responseText).viewCount;
if (viewCount != 0) {
if (viewCount > 1) {
SB.sponsorTimesViewsDisplayEndWord.innerText = "sponsor segments."
SB.sponsorTimesViewsDisplayEndWord.innerText = chrome.i18n.getMessage("Segments");
} else {
SB.sponsorTimesViewsDisplayEndWord.innerText = "sponsor segment."
SB.sponsorTimesViewsDisplayEndWord.innerText = chrome.i18n.getMessage("Segment");
}
SB.sponsorTimesViewsDisplay.innerText = viewCount;
@ -219,13 +210,12 @@ function runThePopup() {
function onTabs(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {message: 'getVideoID'}, function(result) {
if (result != undefined && result.videoID) {
currentVideoID = result.videoID;
loadTabData(tabs);
currentVideoID = result.videoID;
loadTabData(tabs);
} else if (result == undefined && chrome.runtime.lastError) {
//this isn't a YouTube video then, or at least the content script is not loaded
displayNoVideo();
}
//this isn't a YouTube video then, or at least the content script is not loaded
displayNoVideo();
}
});
}
@ -243,7 +233,7 @@ function runThePopup() {
if (sponsorTimesStorage != undefined && sponsorTimesStorage.length > 0) {
if (sponsorTimesStorage[sponsorTimesStorage.length - 1] != undefined && sponsorTimesStorage[sponsorTimesStorage.length - 1].length < 2) {
startTimeChosen = true;
SB.sponsorStart.innerHTML = "Sponsorship Ends Now";
SB.sponsorStart.innerHTML = chrome.i18n.getMessage("sponsorEND");
}
sponsorTimes = sponsorTimesStorage;
@ -283,11 +273,11 @@ function runThePopup() {
SB.loadingIndicator.innerHTML = "";
if (request.found) {
SB.videoFound.innerHTML = "This video's sponsors are in the database!"
SB.videoFound.innerHTML = chrome.i18n.getMessage("sponsorFound");
displayDownloadedSponsorTimes(request);
} else {
SB.videoFound.innerHTML = "No sponsors found"
SB.videoFound.innerHTML = chrome.i18n.getMessage("sponsor404");
}
}
@ -385,7 +375,7 @@ function runThePopup() {
function displayDownloadedSponsorTimes(request) {
if (request.sponsorTimes != undefined) {
//set it to the message
if (SB.downloadedSponsorMessageTimes.innerText != "Channel Whitelisted!") {
if (SB.downloadedSponsorMessageTimes.innerText != chrome.i18n.getMessage("channelWhitelisted")) {
SB.downloadedSponsorMessageTimes.innerText = getSponsorTimesMessage(request.sponsorTimes);
}
@ -654,8 +644,8 @@ function runThePopup() {
tabs[0].id,
{message: "getCurrentTime"},
function (response) {
let minutes = document.getElementById(idStartName + "Minutes" + index);
let seconds = document.getElementById(idStartName + "Seconds" + index);
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);
@ -666,8 +656,8 @@ function runThePopup() {
//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 + "Minutes" + index);
let seconds = document.getElementById(idStartName + "Seconds" + 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);
}
@ -792,14 +782,9 @@ function runThePopup() {
resetStartTimeChosen();
}
function getErrorMessage(lang, statusCode) {
if(lang.has(statusCode)) return lang.get(statusCode);
return lang.get('Unknown').concat(" Error code: ") + statusCode;
}
function submitTimes() {
//make info message say loading
SB.submitTimesInfoMessage.innerText = "Loading...";
SB.submitTimesInfoMessage.innerText = chrome.i18n.getMessage("Loading");
SB.submitTimesInfoMessageContainer.style.display = "unset";
if (sponsorTimes.length > 0) {
@ -814,7 +799,7 @@ function runThePopup() {
clearTimes();
} else {
let errorMessage = getErrorMessage(EN_US, response.statusCode);
let errorMessage = getErrorMessage(response.statusCode);
document.getElementById("submitTimesInfoMessage").innerText = errorMessage;
document.getElementById("submitTimesInfoMessageContainer").style.display = "unset";
@ -981,7 +966,7 @@ function runThePopup() {
//update startTimeChosen letiable
if (!startTimeChosen) {
startTimeChosen = true;
SB.sponsorStart.innerHTML = "Sponsorship Ends Now";
SB.sponsorStart.innerHTML = chrome.i18n.getMessage("sponsorEND");
} else {
resetStartTimeChosen();
}
@ -990,7 +975,7 @@ function runThePopup() {
//set it to false
function resetStartTimeChosen() {
startTimeChosen = false;
SB.sponsorStart.innerHTML = "Sponsorship Starts Now";
SB.sponsorStart.innerHTML = "SP_START";
}
//hides and shows the submit times button when needed
@ -1066,8 +1051,7 @@ function runThePopup() {
//this is not a YouTube video page
function displayNoVideo() {
document.getElementById("loadingIndicator").innerHTML = "This probably isn't a YouTube tab, or you clicked too early. " +
"If you know this is a YouTube tab, close this popup and open it again.";
document.getElementById("loadingIndicator").innerHTML = chrome.i18n.getMessage("sponsor404");
}
function reportAnIssue() {
@ -1104,16 +1088,16 @@ function runThePopup() {
//see if it was a success or failure
if (response.successType == 1) {
//success
addVoteMessage("Thanks for voting!", UUID)
addVoteMessage(chrome.i18n.getMessage("Voted"), UUID)
} else if (response.successType == 0) {
//failure: duplicate vote
addVoteMessage("You have already voted this way before.", UUID)
addVoteMessage(chrome.i18n.getMessage("voteFAIL"), UUID)
} else if (response.successType == -1) {
if (response.statusCode == 502) {
addVoteMessage("It seems the sever is down. Contact the dev immediately.", UUID)
addVoteMessage(chrome.i18n.getMessage("serverDown"), UUID)
} else {
//failure: unknown error
addVoteMessage("A connection error has occured. Error code: " + response.statusCode, UUID)
addVoteMessage(chrome.i18n.getMessage("connectionError") + response.statusCode, UUID)
}
}
}