Merge pull request #195 from ajayyy/experimental-ajay

Small Fixes
This commit is contained in:
Ajay Ramachandran
2019-12-13 23:37:11 -05:00
committed by GitHub
10 changed files with 97 additions and 104 deletions

View File

@@ -76,7 +76,7 @@
"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": "To 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"
@@ -314,5 +314,11 @@
}, },
"youHaveSavedTimeEnd": { "youHaveSavedTimeEnd": {
"message": " of their lives." "message": " of their lives."
},
"guildlinesSummary": {
"message": "- Make sure your segment only contains paid promotion segment, nothing else.\n- Make sure skipping this segment will not skip valuable content\n- If the whole video is a sponsor, please do not report it. A full video reporting system will come out soon.\n- Please do not report disclaimers that could show bias (if a review video is sponsored, don't skip when they mention that)."
},
"statusReminder": {
"message": "Check status.sponsor.ajay.app for server status."
} }
} }

View File

@@ -33,7 +33,7 @@ chrome.runtime.onMessage.addListener(function (request, sender, callback) {
case "alertPrevious": case "alertPrevious":
chrome.notifications.create("stillThere" + Math.random(), { chrome.notifications.create("stillThere" + Math.random(), {
type: "basic", type: "basic",
title: chrome.i18n.getMessage("wantToSubmit") + request.previousVideoID + "?", title: chrome.i18n.getMessage("wantToSubmit") + " " + request.previousVideoID + "?",
message: chrome.i18n.getMessage("leftTimes"), message: chrome.i18n.getMessage("leftTimes"),
iconUrl: "./icons/LogoSponsorBlocker256px.png" iconUrl: "./icons/LogoSponsorBlocker256px.png"
}); });
@@ -215,22 +215,4 @@ function sendRequestToServer(type, address, callback) {
//submit this request //submit this request
xmlhttp.send(); xmlhttp.send();
} }
function generateUserID(length = 36) {
let charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
let result = "";
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;
}
}

View File

