aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAjay Ramachandran <[email protected]>2019-07-09 21:44:41 -0400
committerAjay Ramachandran <[email protected]>2019-07-09 21:44:41 -0400
commit4edab5f9a96232a44f998d6e534eee5bbf5218fc (patch)
treec7249255c04ae16229d42aa8bebed869fca426dc
parent4d4103f053092c2b020333a8df7d1fda0f518270 (diff)
downloadSponsorBlock-4edab5f9a96232a44f998d6e534eee5bbf5218fc.tar.gz
SponsorBlock-4edab5f9a96232a44f998d6e534eee5bbf5218fc.zip
Added go back button
-rw-r--r--content.js37
1 files changed, 34 insertions, 3 deletions
diff --git a/content.js b/content.js
index 09d1d978..0e56c264 100644
--- a/content.js
+++ b/content.js
@@ -22,6 +22,10 @@ var v;
//the last time looked at (used to see if this time is in the interval)
var lastTime;
+//the last time in the video a sponsor was skipped
+//used for the go back button
+var lastSponsorTimeSkipped = null;
+
chrome.runtime.onMessage.addListener( // Detect URL Changes
function(request, sender, sendResponse) {
//message from background script
@@ -85,6 +89,8 @@ function sponsorCheck(sponsorTimes) { // Video skipping
//skip it
v.currentTime = sponsorTime[1];
+ lastSponsorTimeSkipped = sponsorTime[0];
+
//send out the message saying that a sponsor message was skipped
openSkipNotice();
@@ -95,6 +101,15 @@ function sponsorCheck(sponsorTimes) { // Video skipping
});
}
+function goBackToPreviousTime() {
+ if (lastSponsorTimeSkipped != null) {
+ //add a tiny bit of time to make sure it is not skipped again
+ v.currentTime = lastSponsorTimeSkipped + 0.001;
+
+ closeSkipNotice();
+ }
+}
+
//Opens the notice that tells the user that a sponsor was just skipped
function openSkipNotice(){
var noticeElement = document.createElement("div");
@@ -109,13 +124,26 @@ function openSkipNotice(){
var noticeMessage = document.createElement("p");
noticeMessage.innerText = "Hey, you just skipped a sponsor!";
- noticeMessage.style.marginLeft = "10px";
noticeMessage.style.fontSize = "18px";
noticeMessage.style.color = "#000000";
noticeMessage.style.textAlign = "center";
noticeMessage.style.marginTop = "10px";
- noticeElement.appendChild(noticeMessage);
+ var buttonContainer = document.createElement("div");
+ buttonContainer.setAttribute("align", "center");
+
+ var goBackButton = document.createElement("button");
+ goBackButton.innerText = "Go back";
+ goBackButton.style.fontSize = "13px";
+ goBackButton.style.color = "#000000";
+ goBackButton.setAttribute("align", "center");
+ goBackButton.style.marginTop = "5px";
+ goBackButton.addEventListener("click", goBackToPreviousTime);
+
+ buttonContainer.appendChild(goBackButton);
+
+ noticeElement.appendChild(noticeMessage);
+ noticeElement.appendChild(buttonContainer);
var referenceNode = document.getElementById("info");
if (referenceNode == null) {
@@ -127,7 +155,10 @@ function openSkipNotice(){
//Closes the notice that tells the user that a sponsor was just skipped
function closeSkipNotice(){
- document.getElementById("sponsorSkipNotice").remove();
+ let notice = document.getElementById("sponsorSkipNotice");
+ if (notice != null) {
+ notice.remove();
+ }
}
function sponsorMessageStarted() {