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

Segment locking #830

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions manifest/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"icons/report.png",
"icons/close.png",
"icons/refresh.svg",
"icons/lock.svg",
"icons/beep.ogg",
"icons/PlayerInfoIconSponsorBlocker.svg",
"icons/PlayerDeleteIconSponsorBlocker.svg",
Expand Down
1 change: 1 addition & 0 deletions public/icons/lock.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions public/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
<button class="sbSlimButton" id="refreshSegmentsButton" title="__MSG_refreshSegments__">
<img id="refreshSegments" src="/icons/refresh.svg"/>
</button>
<button class="sbSlimButton hidden" id="lockSegmentsButton">
<img id="LockSegments" src="/icons/lock.svg"/>
</button>
</div>
<div id="issueReporterContainer">
<div id="issueReporterTimeButtons"></div>
Expand Down
2 changes: 2 additions & 0 deletions src/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1412,11 +1412,13 @@ function openInfoMenu() {
const edit = <HTMLImageElement> popup.querySelector("#sbPopupIconEdit");
const check = <HTMLImageElement> popup.querySelector("#sbPopupIconCheck");
const refreshSegments = <HTMLImageElement> popup.querySelector("#refreshSegments");
const lockSegments = <HTMLImageElement> popup.querySelector("#lockSegments");
logo.src = chrome.extension.getURL("icons/IconSponsorBlocker256px.png");
settings.src = chrome.extension.getURL("icons/settings.svg");
edit.src = chrome.extension.getURL("icons/pencil.svg");
check.src = chrome.extension.getURL("icons/check.svg");
refreshSegments.src = chrome.extension.getURL("icons/refresh.svg");
lockSegments.src = chrome.extension.getURL("icons/lock.svg");

parentNode.insertBefore(popup, parentNode.firstChild);

Expand Down
111 changes: 46 additions & 65 deletions src/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
"sponsorMessageTimes",
//"downloadedSponsorMessageTimes",
"refreshSegmentsButton",
"lockSegmentsButton",
"whitelistButton",
"sbDonate"
].forEach(id => PageElements[id] = document.getElementById(id));
Expand Down Expand Up @@ -133,6 +134,7 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
PageElements.optionsButton.addEventListener("click", openOptions);
PageElements.helpButton.addEventListener("click", openHelp);
PageElements.refreshSegmentsButton.addEventListener("click", refreshSegments);
PageElements.lockSegmentsButton.addEventListener("click", lockSegments);

/** If true, the content script is in the process of creating a new segment. */
let creatingSegment = false;
Expand All @@ -144,93 +146,68 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
let currentVideoID = null;