@@ -479,7 +479,12 @@ function updatePreviewBar() {
//create an array of the sponsor types //create an array of the sponsor types
let types = []; let types = [];
for (let i = 0; i < localSponsorTimes.length; i++) { for (let i = 0; i < localSponsorTimes.length; i++) {
types.push("sponsor"); if (!hiddenSponsorTimes.includes(i)) {
types.push("sponsor");
} else {
// Don't show this sponsor
types.push(null);
}
} }
for (let i = 0; i < sponsorTimesSubmitting.length; i++) { for (let i = 0; i < sponsorTimesSubmitting.length; i++) {
types.push("previewSponsor"); types.push("previewSponsor");
@@ -493,25 +498,20 @@ function updatePreviewBar() {
function getChannelID() { function getChannelID() {
//get channel id //get channel id
let channelContainers = document.querySelectorAll(".ytd-channel-name#text"); let channelNameContainer = document.getElementById("channel-name");
let channelURLContainer = null; let channelURLContainer = channelNameContainer.querySelector("#container").querySelector("#text-container").querySelector("#text").firstElementChild;
for (let i = 0; i < channelContainers.length; i++) {
let child = channelContainers[i].firstElementChild;
if (child != null && child.getAttribute("href") != "") {
channelURLContainer = child;
}
}
if (channelContainers.length == 0) {
if (channelURLContainer === null) {
//old YouTube theme //old YouTube theme
channelContainers = document.getElementsByClassName("yt-user-info"); let channelContainers = document.getElementsByClassName("yt-user-info");
if (channelContainers.length != 0) { if (channelContainers.length != 0) {
channelURLContainer = channelContainers[0].firstElementChild; channelURLContainer = channelContainers[0].firstElementChild;
} }
} }
if (channelURLContainer == null) { if (channelURLContainer === null) {
//try later //try later
return false; return false;
} }
@@ -545,11 +545,9 @@ function whitelistCheck() {
chrome.storage.sync.get(["whitelistedChannels"], function(result) { chrome.storage.sync.get(["whitelistedChannels"], function(result) {
let whitelistedChannels = result.whitelistedChannels; let whitelistedChannels = result.whitelistedChannels;
if (whitelistedChannels != undefined && whitelistedChannels.includes(channelURL)) { console.log(channelURL)
//reset sponsor times to nothing
sponsorTimes = [];
UUIDs = [];
if (whitelistedChannels != undefined && whitelistedChannels.includes(channelURL)) {
channelWhitelisted = true; channelWhitelisted = true;
} }
}); });
@@ -561,6 +559,8 @@ function sponsorCheck() {
// Make sure this isn't called again // Make sure this isn't called again
v.ontimeupdate = null; v.ontimeupdate = null;
return; return;
} else if (channelWhitelisted) {
return;
} }
let skipHappened = false; let skipHappened = false;
@@ -980,14 +980,8 @@ function vote(type, UUID, skipNotice) {
skipNotice.addNoticeInfoMessage.bind(skipNotice)(chrome.i18n.getMessage("voteFail")) skipNotice.addNoticeInfoMessage.bind(skipNotice)(chrome.i18n.getMessage("voteFail"))
skipNotice.resetVoteButtonInfo.bind(skipNotice)(); skipNotice.resetVoteButtonInfo.bind(skipNotice)();
} else if (response.successType == -1) { } else if (response.successType == -1) {
if (response.statusCode == 502) { skipNotice.addNoticeInfoMessage.bind(skipNotice)(getErrorMessage(response.statusCode))
skipNotice.addNoticeInfoMessage.bind(skipNotice)(chrome.i18n.getMessage("serverDown")) skipNotice.resetVoteButtonInfo.bind(skipNotice)();
skipNotice.resetVoteButtonInfo.bind(skipNotice)();
} else {
//failure: unknown error
skipNotice.addNoticeInfoMessage.bind(skipNotice)(chrome.i18n.getMessage("connectionError") + response.statusCode);
skipNotice.resetVoteButtonInfo.bind(skipNotice)();
}
} }
} }
} }
@@ -1047,8 +1041,11 @@ function submitSponsorTimes() {
//update sponsorTimes //update sponsorTimes
chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes}); chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes});
let confirmMessage = chrome.i18n.getMessage("submitCheck") + "\n\n" + getSponsorTimesMessage(sponsorTimes); //update sponsorTimesSubmitting
confirmMessage += "\n\n" + chrome.i18n.getMessage("confirmMSG"); sponsorTimesSubmitting = sponsorTimes;
let confirmMessage = chrome.i18n.getMessage("submitCheck") + "\n\n" + getSponsorTimesMessage(sponsorTimes)
+ "\n\n" + chrome.i18n.getMessage("confirmMSG") + "\n\n" + chrome.i18n.getMessage("guildlinesSummary");
if(!confirm(confirmMessage)) return; if(!confirm(confirmMessage)) return;
sendSubmitMessage(); sendSubmitMessage();
@@ -1066,8 +1063,6 @@ function sendSubmitMessage(){
let currentVideoID = sponsorVideoID; let currentVideoID = sponsorVideoID;
let currentSponsorTimes = submitSponsorTimes;
chrome.runtime.sendMessage({ chrome.runtime.sendMessage({
message: "submitTimes", message: "submitTimes",
videoID: currentVideoID videoID: currentVideoID
@@ -1091,24 +1086,25 @@ function sendSubmitMessage(){
//clear the sponsor times //clear the sponsor times
let sponsorTimeKey = "sponsorTimes" + currentVideoID; let sponsorTimeKey = "sponsorTimes" + currentVideoID;
chrome.storage.sync.set({[sponsorTimeKey]: []}, () => void updatePreviewBar()); chrome.storage.sync.set({[sponsorTimeKey]: []});
//add submissions to current sponsors list //add submissions to current sponsors list
sponsorTimes = sponsorTimes.concat(sponsorTimesSubmitting); sponsorTimes = sponsorTimes.concat(sponsorTimesSubmitting);
for (let i = 0; i < sponsorTimesSubmitting.length; i++) {
// Add some random IDs
UUIDs.push(generateUserID());
}
// Empty the submitting times
sponsorTimesSubmitting = []; sponsorTimesSubmitting = [];
updatePreviewBar();
} else { } else {
//show that the upload failed //show that the upload failed
document.getElementById("submitButton").style.animation = "unset"; document.getElementById("submitButton").style.animation = "unset";
document.getElementById("submitImage").src = chrome.extension.getURL("icons/PlayerUploadFailedIconSponsorBlocker256px.png"); document.getElementById("submitImage").src = chrome.extension.getURL("icons/PlayerUploadFailedIconSponsorBlocker256px.png");
if([400, 429, 409, 502, 0].includes(response.statusCode)) { alert(getErrorMessage(response.statusCode));
//treat them the same
if (response.statusCode == 503) response.statusCode = 502;
alert(chrome.i18n.getMessage(response.statusCode + "") + " " + chrome.i18n.getMessage("errorCode") + response.statusCode);
} else {
alert(chrome.i18n.getMessage("connectionError") + response.statusCode);
}
} }
} }
}); });

