Fixed indentation

This commit is contained in:
Ajay Ramachandran
2019-08-19 19:21:19 -04:00
parent cc2d1405b6
commit db4182d074
5 changed files with 2260 additions and 2260 deletions

View File

@@ -1,124 +1,124 @@
{ {
"Name": { "Name": {
"message": "SponsorBlock", "message": "SponsorBlock",
"description": "Name of the extension." "description": "Name of the extension."
}, },
"fullName": { "fullName": {
"message": "SponsorBlock for YouTube - Skip Sponsorships", "message": "SponsorBlock for YouTube - Skip Sponsorships",
"description": "Name of the extension." "description": "Name of the extension."
}, },
"Description": { "Description": {
"message": "Skip over sponsorship on YouTube videos. Report sponsors on videos you watch to save the time of others.", "message": "Skip over sponsorship on YouTube videos. Report sponsors on videos you watch to save the time of others.",
"description": "Description of the extension." "description": "Description of the extension."
}, },
"helpPage": { "helpPage": {
"message": "index_en.html" "message": "index_en.html"
}, },
"400": { "400": {
"message": "Server said this request was invalid" "message": "Server said this request was invalid"
}, },
"429": { "429": {
"message": "You have submitted too many sponsor times for this one video, are you sure there are this many?" "message": "You have submitted too many sponsor times for this one video, are you sure there are this many?"
}, },
"409": { "409": {
"message": "This has already been submitted before" "message": "This has already been submitted before"
}, },
"502": { "502": {
"message": "It seems the server is down. Contact the dev to inform them." "message": "It seems the server is down. Contact the dev to inform them."
}, },
"channelWhitelisted": { "channelWhitelisted": {
"message": "Channel Whitelisted!" "message": "Channel Whitelisted!"
}, },
"Sponsor": { "Sponsor": {
"message": "Sponsor" "message": "Sponsor"
}, },
"Sponsors": { "Sponsors": {
"message": "Sponsors" "message": "Sponsors"
}, },
"Segment": { "Segment": {
"message": "sponsor segment" "message": "sponsor segment"
}, },
"Segments": { "Segments": {
"message": "sponsor segments" "message": "sponsor segments"
}, },
"noticeTitle": { "noticeTitle": {
"message": "Sponsor Skipped" "message": "Sponsor Skipped"
}, },
"reportButtonTitle": { "reportButtonTitle": {
"message": "Report" "message": "Report"
}, },
"reportButtonInfo": { "reportButtonInfo": {
"message": "Report this sponsor submission as incorrect." "message": "Report this sponsor submission as incorrect."
}, },
"Dismiss": { "Dismiss": {
"message": "Dismiss" "message": "Dismiss"
}, },
"Loading": { "Loading": {
"message": "Loading..." "message": "Loading..."
}, },
"Mins": { "Mins": {
"message": "Minutes" "message": "Minutes"
}, },
"Secs": { "Secs": {
"message": "Seconds" "message": "Seconds"
}, },
"Hide": { "Hide": {
"message": "Never Show" "message": "Never Show"
}, },
"hitGoBack": { "hitGoBack": {
"message": "Hit unskip to get to where you came from." "message": "Hit unskip to get to where you came from."
}, },
"unskip": { "unskip": {
"message": "Unskip" "message": "Unskip"
}, },
"reskip": { "reskip": {
"message": "Reskip" "message": "Reskip"
}, },
"paused": { "paused": {
"message": "Paused" "message": "Paused"
}, },
"confirmMSG": { "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." "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": { "clearThis": {
"message": "Are you sure you want to clear this?\n\n" "message": "Are you sure you want to clear this?\n\n"
}, },
"Unknown": { "Unknown": {
"message": "There was an error submitting your sponsor times, please try again later." "message": "There was an error submitting your sponsor times, please try again later."
}, },
"sponsorFound": { "sponsorFound": {
"message": "This video's sponsors are in the database!" "message": "This video's sponsors are in the database!"
}, },
"sponsor404": { "sponsor404": {
"message": "No sponsors found" "message": "No sponsors found"
}, },
"sponsorStart": { "sponsorStart": {
"message": "Sponsorship Starts Now" "message": "Sponsorship Starts Now"
}, },
"sponsorEnd": { "sponsorEnd": {
"message": "Sponsorship Ends Now" "message": "Sponsorship Ends Now"
}, },
"noVideoID": { "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." "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": { "Voted": {
"message": "Voted!" "message": "Voted!"
}, },
"voteFail": { "voteFail": {
"message": "You have already voted this way before." "message": "You have already voted this way before."
}, },
"serverDown": { "serverDown": {
"message": "It seems the sever is down. Contact the dev immediately." "message": "It seems the sever is down. Contact the dev immediately."
}, },
"connectionError": { "connectionError": {
"message": "A connection error has occured. Error code: " "message": "A connection error has occured. Error code: "
}, },
"wantToSubmit": { "wantToSubmit": {
"message": "Do you want to submit the sponsor times for video id" "message": "Do you want to submit the sponsor times for video id"
}, },
"leftTimes": { "leftTimes": {
"message": "You seem to have left some sponsor times unsubmitted. Go back to that page to submit them (they are not deleted)." "message": "You seem to have left some sponsor times unsubmitted. Go back to that page to submit them (they are not deleted)."
} }
} }

View File

@@ -1,221 +1,221 @@
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) { chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
chrome.tabs.sendMessage(tabId, { chrome.tabs.sendMessage(tabId, {
message: 'update', message: 'update',
}); });
}); });
chrome.runtime.onMessage.addListener(function (request, sender, callback) { chrome.runtime.onMessage.addListener(function (request, sender, callback) {
switch(request.message) { switch(request.message) {
case "submitTimes": case "submitTimes":
submitTimes(request.videoID, callback); submitTimes(request.videoID, callback);
//this allows the callback to be called later by the submitTimes function //this allows the callback to be called later by the submitTimes function
return true; return true;
case "addSponsorTime": case "addSponsorTime":
addSponsorTime(request.time, request.videoID, callback); addSponsorTime(request.time, request.videoID, callback);
//this allows the callback to be called later //this allows the callback to be called later
return true; return true;
case "getSponsorTimes": case "getSponsorTimes":
getSponsorTimes(request.videoID, function(sponsorTimes) { getSponsorTimes(request.videoID, function(sponsorTimes) {
callback({ callback({
sponsorTimes: sponsorTimes sponsorTimes: sponsorTimes
}) })
}); });
//this allows the callback to be called later //this allows the callback to be called later
return true; return true;
case "submitVote": case "submitVote":
submitVote(request.type, request.UUID, callback); submitVote(request.type, request.UUID, callback);
//this allows the callback to be called later //this allows the callback to be called later
return true; return true;
case "alertPrevious": case "alertPrevious":
chrome.notifications.create("stillThere" + Math.random(), { chrome.notifications.create("stillThere" + Math.random(), {
type: "basic", type: "basic",
title: "Do you want to submit the sponsor times for video id " + request.previousVideoID + "?", 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).", 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" iconUrl: "./icons/LogoSponsorBlocker256px.png"
}); });
} }
}); });
//add help page on install //add help page on install
chrome.runtime.onInstalled.addListener(function (object) { chrome.runtime.onInstalled.addListener(function (object) {
// TODO (shownInstallPage): remove shownInstallPage logic after sufficient amount of time, // TODO (shownInstallPage): remove shownInstallPage logic after sufficient amount of time,
// so that people have time to upgrade and move to shownInstallPage-free code. // so that people have time to upgrade and move to shownInstallPage-free code.
chrome.storage.sync.get(["userID", "shownInstallPage"], function(result) { chrome.storage.sync.get(["userID", "shownInstallPage"], function(result) {
const userID = result.userID; const userID = result.userID;
// TODO (shownInstallPage): delete row below // TODO (shownInstallPage): delete row below
const shownInstallPage = result.shownInstallPage; const shownInstallPage = result.shownInstallPage;
// If there is no userID, then it is the first install. // If there is no userID, then it is the first install.
if (!userID){ if (!userID){
// Show install page, if there is no user id // Show install page, if there is no user id
// and there is no shownInstallPage. // and there is no shownInstallPage.
// TODO (shownInstallPage): remove this if statement, but leave contents // TODO (shownInstallPage): remove this if statement, but leave contents
if (!shownInstallPage){ if (!shownInstallPage){
//open up the install page //open up the install page
chrome.tabs.create({url: chrome.extension.getURL("/help/"+chrome.i18n.getMessage("helpPage"))}); chrome.tabs.create({url: chrome.extension.getURL("/help/"+chrome.i18n.getMessage("helpPage"))});
} }
// TODO (shownInstallPage): delete if statement and contents // TODO (shownInstallPage): delete if statement and contents
// If shownInstallPage is set, remove it. // If shownInstallPage is set, remove it.
if (!!shownInstallPage){ if (!!shownInstallPage){
chrome.storage.sync.remove("shownInstallPage"); chrome.storage.sync.remove("shownInstallPage");
} }
//generate a userID //generate a userID
const newUserID = generateUUID(); const newUserID = generateUUID();
//save this UUID //save this UUID
chrome.storage.sync.set({ chrome.storage.sync.set({
"userID": newUserID, "userID": newUserID,
//the last video id loaded, to make sure it is a video id change //the last video id loaded, to make sure it is a video id change
"sponsorVideoID": null, "sponsorVideoID": null,
"previousVideoID": null "previousVideoID": null
}); });
} }
}); });
}); });
//gets the sponsor times from memory //gets the sponsor times from memory
function getSponsorTimes(videoID, callback) { function getSponsorTimes(videoID, callback) {
let sponsorTimes = []; let sponsorTimes = [];
let sponsorTimeKey = "sponsorTimes" + videoID; let sponsorTimeKey = "sponsorTimes" + videoID;
chrome.storage.sync.get([sponsorTimeKey], function(result) { chrome.storage.sync.get([sponsorTimeKey], function(result) {
let sponsorTimesStorage = result[sponsorTimeKey]; let sponsorTimesStorage = result[sponsorTimeKey];
if (sponsorTimesStorage != undefined && sponsorTimesStorage.length > 0) { if (sponsorTimesStorage != undefined && sponsorTimesStorage.length > 0) {
sponsorTimes = sponsorTimesStorage; sponsorTimes = sponsorTimesStorage;
} }
callback(sponsorTimes) callback(sponsorTimes)
}); });
} }
function addSponsorTime(time, videoID, callback) { function addSponsorTime(time, videoID, callback) {
getSponsorTimes(videoID, function(sponsorTimes) { getSponsorTimes(videoID, function(sponsorTimes) {
//add to sponsorTimes //add to sponsorTimes
if (sponsorTimes.length > 0 && sponsorTimes[sponsorTimes.length - 1].length < 2) { if (sponsorTimes.length > 0 && sponsorTimes[sponsorTimes.length - 1].length < 2) {
//it is an end time //it is an end time
sponsorTimes[sponsorTimes.length - 1][1] = time; sponsorTimes[sponsorTimes.length - 1][1] = time;
} else { } else {
//it is a start time //it is a start time
let sponsorTimesIndex = sponsorTimes.length; let sponsorTimesIndex = sponsorTimes.length;
sponsorTimes[sponsorTimesIndex] = []; sponsorTimes[sponsorTimesIndex] = [];
sponsorTimes[sponsorTimesIndex][0] = time; sponsorTimes[sponsorTimesIndex][0] = time;
} }
//save this info //save this info
let sponsorTimeKey = "sponsorTimes" + videoID; let sponsorTimeKey = "sponsorTimes" + videoID;
chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes}, callback); chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes}, callback);
}); });
} }
function submitVote(type, UUID, callback) { function submitVote(type, UUID, callback) {
chrome.storage.sync.get(["userID"], function(result) { chrome.storage.sync.get(["userID"], function(result) {
let userID = result.userID; let userID = result.userID;
//publish this vote //publish this vote
sendRequestToServer("GET", "/api/voteOnSponsorTime?UUID=" + UUID + "&userID=" + userID + "&type=" + type, function(xmlhttp, error) { sendRequestToServer("GET", "/api/voteOnSponsorTime?UUID=" + UUID + "&userID=" + userID + "&type=" + type, function(xmlhttp, error) {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
callback({ callback({
successType: 1 successType: 1
}); });
} else if (xmlhttp.readyState == 4 && xmlhttp.status == 405) { } else if (xmlhttp.readyState == 4 && xmlhttp.status == 405) {
//duplicate vote //duplicate vote
callback({ callback({
successType: 0, successType: 0,
statusCode: xmlhttp.status statusCode: xmlhttp.status
}); });
} else if (error) { } else if (error) {
//error while connect //error while connect
callback({ callback({
successType: -1, successType: -1,
statusCode: xmlhttp.status statusCode: xmlhttp.status
}); });
} }
})
}) })
})
} }
function submitTimes(videoID, callback) { function submitTimes(videoID, callback) {
//get the video times from storage //get the video times from storage
let sponsorTimeKey = 'sponsorTimes' + videoID; let sponsorTimeKey = 'sponsorTimes' + videoID;
chrome.storage.sync.get([sponsorTimeKey, "userID"], function(result) { chrome.storage.sync.get([sponsorTimeKey, "userID"], function(result) {
let sponsorTimes = result[sponsorTimeKey]; let sponsorTimes = result[sponsorTimeKey];
let userID = result.userID; let userID = result.userID;
if (sponsorTimes != undefined && sponsorTimes.length > 0) { if (sponsorTimes != undefined && sponsorTimes.length > 0) {
//submit these times //submit these times
for (let i = 0; i < sponsorTimes.length; i++) { for (let i = 0; i < sponsorTimes.length; i++) {
//submit the sponsorTime //submit the sponsorTime
sendRequestToServer("GET", "/api/postVideoSponsorTimes?videoID=" + videoID + "&startTime=" + sponsorTimes[i][0] + "&endTime=" + sponsorTimes[i][1] sendRequestToServer("GET", "/api/postVideoSponsorTimes?videoID=" + videoID + "&startTime=" + sponsorTimes[i][0] + "&endTime=" + sponsorTimes[i][1]
+ "&userID=" + userID, function(xmlhttp, error) { + "&userID=" + userID, function(xmlhttp, error) {
if (xmlhttp.readyState == 4 && !error) { if (xmlhttp.readyState == 4 && !error) {
callback({ callback({
statusCode: xmlhttp.status statusCode: xmlhttp.status
}); });
if (xmlhttp.status == 200) { if (xmlhttp.status == 200) {
//add these to the storage log //add these to the storage log
chrome.storage.sync.get(["sponsorTimesContributed"], function(result) { chrome.storage.sync.get(["sponsorTimesContributed"], function(result) {
let currentContributionAmount = 0; let currentContributionAmount = 0;
if (result.sponsorTimesContributed != undefined) { if (result.sponsorTimesContributed != undefined) {
//current contribution amount is known //current contribution amount is known
currentContributionAmount = result.sponsorTimesContributed; currentContributionAmount = result.sponsorTimesContributed;
} }
//save the amount contributed //save the amount contributed
chrome.storage.sync.set({"sponsorTimesContributed": currentContributionAmount + sponsorTimes.length}); 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) { 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) { if (callback != undefined) {
xmlhttp.onreadystatechange = function () { xmlhttp.onreadystatechange = function () {
callback(xmlhttp, false); callback(xmlhttp, false);
}; };
xmlhttp.onerror = function(ev) { xmlhttp.onerror = function(ev) {
callback(xmlhttp, true); callback(xmlhttp, true);
}; };
} }
//submit this request //submit this request
xmlhttp.send(); xmlhttp.send();
} }
function generateUUID(length = 36) { function generateUUID(length = 36) {
let charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; let charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
let result = ""; let result = "";
let isOpera = Object.prototype.toString.call(window.opera) == '[object Opera]'; let isOpera = Object.prototype.toString.call(window.opera) == '[object Opera]';
if (window.crypto && window.crypto.getRandomValues) { if (window.crypto && window.crypto.getRandomValues) {
values = new Uint32Array(length); values = new Uint32Array(length);
window.crypto.getRandomValues(values); window.crypto.getRandomValues(values);
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
result += charset[values[i] % charset.length]; 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;
} else {
for (let i = 0; i < length; i++) {
result += charset[Math.floor(Math.random() * charset.length)];
}
return result;
}
} }

1482
content.js

File diff suppressed because it is too large Load Diff

View File

@@ -8,24 +8,24 @@ p.popupElement {
h1.popupElement { h1.popupElement {
margin-block-start: 0.67em; margin-block-start: 0.67em;
margin-block-end: 0.67em; margin-block-end: 0.67em;
margin-inline-start: 0px; margin-inline-start: 0px;
margin-inline-end: 0px; margin-inline-end: 0px;
font-weight: bold; font-weight: bold;
} }
h2.popupElement { h2.popupElement {
margin-block-start: 0.83em; margin-block-start: 0.83em;
margin-block-end: 0.83em; margin-block-end: 0.83em;
margin-inline-start: 0px; margin-inline-start: 0px;
margin-inline-end: 0px; margin-inline-end: 0px;
font-weight: bold; font-weight: bold;
} }
h3.popupElement { h3.popupElement {
margin-block-start: 1em; margin-block-start: 1em;
margin-block-end: 1em; margin-block-end: 1em;
margin-inline-start: 0px; margin-inline-start: 0px;
margin-inline-end: 0px; margin-inline-end: 0px;
font-weight: bold; font-weight: bold;
} }
@@ -36,9 +36,9 @@ sub.popupElement {
/* end reset */ /* end reset */
.popupElement { .popupElement {
font-family: 'Source Sans Pro', sans-serif; font-family: 'Source Sans Pro', sans-serif;
color: black; color: black;
} }
h1.popupElement { h1.popupElement {
@@ -109,43 +109,43 @@ h1.popupElement {
padding:8px 37px; padding:8px 37px;
text-decoration:none; text-decoration:none;
text-shadow:0px 0px 0px #27663c; text-shadow:0px 0px 0px #27663c;
} }
.whitelistButton:hover.popupElement { .whitelistButton:hover.popupElement {
background-color:#218b26; background-color:#218b26;
} }
.whitelistButton:focus.popupElement { .whitelistButton:focus.popupElement {
outline: none; outline: none;
background-color:#218b26; background-color:#218b26;
} }
.whitelistButton:active.popupElement { .whitelistButton:active.popupElement {
position:relative; position:relative;
top:1px; top:1px;
} }
.greenButton.popupElement { .greenButton.popupElement {
background-color:#ec1c1c; background-color:#ec1c1c;
-moz-border-radius:28px; -moz-border-radius:28px;
-webkit-border-radius:28px; -webkit-border-radius:28px;
border-radius:28px; border-radius:28px;
border:1px solid #d31919; border:1px solid #d31919;
display:inline-block; display:inline-block;
cursor:pointer; cursor:pointer;
color:#ffffff; color:#ffffff;
font-size:16px; font-size:16px;
padding:8px 37px; padding:8px 37px;
text-decoration:none; text-decoration:none;
text-shadow:0px 0px 0px #662727; text-shadow:0px 0px 0px #662727;
} }
.greenButton:hover.popupElement { .greenButton:hover.popupElement {
background-color:#bf2a2a; background-color:#bf2a2a;
} }
.greenButton:focus.popupElement { .greenButton:focus.popupElement {
outline: none; outline: none;
background-color:#bf2a2a; background-color:#bf2a2a;
} }
.greenButton:active.popupElement { .greenButton:active.popupElement {
position:relative; position:relative;
top:1px; top:1px;
} }
.dangerButton.popupElement { .dangerButton.popupElement {

2406
popup.js

File diff suppressed because it is too large Load Diff