Merge pull request #143 from ajayyy/experimental-ajay

More Localisation + Fixed Whitelisting
This commit is contained in:
Ajay Ramachandran 2019-08-31 22:07:41 -04:00 committed by GitHub
commit 85b70f8ad7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 251 additions and 82 deletions

View file

@ -31,10 +31,10 @@
"message": "Channel Whitelisted!"
},
"Sponsor": {
"message": "Sponsor"
"message": "sponsor"
},
"Sponsors": {
"message": "Sponsors"
"message": "sponsors"
},
"Segment": {
"message": "sponsor segment"
@ -136,6 +136,102 @@
"submitCheck": {
"message": "Are you sure you want to submit this?"
},
"whitelistChannel": {
"message": "Whitelist Channel"
},
"removeFromWhitelist": {
"message": "Remove Channel From Whitelist"
},
"whitelistDescription": {
"message": "Whitelist the channels who do sponsorships ethically to encourage good behavior, or maybe if they are just entertaining and funny. Or don't, that's your call."
},
"voteOnTime": {
"message": "Vote On A Sponsor Time"
},
"recordTimes": {
"message": "Record the times of a sponsorship"
},
"soFarUHSubmited": {
"message": "So far, you've submitted"
},
"savedPeopleFrom": {
"message": "You have saved people from "
},
"viewLeaderboard": {
"message": "View the leaderboard"
},
"here": {
"message": "here"
},
"recordTimesDescription": {
"message": "Click the button below when the sponsorship starts and ends to record and\nsubmit it to the database."
},
"popupHint": {
"message": "Hint: Press the semicolon key while focused on a video report the start/end of a sponsor and quote to submit."
},
"lastTimes": {
"message": "Latest Sponsor Message Times Chosen"
},
"clearTimesButton": {
"message": "Clear Times"
},
"submitTimesButton": {
"message": "Submit Times"
},
"publicStats": {
"message": "This is used on the public stats page to show off how much you've contributed. See it"
},
"setUsername": {
"message": "Set Username"
},
"discordAdvert": {
"message": "Come join the official discord server to give suggestions and feedback!"
},
"hideThis": {
"message": "Hide this"
},
"Options": {
"message": "Options"
},
"showButtons": {
"message": "Hide Buttons On YouTube Player"
},
"hideButtons": {
"message": "Show Buttons On YouTube Player"
},
"hideButtonsDescription": {
"message": "This hides the buttons that appear on the YouTube player to submit sponsors. I can see this being annoying for some\n people. Instead of using the button there, this popup can be used to submit sponsors. To hide the notice that appears, \n use the button that appears on the notice saying \"Don't show this again\". You can always enable these settings again later."
},
"showInfoButton": {
"message": "Show Info Button On YouTube Player"
},
"hideInfoButton": {
"message": "Hide Info Button On YouTube Player"
},
"whatInfoButton": {
"message": "This is the button that opens up a popup in the YouTube page."
},
"hideDeleteButton": {
"message": "Hide Delete Button On YouTube Player"
},
"showDeleteButton": {
"message": "Show Delete Button On YouTube Player"
},
"whatDeleteButton": {
"message": "This is the button that allows you to clear all sponsors on the YouTube player."
},
"disableViewTracking": {
"message": "Disable Sponsor View Tracking"
},
"enableViewTracking": {
"message": "Enable Sponsor View Tracking"
},
"whatViewTracking": {
"message": "This feature tracks which sponsors you have skipped to let users know how much their submission has helped others and\nused as a metric along with upvotes to ensure that spam doesn't get into the database. The extension sends a message\nto the server each time you skip a sponsor. Hopefully most people don't change this setting so that the view numbers are accurate. :)"
},
"showNotice": {
"message": "Show Notice Again"
},
"longDescription": {
"message": "SponsorBlock is an extension that will skip over sponsored segments of YouTube videos. SponsorBlock is a crowdsourced browser extension that let's anyone submit the start and end time's of sponsored segments of YouTube videos. Once one person submits this information, everyone else with this extension will skip right over the sponsored segment.",
"description": "Full description of the extension on the store pages."

View file

@ -24,6 +24,9 @@ var durationListenerSetUp = false;
//the channel this video is about
var channelURL;
//the title of the last video loaded. Used to make sure the channel URL has been updated yet.
var title;
//is this channel whitelised from getting sponsors skipped
var channelWhitelisted = false;
@ -194,16 +197,16 @@ function messageListener(request, sender, sendResponse) {
//check for hotkey pressed
document.onkeydown = function(e){
e = e || window.event;
var key = e.which || e.keyCode;
var key = e.key;
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){
if(key == ';'){
//semicolon
startSponsorClicked();
} else if (key == 222) {
} else if (key == "'") {
//single quote
submitSponsorTimes();
}
@ -235,7 +238,10 @@ function videoIDChange(id) {
//set the global videoID
sponsorVideoID = id;
resetValues();
resetValues();
let channelIDPromise = wait(getChannelID);
channelIDPromise.then(() => channelIDPromise.isFulfilled = true).catch(() => channelIDPromise.isRejected = true)
//id is not valid
if (!id) return;
@ -275,7 +281,7 @@ function videoIDChange(id) {
//close popup
closeInfoMenu();
sponsorsLookup(id);
sponsorsLookup(id, channelIDPromise);
//make sure everything is properly added
updateVisibilityOfPlayerControlsButton();
@ -334,7 +340,7 @@ function videoIDChange(id) {
}
function sponsorsLookup(id) {
function sponsorsLookup(id, channelIDPromise) {
v = document.querySelector('video') // Youtube video player
//there is no video here
if (v == null) {
@ -348,9 +354,8 @@ function sponsorsLookup(id) {
//wait until it is loaded
v.addEventListener('durationchange', updatePreviewBar);
}
//check database for sponsor times
//check database for sponsor times
//made true once a setTimeout has been created to try again after a server error
let recheckStarted = false;
sendRequestToServer('GET', "/api/getVideoSponsorTimes?videoID=" + id, function(xmlhttp) {
@ -368,7 +373,17 @@ function sponsorsLookup(id) {
updatePreviewBar();
}
getChannelID();
if (channelIDPromise != null) {
if (channelIDPromise.isFulfilled) {
whitelistCheck();
} else if (channelIDPromise.isRejected) {
//try again
wait(getChannelID).then(whitelistCheck).catch();
} else {
//add it as a then statement
channelIDPromise.then(whitelistCheck);
}
}
sponsorLookupRetries = 0;
} else if (xmlhttp.readyState == 4 && xmlhttp.status == 404) {
@ -376,7 +391,7 @@ function sponsorsLookup(id) {
//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) {
sendRequestToCustomServer('GET', "https://invidio.us/api/v1/videos/" + id + '?fields=published', function(xmlhttp, error) {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
let unixTimePublished = JSON.parse(xmlhttp.responseText).published;
@ -427,12 +442,13 @@ function updatePreviewBar() {
function getChannelID() {
//get channel id
let channelContainers = document.querySelectorAll("#owner-name");
let channelContainers = document.querySelectorAll(".ytd-channel-name#text");
let channelURLContainer = null;
for (let i = 0; i < channelContainers.length; i++) {
if (channelContainers[i].firstElementChild != null) {
channelURLContainer = channelContainers[i].firstElementChild;
let child = channelContainers[i].firstElementChild;
if (child != null && child.getAttribute("href") != "") {
channelURLContainer = child;
}
}
@ -446,12 +462,34 @@ function getChannelID() {
if (channelURLContainer == null) {
//try later
setTimeout(getChannelID, 100);
return;
return false;
}
//first get the title to make sure a title change has occurred (otherwise the next video might still be loading)
let titleInfoContainer = document.getElementById("info-contents");
let currentTitle = "";
if (titleInfoContainer != null) {
currentTitle = titleInfoContainer.firstElementChild.firstElementChild.querySelector(".title").firstElementChild.innerText;
} else {
//old YouTube theme
currentTitle = document.getElementById("eow-title").innerText;
}
if (title == currentTitle) {
//video hasn't changed yet, wait
//try later
return false;
}
title = currentTitle;
channelURL = channelURLContainer.getAttribute("href");
//reset variables
channelWhitelisted = false;
}
//checks if this channel is whitelisted, should be done only after the channelID has been loaded
function whitelistCheck() {
//see if this is a whitelisted channel
chrome.storage.sync.get(["whitelistedChannels"], function(result) {
let whitelistedChannels = result.whitelistedChannels;
@ -462,6 +500,23 @@ function getChannelID() {
UUIDs = [];
channelWhitelisted = true;
//make sure the whitelistedChannels array isn't broken and full of null entries
//TODO: remove this at some point in the future as the bug that caused this should be patched
if (whitelistedChannels.some((el) => el === null)) {
//remove the entries that are null
let cleanWhitelistedChannelsArray = [];
for (let i = 0; i < whitelistedChannels.length; i++) {
let channelURL = whitelistedChannels[i];
if (channelURL !== null) {
//add it
cleanWhitelistedChannelsArray.push(channelURL);
}
}
//save this value
chrome.storage.sync.set({"whitelistedChannels": cleanWhitelistedChannelsArray});
}
}
});
}
@ -603,29 +658,30 @@ function getControls() {
};
//adds all the player controls buttons
function createButtons() {
wait(getControls).then(result => {
//set global controls variable
controls = result;
async function createButtons() {
let result = await wait(getControls).catch();
// Add button if does not already exist in html
createButton("startSponsor", "sponsorStart", startSponsorClicked, "PlayerStartIconSponsorBlocker256px.png");
createButton("info", "openPopup", openInfoMenu, "PlayerInfoIconSponsorBlocker256px.png")
createButton("delete", "clearTimes", clearSponsorTimes, "PlayerDeleteIconSponsorBlocker256px.png");
createButton("submit", "SubmitTimes", submitSponsorTimes, "PlayerUploadIconSponsorBlocker256px.png");
});
//set global controls variable
controls = result;
// Add button if does not already exist in html
createButton("startSponsor", "sponsorStart", startSponsorClicked, "PlayerStartIconSponsorBlocker256px.png");
createButton("info", "openPopup", openInfoMenu, "PlayerInfoIconSponsorBlocker256px.png")
createButton("delete", "clearTimes", clearSponsorTimes, "PlayerDeleteIconSponsorBlocker256px.png");
createButton("submit", "SubmitTimes", submitSponsorTimes, "PlayerUploadIconSponsorBlocker256px.png");
}
//adds or removes the player controls button to what it should be
function updateVisibilityOfPlayerControlsButton() {
async function updateVisibilityOfPlayerControlsButton() {
//not on a proper video yet
if (!sponsorVideoID) return;
createButtons();
await createButtons();
if (hideVideoPlayerControls) {
removePlayerControlsButton();
}
if (hideInfoButtonPlayerControls) {
//don't show the info button on embeds
if (hideInfoButtonPlayerControls || document.URL.includes("/embed/")) {
document.getElementById("infoButton").style.display = "none";
}
if (hideDeleteButtonPlayerControls) {
@ -763,8 +819,10 @@ function closeInfoMenu() {
if (popup != null) {
popup.remove();
//show info button
document.getElementById("infoButton").style.display = "unset";
//show info button if it's not an embed
if (!document.URL.includes("/embed/")) {
document.getElementById("infoButton").style.display = "unset";
}
}
}

View file

@ -1,7 +1,7 @@
{
"name": "__MSG_fullName__",
"short_name": "__MSG_Name__",
"version": "1.1.7",
"version": "1.1.8",
"default_locale": "en",
"description": "__MSG_Description__",
"content_scripts": [

View file

@ -1,6 +1,6 @@
<html>
<head>
<title>SponsorBlock Popup</title>
<title>__MSG_openPopup__</title>
<link id="sponorBlockPopupFont" rel="stylesheet" type="text/css" href="/libs/Source+Sans+Pro.css"/>
<link id="sponorBlockStyleSheet" rel="stylesheet" type="text/css" href="popup.css"/>
</head>
@ -10,10 +10,10 @@
<div id="app" class="popupBody">
<img src="icons/LogoSponsorBlocker256px.png" height="64px" id="sponsorBlockPopupLogo"/>
<h1 class="popupElement">SponsorBlock</h1>
<h1 class="popupElement">__MSG_Name__</h1>
<!-- Loading text -->
<p id="loadingIndicator" class="popupElement">Loading...</p>
<p id="loadingIndicator" class="popupElement">__MSG_Loading__</p>
<!-- Hidden until loading complete -->
<div id="mainControls" class="main popupElement" style="display: none">
@ -29,21 +29,21 @@
<br/>
<div>
<button id="whitelistChannel" class="whitelistButton popupElement">Whitelist Channel</button>
<button id="unwhitelistChannel" class="whitelistButton popupElement" style="display: none">Remove Channel From Whitelist</button>
<button id="whitelistChannel" class="whitelistButton popupElement">__MSG_whitelistChannel__</button>
<button id="unwhitelistChannel" class="whitelistButton popupElement" style="display: none">__MSG_removeFromWhitelist__</button>
</div>
<sub class="popupElement">
Whitelist the channels who do sponsorships ethically to encourage good behavior, or maybe if they are just entertaining and funny. Or don't, that's your call.
__MSG_whitelistDescription__
</sub>
<br/>
<br/>
<button id="reportAnIssue" class="dangerButton popupElement">Vote On A Sponsor Time</button>
<button id="reportAnIssue" class="dangerButton popupElement">__MSG_voteOnTime__</button>
<div id="issueReporterContainer" class="popupElement" style="display: none">
<h3 style="margin-top: 0px" class="popupElement">Vote On A Sponsor Time</h3>
<h3 style="margin-top: 0px" class="popupElement">__MSG_voteOnTime__</h3>
<div id="issueReporterTimeButtons" class="popupElement">
@ -51,47 +51,47 @@
</div>
<h2 class="recordingSubtitle popupElement">Record the times of a sponsorship</h2>
<h2 class="recordingSubtitle popupElement">__MSG_recordTimes__</h2>
<p class="popupElement">
<span id=sponsorTimesContributionsContainer class="popupElement" style="display: none">
So far, you've submitted
__MSG_soFarUHSubmited__
<span id="sponsorTimesContributionsDisplay" class="popupElement">
0
</span>
<span id="sponsorTimesContributionsDisplayEndWord" class="popupElement">
sponsors.
__MSG_Sponsors__.
</span>
</span>
<span id=sponsorTimesViewsContainer class="popupElement" style="display: none">
You have saved people from
__MSG_savedPeopleFrom__
<span id="sponsorTimesViewsDisplay" class="popupElement">
0
</span>
<span id="sponsorTimesViewsDisplayEndWord" class="popupElement">
sponsor segments.
__MSG_Segments__.
__MSG_savedPeopleFrom__
</span>
</span>
<div class="popupElement">
View the leaderboard <a class="popupElement discreteLink" href="https://sponsor.ajay.app/stats" target="_blank">here</a>.
__MSG_viewLeaderboard__ <a class="popupElement discreteLink" href="https://sponsor.ajay.app/stats" target="_blank">__MSG_here__</a>.
</div>
</p>
<p class="popupElement">
Click the button below when the sponsorship starts and ends to record and
submit it to the database.
__MSG_recordTimesDescription__
</p>
<div>
<button id="sponsorStart" class="greenButton popupElement">Sponsorship Starts Now</button>
<button id="sponsorStart" class="greenButton popupElement">__MSG_sponsorStart__</button>
</div>
<sub class="popupElement">Hint: Press the semicolon key while focused on a video report the start/end of a sponsor and quote to submit.</sub>
<sub class="popupElement">__MSG_popupHint__</sub>
<div id="submissionSection" class="popupElement" style="display: none">
<h3 class="popupElement">Latest Sponsor Message Times Chosen</h3>
<h3 class="popupElement">__MSG_lastTimes__</h3>
<b>
<div id="sponsorMessageTimes" class="popupElement">
@ -100,13 +100,13 @@
<br/>
<button id="clearTimes" class="smallButton popupElement">Clear Times</button>
<button id="clearTimes" class="smallButton popupElement">__MSG_clearTimesButton__</button>
<br/>
<br/>
<div id="submitTimesContainer" class="popupElement" style="display: none">
<button id="submitTimes" class="smallButton popupElement">Submit Times</button>
<button id="submitTimes" class="smallButton popupElement">__MSG_submitTimesButton__</button>
<div id="submitTimesInfoMessageContainer" class="popupElement" style="display: none">
<h3 id="submitTimesInfoMessage" class="popupElement">
@ -122,17 +122,17 @@
<br/>
<br/>
<button id="setUsernameButton" class="warningButton popupElement">Set Username</button>
<button id="setUsernameButton" class="warningButton popupElement">__MSG_setUsername__</button>
<br/>
<sub class="popupElement">
This is used on the public stats page to show off how much you've contributed. See it <a class="popupElement discreteLink" href="https://sponsor.ajay.app/stats" target="_blank">here</a>.
__MSG_publicStats__ <a class="popupElement discreteLink" href="https://sponsor.ajay.app/stats" target="_blank">__MSG_here__</a>.
</sub>
</div>
<div id="setUsername" class="popupElement" style="display: none">
<br/>
<h3>Set Username</h3>
<h3>__MSG_setUsername__</h3>
<div id="setUsernameStatusContainer" style="display: none">
<h2 id="setUsernameStatus"></h2>
@ -154,72 +154,66 @@
<br/>
Come join the official discord server to give suggestions and feedback!
__MSG_discordAdvert__
<br/>
<span id="hideDiscordButton" class="smallLink popupElement">Hide this</span>
<span id="hideDiscordButton" class="smallLink popupElement">__MSG_hideThis__</span>
</div>
<div id="optionsButtonContainer" class="popupElement">
<br/>
<br/>
<button id="optionsButton" class="dangerButton popupElement">Options</button>
<button id="optionsButton" class="dangerButton popupElement">__MSG_Options__</button>
</div>
<div id="options" class="popupElement" style="display: none">
<br/>
<h3>Options</h3>
<h3>__MSG_Options__</h3>
<button id="hideVideoPlayerControls" class="warningButton popupElement">Hide Buttons On YouTube Player</button>
<button id="showVideoPlayerControls" style="display: none" class="warningButton popupElement">Show Buttons On YouTube Player</button>
<button id="hideVideoPlayerControls" class="warningButton popupElement">__MSG_hideButtons__</button>
<button id="showVideoPlayerControls" style="display: none" class="warningButton popupElement">__MSG_showButtons__</button>
<br/>
<sub class="popupElement">
This hides the buttons that appear on the YouTube player to submit sponsors. I can see this being annoying for some
people. Instead of using the button there, this popup can be used to submit sponsors. To hide the notice that appears,
use the button that appears on the notice saying "Don't show this again". You can always enable these settings again
later.
__MSG_hideButtonsDescription__
</sub>
<br/>
<br/>
<button id="hideInfoButtonPlayerControls" class="warningButton popupElement">Hide Info Button On YouTube Player</button>
<button id="showInfoButtonPlayerControls" style="display: none" class="warningButton popupElement">Show Info Button On YouTube Player</button>
<button id="hideInfoButtonPlayerControls" class="warningButton popupElement">__MSG_hideInfoButton__</button>
<button id="showInfoButtonPlayerControls" style="display: none" class="warningButton popupElement">__MSG_showInfoButton__</button>
<br/>
<sub class="popupElement">
This is the button that opens up a popup in the YouTube page.
__MSG_whatInfoButton__
</sub>
<br/>
<br/>
<button id="hideDeleteButtonPlayerControls" class="warningButton popupElement">Hide Delete Button On YouTube Player</button>
<button id="showDeleteButtonPlayerControls" style="display: none" class="warningButton popupElement">Show Delete Button On YouTube Player</button>
<button id="hideDeleteButtonPlayerControls" class="warningButton popupElement">__MSG_hideDeleteButton__</button>
<button id="showDeleteButtonPlayerControls" style="display: none" class="warningButton popupElement">__MSG_showDeleteButton__</button>
<br/>
<sub class="popupElement">
This is the button that allows you to clear all sponsors on the YouTube player.
__MSG_whatDeleteButton__
</sub>
<br/>
<br/>
<button id="disableSponsorViewTracking" class="warningButton popupElement">Disable Sponsor View Tracking</button>
<button id="enableSponsorViewTracking" style="display: none" class="warningButton popupElement">Enable Sponsor View Tracking</button>
<button id="disableSponsorViewTracking" class="warningButton popupElement">__MSG_disableViewTracking__</button>
<button id="enableSponsorViewTracking" style="display: none" class="warningButton popupElement">__MSG_enableViewTracking__</button>
<br/>
<sub class="popupElement">
This feature tracks which sponsors you have skipped to let users know how much their submission has helped others and
used as a metric along with upvotes to ensure that spam doesn't get into the database. The extension sends a message
to the server each time you skip a sponsor. Hopefully most people don't change this setting so that the view numbers
are accurate. :)
__MSG_whatViewTracking__
</sub>
<br/>
<br/>
<button id="showNoticeAgain" style="display: none" class="dangerButton popupElement">Show Notice Again</button>
<button id="showNoticeAgain" style="display: none" class="dangerButton popupElement">__MSG_showNotice__</button>
</div>
</div>
</div>

View file

@ -1,6 +1,7 @@
//make this a function to allow this to run on the content page
function runThePopup() {
localizeHtmlPage();
//is it in the popup or content script
var inPopup = true;

View file

@ -43,6 +43,26 @@ function getYouTubeVideoID(url) {
return false;
}
}
return false;
}
function localizeHtmlPage() {
//Localize by replacing __MSG_***__ meta tags
var objects = document.getElementsByClassName("popupBody")[0].children;
for (var j = 0; j < objects.length; j++) {
var obj = objects[j];
var valStrH = obj.innerHTML.toString();
var valNewH = valStrH.replace(/__MSG_(\w+)__/g, function(match, v1)
{
return v1 ? chrome.i18n.getMessage(v1) : "";
});
if(valNewH != valStrH)
{
obj.innerHTML = valNewH;
}
}
}
return false;
}