Merge pull request #163 from ajayyy/experimental-ajay

Keybind edit, show notice again, ignore rate limits
This commit is contained in:
Ajay Ramachandran 2019-10-30 23:39:18 -04:00 committed by GitHub
commit 44516648a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 159 additions and 51 deletions

View file

@ -166,7 +166,7 @@
"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."
"message": "Hint: Press the semicolon key while focused on a video report the start/end of a sponsor and quote to submit. (This can be changed in the options)"
},
"lastTimes": {
"message": "Latest Sponsor Message Times Chosen"
@ -242,5 +242,25 @@
"sourceCode": {
"message": "Source Code",
"description": "Used on Firefox Store Page"
},
"noticeUpdate": {
"message": "The notice has been upgraded!",
"description": "The first line of the message displayed after the notice was upgraded."
},
"noticeUpdate2": {
"message": "If you still don't like it, hit the never show button.",
"description": "The second line of the message displayed after the notice was upgraded."
},
"setStartSponsorShortcut": {
"message": "Set key for start sponsor keybind"
},
"setSubmitKeybind": {
"message": "Set key for submission keybind"
},
"keybindDescription": {
"message": "Select a key by typing it"
},
"keybindDescriptionComplete": {
"message": "The keybind has been set to: "
}
}

View file

@ -42,28 +42,13 @@ chrome.runtime.onMessage.addListener(function (request, sender, callback) {
//add help page on install
chrome.runtime.onInstalled.addListener(function (object) {
// TODO (shownInstallPage): remove shownInstallPage logic after sufficient amount of time,
// so that people have time to upgrade and move to shownInstallPage-free code.
chrome.storage.sync.get(["userID", "shownInstallPage"], function(result) {
const userID = result.userID;
// TODO (shownInstallPage): delete row below
const shownInstallPage = result.shownInstallPage;
// If there is no userID, then it is the first install.
if (!userID){
// Show install page, if there is no user id
// and there is no shownInstallPage.
// TODO (shownInstallPage): remove this if statement, but leave contents
if (!shownInstallPage){
//open up the install page
chrome.tabs.create({url: chrome.extension.getURL("/help/"+chrome.i18n.getMessage("helpPage"))});
}
// TODO (shownInstallPage): delete if statement and contents
// If shownInstallPage is set, remove it.
if (!!shownInstallPage){
chrome.storage.sync.remove("shownInstallPage");
}
//open up the install page
chrome.tabs.create({url: chrome.extension.getURL("/help/"+chrome.i18n.getMessage("helpPage"))});
//generate a userID
const newUserID = generateUserID();

View file

@ -80,13 +80,22 @@ chrome.storage.sync.get(["trackViewCount"], function(result) {
//if the notice should not be shown
//happens when the user click's the "Don't show notice again" button
//option renamed when new notice was made
var dontShowNotice = false;
chrome.storage.sync.get(["dontShowNoticeAgain"], function(result) {
chrome.storage.sync.get(["dontShowNotice"], function(result) {
let dontShowNoticeAgain = result.dontShowNoticeAgain;
if (dontShowNoticeAgain != undefined) {
dontShowNotice = dontShowNoticeAgain;
}
});
//load the legacy option to hide the notice
var dontShowNoticeOld = false;
chrome.storage.sync.get(["dontShowNoticeAgain"], function(result) {
let dontShowNoticeAgain = result.dontShowNoticeAgain;
if (dontShowNoticeAgain != undefined) {
dontShowNoticeOld = dontShowNoticeAgain;
}
});
//get messages from the background script and the popup
chrome.runtime.onMessage.addListener(messageListener);
@ -195,18 +204,32 @@ function messageListener(request, sender, sendResponse) {
}
//check for hotkey pressed
document.onkeydown = function(e){
document.onkeydown = async function(e){
e = e || window.event;
var key = e.key;
let video = document.getElementById("movie_player");
let startSponsorKey = await new Promise((resolve, reject) => {
chrome.storage.sync.get(["startSponsorKeybind"], (result) => resolve(result));
});
let submitKey = await new Promise((resolve, reject) => {
chrome.storage.sync.get(["submitKeybind"], (result) => resolve(result));
});
if (startSponsorKey.startSponsorKeybind === undefined) {
startSponsorKey.startSponsorKeybind = ";"
}
if (submitKey.submitKeybind === undefined) {
submitKey.submitKeybind = "'"
}
//is the video in focus, otherwise they could be typing a comment
if (document.activeElement === video) {
if(key == ';'){
if(key == startSponsorKey.startSponsorKeybind){
//semicolon
startSponsorClicked();
} else if (key == "'") {
} else if (key == submitKey.submitKeybind) {
//single quote
submitSponsorTimes();
}
@ -591,7 +614,16 @@ function skipToTime(v, index, sponsorTimes, openNotice) {
if (openNotice) {
//send out the message saying that a sponsor message was skipped
if (!dontShowNotice) {
new SkipNotice(this, currentUUID);
let skipNotice = new SkipNotice(this, currentUUID);
if (dontShowNoticeOld) {
//show why this notice is showing
skipNotice.addNoticeInfoMessage(chrome.i18n.getMessage("noticeUpdate"), chrome.i18n.getMessage("noticeUpdate2"));
//remove this setting
chrome.storage.sync.remove(["dontShowNoticeAgain"]);
dontShowNoticeOld = false;
}
//auto-upvote this sponsor
if (trackViewCount) {
@ -879,8 +911,8 @@ function vote(type, UUID, skipNotice) {
if (response != undefined) {
//see if it was a success or failure
if (skipNotice != null) {
if (response.successType == 1) {
//success
if (response.successType == 1 || (response.successType == -1 && response.statusCode == 429)) {
//success (treat rate limits as a success)
if (type == 0) {
skipNotice.afterDownvote.bind(skipNotice)();
}
@ -912,7 +944,7 @@ function closeAllSkipNotices(){
}
function dontShowNoticeAgain() {
chrome.storage.sync.set({"dontShowNoticeAgain": true});
chrome.storage.sync.set({"dontShowNotice": true});
dontShowNotice = true;
@ -920,15 +952,15 @@ function dontShowNoticeAgain() {
}
function sponsorMessageStarted(callback) {
v = document.querySelector('video');
v = document.querySelector('video');
//send back current time
callback({
time: v.currentTime
})
//send back current time
callback({
time: v.currentTime
})
//update button
toggleStartSponsorButton();
//update button
toggleStartSponsorButton();
}
function submitSponsorTimes() {

View file

@ -0,0 +1,8 @@
{
"browser_specific_settings": {
"gecko": {
"id": "sponsorBlocker@ajay.app",
"strict_min_version": "57.0"
}
}
}

View file

@ -1,7 +1,7 @@
{
"name": "__MSG_fullName__",
"short_name": "__MSG_Name__",
"version": "1.1.9",
"version": "1.1.9.1",
"default_locale": "en",
"description": "__MSG_Description__",
"content_scripts": [
@ -65,11 +65,5 @@
"128": "icons/LogoSponsorBlocker128px.png",
"256": "icons/LogoSponsorBlocker256px.png"
},
"browser_specific_settings": {
"gecko": {
"id": "sponsorBlocker@ajay.app",
"strict_min_version": "57.0"
}
},
"manifest_version": 2
}

View file

@ -172,6 +172,19 @@
<br/>
<h3>__MSG_Options__</h3>
<span id="keybindButtons">
<button id="setStartSponsorKeybind" class="warningButton popupElement">__MSG_setStartSponsorShortcut__</button>
<br/>
<br/>
<button id="setSubmitKeybind" class="warningButton popupElement">__MSG_setSubmitKeybind__</button>
<br/>
</span>
<h2 id="keybindDescription" style="display: none" class="popupElement">__MSG_keybindDescription__</h2>
<br/>
<br/>
<button id="hideVideoPlayerControls" class="warningButton popupElement">__MSG_hideButtons__</button>
<button id="showVideoPlayerControls" style="display: none" class="warningButton popupElement">__MSG_showButtons__</button>

View file

@ -70,6 +70,10 @@ function runThePopup() {
"videoFound",
"sponsorMessageTimes",
"downloadedSponsorMessageTimes",
// Keybinds
"setStartSponsorKeybind",
"setSubmitKeybind",
"keybindDescription"
].forEach(id => SB[id] = document.getElementById(id));
//setup click listeners
@ -79,6 +83,8 @@ function runThePopup() {
SB.clearTimes.addEventListener("click", clearTimes);
SB.submitTimes.addEventListener("click", submitTimes);
SB.showNoticeAgain.addEventListener("click", showNoticeAgain);
SB.setStartSponsorKeybind.addEventListener("click", () => setKeybind(true));
SB.setSubmitKeybind.addEventListener("click", () => setKeybind(false));
SB.hideVideoPlayerControls.addEventListener("click", hideVideoPlayerControls);
SB.showVideoPlayerControls.addEventListener("click", showVideoPlayerControls);
SB.hideInfoButtonPlayerControls.addEventListener("click", hideInfoButtonPlayerControls);
@ -104,6 +110,9 @@ function runThePopup() {
//is this a YouTube tab?
let isYouTubeTab = false;
// Is the start sponsor keybind currently being set
let setStartSponsorKeybind = false;
//see if discord link can be shown
chrome.storage.sync.get(["hideDiscordLink"], function(result) {
@ -127,9 +136,9 @@ function runThePopup() {
//if the don't show notice again letiable is true, an option to
// disable should be available
chrome.storage.sync.get(["dontShowNoticeAgain"], function(result) {
let dontShowNoticeAgain = result.dontShowNoticeAgain;
if (dontShowNoticeAgain != undefined && dontShowNoticeAgain) {
chrome.storage.sync.get(["dontShowNotice"], function(result) {
let dontShowNotice = result.dontShowNotice;
if (dontShowNotice != undefined && dontShowNotice) {
SB.showNoticeAgain.style.display = "unset";
}
});
@ -819,7 +828,7 @@ function runThePopup() {
}
function showNoticeAgain() {
chrome.storage.sync.set({"dontShowNoticeAgain": false});
chrome.storage.sync.set({"dontShowNotice": false});
chrome.tabs.query({
active: true,
@ -1102,8 +1111,8 @@ function runThePopup() {
}, function(response) {
if (response != undefined) {
//see if it was a success or failure
if (response.successType == 1) {
//success
if (response.successType == 1 || (response.successType == -1 && response.statusCode == 429)) {
//success (treat rate limits as a success)
addVoteMessage(chrome.i18n.getMessage("voted"), UUID)
} else if (response.successType == 0) {
//failure: duplicate vote
@ -1236,7 +1245,35 @@ function runThePopup() {
);
});
}
function setKeybind(startSponsorKeybind) {
document.getElementById("keybindButtons").style.display = "none";
document.getElementById("keybindDescription").style.display = "initial";
document.getElementById("keybindDescription").innerText = chrome.i18n.getMessage("keybindDescription");
setStartSponsorKeybind = startSponsorKeybind;
document.addEventListener("keydown", onKeybindSet)
}
function onKeybindSet(e) {
e = e || window.event;
var key = e.key;
if (setStartSponsorKeybind) {
chrome.storage.sync.set({"startSponsorKeybind": key});
} else {
chrome.storage.sync.set({"submitKeybind": key});
}
document.removeEventListener("keydown", onKeybindSet);
document.getElementById("keybindDescription").innerText = chrome.i18n.getMessage("keybindDescriptionComplete") + " " + key;
document.getElementById("keybindButtons").style.display = "unset";
}
//converts time in seconds to minutes
function getTimeInMinutes(seconds) {
let minutes = Math.floor(seconds / 60);

View file

@ -294,21 +294,37 @@ class SkipNotice {
}
}
addNoticeInfoMessage(message) {
addNoticeInfoMessage(message, message2) {
let previousInfoMessage = document.getElementById("sponsorTimesInfoMessage" + this.idSuffix);
if (previousInfoMessage != null) {
//remove it
document.getElementById("sponsorSkipNotice" + this.idSuffix).removeChild(previousInfoMessage);
}
let previousInfoMessage2 = document.getElementById("sponsorTimesInfoMessage" + this.idSuffix + "2");
if (previousInfoMessage2 != null) {
//remove it
document.getElementById("sponsorSkipNotice" + this.idSuffix).removeChild(previousInfoMessage2);
}
//add info
let thanksForVotingText = document.createElement("p");
thanksForVotingText.id = "sponsorTimesInfoMessage" + this.idSuffix;
thanksForVotingText.className = "sponsorTimesInfoMessage";
thanksForVotingText.innerText = message;
//add element to div
document.getElementById("sponsorSkipNotice" + this.idSuffix).insertBefore(thanksForVotingText, document.getElementById("sponsorSkipNoticeSpacer" + this.idSuffix));
if (message2 !== undefined) {
let thanksForVotingText2 = document.createElement("p");
thanksForVotingText2.id = "sponsorTimesInfoMessage" + this.idSuffix + "2";
thanksForVotingText2.className = "sponsorTimesInfoMessage";
thanksForVotingText2.innerText = message2;
//add element to div
document.getElementById("sponsorSkipNotice" + this.idSuffix).insertBefore(thanksForVotingText2, document.getElementById("sponsorSkipNoticeSpacer" + this.idSuffix));
}
}
resetNoticeInfoMessage() {
@ -337,7 +353,7 @@ class SkipNotice {
thanksForVotingText.id = "sponsorTimesVoteButtonInfoMessage" + this.idSuffix;
thanksForVotingText.className = "sponsorTimesInfoMessage sponsorTimesVoteButtonMessage";
thanksForVotingText.innerText = message;
//add element to div
document.getElementById("sponsorSkipNoticeSecondRow" + this.idSuffix).prepend(thanksForVotingText);
}
@ -348,13 +364,16 @@ class SkipNotice {
//remove it
document.getElementById("sponsorSkipNoticeSecondRow" + this.idSuffix).removeChild(previousInfoMessage);
}
//show button again
document.getElementById("sponsorTimesDownvoteButtonsContainer" + this.idSuffix).style.removeProperty("display");
}
//close this notice
close() {
//reset message
this.resetNoticeInfoMessage();
let notice = document.getElementById("sponsorSkipNotice" + this.idSuffix);
if (notice != null) {
notice.remove();