View File

@@ -39,7 +39,7 @@
<br/> <br/>
<br/> <br/>
Whenever you skip a video, you will get a notice report that submission. If the timing seems wrong, report it! You can also vote in the popup. The extension auto upvotes it if you don't report it, so make sure to report when necessary. Whenever you skip a video, you will get a notice report that submission. If the timing seems wrong, report it! You can also vote in the popup. The extension auto upvotes it if you don't report it, so make sure to report when necessary (this can be disabled in the options).
</p> </p>
<center><img height="120px" src="https://user-images.githubusercontent.com/12688112/63067735-5a638700-bede-11e9-8147-f321b57527ec.gif"></center> <center><img height="120px" src="https://user-images.githubusercontent.com/12688112/63067735-5a638700-bede-11e9-8147-f321b57527ec.gif"></center>

View File

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

View File

@@ -140,24 +140,24 @@
<span class="popupElement">__MSG_youHaveSavedTimeEnd__</span> <span class="popupElement">__MSG_youHaveSavedTimeEnd__</span>
</span> </span>
<br/> <div id="sponsorTimesSkipsDoneContainer" class="popupElement" style="display: none">
<br/>
<span id="sponsorTimesSkipsDoneContainer" class="popupElement" style="display: none">
__MSG_youHaveSkipped__ __MSG_youHaveSkipped__
<span id="sponsorTimesSkipsDoneDisplay" class="popupElement"> <span id="sponsorTimesSkipsDoneDisplay" class="popupElement">
0 0
</span> </span>
<span id="sponsorTimesSkipsDoneEndWord" class="popupElement">__MSG_Segments__</span> since December 5th. <span id="sponsorTimesSkipsDoneEndWord" class="popupElement">__MSG_Segments__</span> since December 5th.
</span> </div>
<span id="sponsorTimeSavedContainer" class="popupElement" style="display: none"> <div id="sponsorTimeSavedContainer" class="popupElement" style="display: none">
__MSG_youHaveSaved__ __MSG_youHaveSaved__
<span id="sponsorTimeSavedDisplay" class="popupElement"> <span id="sponsorTimeSavedDisplay" class="popupElement">
0 0
</span> </span>
<span id="sponsorTimeSavedEndWord" class="popupElement">__MSG_minsLower__</span> since December 5th. <span id="sponsorTimeSavedEndWord" class="popupElement">__MSG_minsLower__</span> since December 5th.
</span>
</br/>
</br/>
</div>
<div class="popupElement"> <div class="popupElement">
__MSG_viewLeaderboard__ <a class="popupElement discreteLink" href="https://sponsor.ajay.app/stats" target="_blank">__MSG_here__</a>. __MSG_viewLeaderboard__ <a class="popupElement discreteLink" href="https://sponsor.ajay.app/stats" target="_blank">__MSG_here__</a>.

View File