//show proper disable skipping button
const disableSkipping = Config.config.disableSkipping;
if (disableSkipping != undefined && disableSkipping) {
if (Config.config.disableSkipping) {
PageElements.disableSkipping.style.display = "none";
PageElements.enableSkipping.style.display = "unset";
PageElements.toggleSwitch.checked = false;
}

//if the don't show notice again variable is true, an option to
// disable should be available
const dontShowNotice = Config.config.dontShowNotice;
if (dontShowNotice != undefined && dontShowNotice) {
if (Config.config.dontShowNotice) {
PageElements.showNoticeAgain.style.display = "unset";
}

utils.sendRequestToServer("GET", "/api/getUsername?userID=" + Config.config.userID, (res) => {
if (res.status === 200) {
PageElements.usernameValue.innerText = JSON.parse(res.responseText).userName
}
})
const userInfoRes = await utils.asyncRequestToServer("GET", "/api/userInfo?userID=" + Config.config.userID);
if (userInfoRes.ok) {
const userInfo = JSON.parse(userInfoRes.responseText);

//get the amount of times this user has contributed and display it to thank them
if (Config.config.sponsorTimesContributed != undefined) {
PageElements.sponsorTimesContributionsDisplay.innerText = Config.config.sponsorTimesContributed.toLocaleString();
PageElements.sponsorTimesContributionsContainer.classList.remove("hidden");
if (userInfo.vip) PageElements.lockSegmentsButton.classList.remove("hidden");

//get the userID
const userID = Config.config.userID;
if (userID != undefined) {
//there are probably some views on these submissions then
//get the amount of views from the sponsors submitted
utils.sendRequestToServer("GET", "/api/getViewsForUser?userID=" + userID, function(response) {
if (response.status == 200) {
const viewCount = JSON.parse(response.responseText).viewCount;
if (viewCount != 0) {
if (viewCount > 1) {
PageElements.sponsorTimesViewsDisplayEndWord.innerText = chrome.i18n.getMessage("Segments");
} else {
PageElements.sponsorTimesViewsDisplayEndWord.innerText = chrome.i18n.getMessage("Segment");
}
PageElements.usernameValue.innerText = userInfo.userName;

PageElements.sponsorTimesViewsDisplay.innerText = viewCount.toLocaleString();
PageElements.sponsorTimesViewsContainer.style.display = "unset";
}
}
});
PageElements.sponsorTimesContributionsDisplay.innerText = userInfo.segmentCount.toLocaleString();
PageElements.sponsorTimesContributionsContainer.classList.remove("hidden");

//get this time in minutes
utils.sendRequestToServer("GET", "/api/getSavedTimeForUser?userID=" + userID, function(response) {
if (response.status == 200) {
const minutesSaved = JSON.parse(response.responseText).timeSaved;
if (minutesSaved != 0) {
if (minutesSaved != 1) {
PageElements.sponsorTimesOthersTimeSavedEndWord.innerText = chrome.i18n.getMessage("minsLower");
} else {
PageElements.sponsorTimesOthersTimeSavedEndWord.innerText = chrome.i18n.getMessage("minLower");
}
const viewCount = userInfo.viewCount;
if (viewCount != 0) {
if (viewCount > 1) {
PageElements.sponsorTimesViewsDisplayEndWord.innerText = chrome.i18n.getMessage("Segments");
} else {
PageElements.sponsorTimesViewsDisplayEndWord.innerText = chrome.i18n.getMessage("Segment");
}

PageElements.sponsorTimesOthersTimeSavedDisplay.innerText = getFormattedHours(minutesSaved);
}
}
});
PageElements.sponsorTimesViewsDisplay.innerText = viewCount.toLocaleString();
PageElements.sponsorTimesViewsContainer.style.display = "unset";
}
}

//get the amount of times this user has skipped a sponsor
if (Config.config.skipCount != undefined) {
if (Config.config.skipCount != 1) {
PageElements.sponsorTimesSkipsDoneEndWord.innerText = chrome.i18n.getMessage("Segments");
} else {
PageElements.sponsorTimesSkipsDoneEndWord.innerText = chrome.i18n.getMessage("Segment");
const minutesSaved = userInfo.minutesSaved;
if (minutesSaved != 0) {
if (minutesSaved != 1) {
PageElements.sponsorTimesOthersTimeSavedEndWord.innerText = chrome.i18n.getMessage("minsLower");
} else {
PageElements.sponsorTimesOthersTimeSavedEndWord.innerText = chrome.i18n.getMessage("minLower");
}

PageElements.sponsorTimesOthersTimeSavedDisplay.innerText = getFormattedHours(minutesSaved);
}
}

PageElements.sponsorTimesSkipsDoneDisplay.innerText = Config.config.skipCount.toLocaleString();
PageElements.sponsorTimesSkipsDoneContainer.style.display = "unset";
if (Config.config.skipCount != 1) {
PageElements.sponsorTimesSkipsDoneEndWord.innerText = chrome.i18n.getMessage("Segments");
} else {
PageElements.sponsorTimesSkipsDoneEndWord.innerText = chrome.i18n.getMessage("Segment");
}

//get the amount of time this user has saved.
if (Config.config.minutesSaved != undefined) {
if (Config.config.minutesSaved != 1) {
PageElements.sponsorTimeSavedEndWord.innerText = chrome.i18n.getMessage("minsLower");
} else {
PageElements.sponsorTimeSavedEndWord.innerText = chrome.i18n.getMessage("minLower");
}
PageElements.sponsorTimesSkipsDoneDisplay.innerText = Config.config.skipCount.toLocaleString();
PageElements.sponsorTimesSkipsDoneContainer.style.display = "unset";

PageElements.sponsorTimeSavedDisplay.innerText = getFormattedHours(Config.config.minutesSaved);
if (Config.config.minutesSaved != 1) {
PageElements.sponsorTimeSavedEndWord.innerText = chrome.i18n.getMessage("minsLower");
} else {
PageElements.sponsorTimeSavedEndWord.innerText = chrome.i18n.getMessage("minLower");
}

PageElements.sponsorTimeSavedDisplay.innerText = getFormattedHours(Config.config.minutesSaved);

// Must be delayed so it only happens once loaded
setTimeout(() => PageElements.sponsorblockPopup.classList.remove("preload"), 250);

Expand Down Expand Up @@ -690,6 +667,10 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
);
}

function lockSegments() {
alert("lock");
}

/**
* Should skipping be disabled (visuals stay)
*/
Expand Down