Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keybind edit, show notice again, ignore rate limits #163

Merged
merged 12 commits into from
Oct 31, 2019
Merged
22 changes: 21 additions & 1 deletion _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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: "
}
}
19 changes: 2 additions & 17 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
62 changes: 47 additions & 15 deletions content.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong. Storage returns {dontShowNotice: true} so result.dontShowNoticeAgain is undefined and it shows the notice every time.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I fixed this in popup.js but forgot here.

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);
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)();
}
Expand Down Expand Up @@ -912,23 +944,23 @@ function closeAllSkipNotices(){
}

function dontShowNoticeAgain() {
chrome.storage.sync.set({"dontShowNoticeAgain": true});
chrome.storage.sync.set({"dontShowNotice": true});

dontShowNotice = true;

closeAllSkipNotices();
}

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() {
Expand Down
8 changes: 8 additions & 0 deletions firefox_manifest-extra.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"browser_specific_settings": {
"gecko": {
"id": "sponsorBlocker@ajay.app",
"strict_min_version": "57.0"
}
}
}
8 changes: 1 addition & 7 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down Expand Up @@ -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
}
13 changes: 13 additions & 0 deletions popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,19 @@ <h2 id="setUsernameStatus"></h2>
<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>
Expand Down
51 changes: 44 additions & 7 deletions popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ function runThePopup() {
"videoFound",
"sponsorMessageTimes",
"downloadedSponsorMessageTimes",
// Keybinds
"setStartSponsorKeybind",
"setSubmitKeybind",
"keybindDescription"
].forEach(id => SB[id] = document.getElementById(id));

//setup click listeners
Expand All @@ -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);
Expand All @@ -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) {
Expand All @@ -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";
}
});
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
Loading