@@ -895,18 +895,7 @@ function runThePopup() {
clearTimes(); clearTimes();
} else { } else {
let errorMessage = ""; document.getElementById("submitTimesInfoMessage").innerText = getErrorMessage(response.statusCode);
if([400, 429, 409, 502, 0].includes(response.statusCode)) {
//treat them the same
if (response.statusCode == 503) response.statusCode = 502;
errorMessage = chrome.i18n.getMessage(response.statusCode + "") + " " + chrome.i18n.getMessage("errorCode") + response.statusCode;
} else {
errorMessage = chrome.i18n.getMessage("connectionError") + response.statusCode;
}
document.getElementById("submitTimesInfoMessage").innerText = errorMessage;
document.getElementById("submitTimesInfoMessageContainer").style.display = "unset"; document.getElementById("submitTimesInfoMessageContainer").style.display = "unset";
SB.submitTimesInfoMessageContainer.style.display = "unset"; SB.submitTimesInfoMessageContainer.style.display = "unset";
@@ -1138,7 +1127,7 @@ function runThePopup() {
SB.usernameInput.style.display = "none"; SB.usernameInput.style.display = "none";
SB.setUsernameStatusContainer.style.display = "unset"; SB.setUsernameStatusContainer.style.display = "unset";
SB.setUsernameStatus.innerText = "Couldn't connect to server. Error code: " + xmlhttp.status; SB.setUsernameStatus.innerText = getErrorMessage(xmlhttp.status);
} }
}); });
}); });
@@ -1160,15 +1149,7 @@ function runThePopup() {
SB.setUsernameStatus.innerText = chrome.i18n.getMessage("success"); SB.setUsernameStatus.innerText = chrome.i18n.getMessage("success");
} else if (xmlhttp.readyState == 4) { } else if (xmlhttp.readyState == 4) {
let errorMessage = ""; SB.setUsernameStatus.innerText = getErrorMessageI(xmlhttp.status);
if([400, 429, 409, 502].includes(xmlhttp.status)) {
errorMessage = chrome.i18n.getMessage(xmlhttp.status);
} else {
errorMessage = chrome.i18n.getMessage("connectionError") + xmlhttp.status;
}
SB.setUsernameStatus.innerText = errorMessage;
} }
}); });
}); });
@@ -1224,12 +1205,7 @@ function runThePopup() {
//failure: duplicate vote //failure: duplicate vote
addVoteMessage(chrome.i18n.getMessage("voteFail"), UUID) addVoteMessage(chrome.i18n.getMessage("voteFail"), UUID)
} else if (response.successType == -1) { } else if (response.successType == -1) {
if (response.statusCode == 502) { addVoteMessage(getErrorMessage(response.statusCode), UUID)
addVoteMessage(chrome.i18n.getMessage("serverDown"), UUID)
} else {
//failure: unknown error
addVoteMessage(chrome.i18n.getMessage("connectionError") + response.statusCode, UUID)
}
} }
} }
}); });

View File

@@ -66,3 +66,42 @@ function localizeHtmlPage() {
} }
} }
function generateUserID(length = 36) {
let charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
let result = "";
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;
}
}
/**
* Gets the error message in a nice string
*
* @param {int} statusCode
* @returns {string} errorMessage
*/
function getErrorMessage(statusCode) {
let errorMessage = "";
if([400, 429, 409, 502, 0].includes(statusCode)) {
//treat them the same
if (statusCode == 503) statusCode = 502;
errorMessage = chrome.i18n.getMessage(statusCode + "") + " " + chrome.i18n.getMessage("errorCode") + statusCode
+ "\n\n" + chrome.i18n.getMessage("statusReminder");
} else {
errorMessage = chrome.i18n.getMessage("connectionError") + statusCode;
}
return errorMessage;
}

View File

@@ -59,6 +59,8 @@ class PreviewBar {
duration = Math.floor(duration * 100) / 100; duration = Math.floor(duration * 100) / 100;
let width; let width;
for (let i = 0; i < timestamps.length; i++) { for (let i = 0; i < timestamps.length; i++) {
if (types[i] == null) continue;
width = (timestamps[i][1] - timestamps[i][0]) / duration * 100; width = (timestamps[i][1] - timestamps[i][0]) / duration * 100;
width = Math.floor(width * 100) / 100; width = Math.floor(width * 100) / 100;

View File

@@ -324,15 +324,7 @@ class SkipNotice {
//add this as a hidden sponsorTime //add this as a hidden sponsorTime
hiddenSponsorTimes.push(i); hiddenSponsorTimes.push(i);
let sponsorTimesLeft = sponsorTimes.slice(); updatePreviewBar();
for (let j = 0; j < hiddenSponsorTimes.length; j++) {
//remove this sponsor time
sponsorTimesLeft.splice(hiddenSponsorTimes[j], 1);
}
//update the preview
previewBar.set(sponsorTimesLeft, [], v.duration);
break; break;
} }
} }