mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-07 03:57:09 +03:00
Added submit button on the video player.
This commit is contained in:
44
content.css
44
content.css
@@ -1,3 +1,11 @@
|
|||||||
|
.playerButton {
|
||||||
|
height: 60%;
|
||||||
|
top: 0;
|
||||||
|
bottom: 0;
|
||||||
|
display: block;
|
||||||
|
margin: auto;
|
||||||
|
}
|
||||||
|
|
||||||
.sponsorSkipObject {
|
.sponsorSkipObject {
|
||||||
font-family: 'Source Sans Pro', sans-serif;
|
font-family: 'Source Sans Pro', sans-serif;
|
||||||
}
|
}
|
||||||
@@ -84,6 +92,42 @@
|
|||||||
filter: brightness(80%);
|
filter: brightness(80%);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.submitButton {
|
||||||
|
background-color:#ec1c1c;
|
||||||
|
-moz-border-radius:28px;
|
||||||
|
-webkit-border-radius:28px;
|
||||||
|
border-radius:28px;
|
||||||
|
border:1px solid #d31919;
|
||||||
|
display:inline-block;
|
||||||
|
cursor:pointer;
|
||||||
|
color:#ffffff;
|
||||||
|
font-size:14px;
|
||||||
|
padding:4px 15px;
|
||||||
|
text-decoration:none;
|
||||||
|
text-shadow:0px 0px 0px #662727;
|
||||||
|
|
||||||
|
margin-top: 5px;
|
||||||
|
margin-right: 15px;
|
||||||
|
}
|
||||||
|
.submitButton:hover {
|
||||||
|
background-color:#bf2a2a;
|
||||||
|
}
|
||||||
|
|
||||||
|
.submitButton:focus {
|
||||||
|
outline: none;
|
||||||
|
background-color:#bf2a2a;
|
||||||
|
}
|
||||||
|
|
||||||
|
.submitButton:active {
|
||||||
|
position:relative;
|
||||||
|
top:1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes rotate {
|
||||||
|
from { transform: rotate(0deg); }
|
||||||
|
to { transform: rotate(360deg); }
|
||||||
|
}
|
||||||
|
|
||||||
.sponsorSkipButton {
|
.sponsorSkipButton {
|
||||||
background-color:#ec1c1c;
|
background-color:#ec1c1c;
|
||||||
-moz-border-radius:28px;
|
-moz-border-radius:28px;
|
||||||
|
|||||||
98
content.js
98
content.js
@@ -74,8 +74,8 @@ chrome.runtime.onMessage.addListener( // Detect URL Changes
|
|||||||
dontShowNotice = false;
|
dontShowNotice = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.message == "toggleStartSponsorButton") {
|
if (request.message == "changeStartSponsorButton") {
|
||||||
toggleStartSponsorButton();
|
changeStartSponsorButton(request.visibility, request.uploadButtonVisible);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.message == "changeVideoPlayerControlsVisibility") {
|
if (request.message == "changeVideoPlayerControlsVisibility") {
|
||||||
@@ -97,7 +97,9 @@ function videoIDChange(id) {
|
|||||||
}, function(response) {
|
}, function(response) {
|
||||||
if (response != undefined) {
|
if (response != undefined) {
|
||||||
let sponsorTimes = response.sponsorTimes;
|
let sponsorTimes = response.sponsorTimes;
|
||||||
if (sponsorTimes != undefined && sponsorTimes.length > 0 && sponsorTimes[sponsorTimes.length - 1].length < 2) {
|
if (sponsorTimes != undefined && sponsorTimes.length > 0 && sponsorTimes[sponsorTimes.length - 1].length >= 2) {
|
||||||
|
document.getElementById("submitButton").style.display = "unset";
|
||||||
|
} else if (sponsorTimes != undefined && sponsorTimes.length > 0 && sponsorTimes[sponsorTimes.length - 1].length < 2) {
|
||||||
toggleStartSponsorButton();
|
toggleStartSponsorButton();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -184,11 +186,7 @@ function addPlayerControlsButton() {
|
|||||||
|
|
||||||
let startSponsorImage = document.createElement("img");
|
let startSponsorImage = document.createElement("img");
|
||||||
startSponsorImage.id = "startSponsorImage";
|
startSponsorImage.id = "startSponsorImage";
|
||||||
startSponsorImage.style.height = "60%";
|
startSponsorImage.className = "playerButton";
|
||||||
startSponsorImage.style.top = "0";
|
|
||||||
startSponsorImage.style.bottom = "0";
|
|
||||||
startSponsorImage.style.display = "block";
|
|
||||||
startSponsorImage.style.margin = "auto";
|
|
||||||
startSponsorImage.src = chrome.extension.getURL("icons/PlayerStartIconSponsorBlocker256px.png");
|
startSponsorImage.src = chrome.extension.getURL("icons/PlayerStartIconSponsorBlocker256px.png");
|
||||||
|
|
||||||
//add the image to the button
|
//add the image to the button
|
||||||
@@ -201,6 +199,7 @@ function addPlayerControlsButton() {
|
|||||||
|
|
||||||
function removePlayerControlsButton() {
|
function removePlayerControlsButton() {
|
||||||
document.getElementById("startSponsorButton").style.display = "none";
|
document.getElementById("startSponsorButton").style.display = "none";
|
||||||
|
document.getElementById("submitButton").style.display = "none";
|
||||||
}
|
}
|
||||||
|
|
||||||
//adds or removes the player controls button to what it should be
|
//adds or removes the player controls button to what it should be
|
||||||
@@ -209,6 +208,7 @@ function updateVisibilityOfPlayerControlsButton() {
|
|||||||
removePlayerControlsButton();
|
removePlayerControlsButton();
|
||||||
} else {
|
} else {
|
||||||
addPlayerControlsButton();
|
addPlayerControlsButton();
|
||||||
|
addSubmitButton();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,16 +222,58 @@ function startSponsorClicked() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleStartSponsorButton() {
|
function changeStartSponsorButton(visibility, uploadButtonVisible) {
|
||||||
if (showingStartSponsor) {
|
if (visibility) {
|
||||||
showingStartSponsor = false;
|
|
||||||
document.getElementById("startSponsorImage").src = chrome.extension.getURL("icons/PlayerStopIconSponsorBlocker256px.png");
|
|
||||||
} else {
|
|
||||||
showingStartSponsor = true;
|
showingStartSponsor = true;
|
||||||
document.getElementById("startSponsorImage").src = chrome.extension.getURL("icons/PlayerStartIconSponsorBlocker256px.png");
|
document.getElementById("startSponsorImage").src = chrome.extension.getURL("icons/PlayerStartIconSponsorBlocker256px.png");
|
||||||
|
|
||||||
|
if (document.getElementById("startSponsorImage").style.display != "none" && uploadButtonVisible) {
|
||||||
|
document.getElementById("submitButton").style.display = "unset";
|
||||||
|
} else if (!uploadButtonVisible) {
|
||||||
|
//disable submit button
|
||||||
|
document.getElementById("submitButton").style.display = "none";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
showingStartSponsor = false;
|
||||||
|
document.getElementById("startSponsorImage").src = chrome.extension.getURL("icons/PlayerStopIconSponsorBlocker256px.png");
|
||||||
|
|
||||||
|
//disable submit button
|
||||||
|
document.getElementById("submitButton").style.display = "none";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function toggleStartSponsorButton() {
|
||||||
|
changeStartSponsorButton(!showingStartSponsor, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
//shows the submit button on the video player
|
||||||
|
function addSubmitButton() {
|
||||||
|
if (document.getElementById("submitButton") != null) {
|
||||||
|
//it's already added
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//make a submit button
|
||||||
|
let submitButton = document.createElement("button");
|
||||||
|
submitButton.id = "submitButton";
|
||||||
|
submitButton.className = "ytp-button";
|
||||||
|
submitButton.setAttribute("title", "Submit Sponsor Times");
|
||||||
|
submitButton.addEventListener("click", submitSponsorTimes);
|
||||||
|
//hide it at the start
|
||||||
|
submitButton.style.display = "none";
|
||||||
|
|
||||||
|
let submitImage = document.createElement("img");
|
||||||
|
submitImage.id = "submitButtonImage";
|
||||||
|
submitImage.className = "playerButton";
|
||||||
|
submitImage.src = chrome.extension.getURL("icons/PlayerUploadIconSponsorBlocker256px.png");
|
||||||
|
|
||||||
|
//add the image to the button
|
||||||
|
submitButton.appendChild(submitImage);
|
||||||
|
|
||||||
|
let referenceNode = document.getElementsByClassName("ytp-right-controls")[0];
|
||||||
|
referenceNode.prepend(submitButton);
|
||||||
|
}
|
||||||
|
|
||||||
//Opens the notice that tells the user that a sponsor was just skipped
|
//Opens the notice that tells the user that a sponsor was just skipped
|
||||||
function openSkipNotice(){
|
function openSkipNotice(){
|
||||||
if (dontShowNotice) {
|
if (dontShowNotice) {
|
||||||
@@ -460,6 +502,36 @@ function sponsorMessageStarted() {
|
|||||||
toggleStartSponsorButton();
|
toggleStartSponsorButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function submitSponsorTimes() {
|
||||||
|
//add loading animation
|
||||||
|
document.getElementById("submitButtonImage").src = chrome.extension.getURL("icons/PlayerUploadIconSponsorBlocker256px.png");
|
||||||
|
document.getElementById("submitButton").style.animation = "rotate 1s 0s infinite";
|
||||||
|
|
||||||
|
let currentVideoID = getYouTubeVideoID(document.URL);
|
||||||
|
|
||||||
|
chrome.runtime.sendMessage({
|
||||||
|
message: "submitTimes",
|
||||||
|
videoID: currentVideoID
|
||||||
|
}, function(response) {
|
||||||
|
if (response != undefined) {
|
||||||
|
if (response.statusCode == 200) {
|
||||||
|
//hide loading message
|
||||||
|
document.getElementById("submitButton").style.animation = "unset";
|
||||||
|
document.getElementById("submitButton").style.display = "none";
|
||||||
|
|
||||||
|
//clear the sponsor times
|
||||||
|
let sponsorTimeKey = "sponsorTimes" + currentVideoID;
|
||||||
|
chrome.storage.local.set({[sponsorTimeKey]: []});
|
||||||
|
} else {
|
||||||
|
//for a more detailed error message, they should check the popup
|
||||||
|
//show that the upload failed
|
||||||
|
document.getElementById("submitButton").style.animation = "unset";
|
||||||
|
document.getElementById("submitButtonImage").src = chrome.extension.getURL("icons/PlayerUploadFailedIconSponsorBlocker256px.png");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function sendRequestToServer(type, address, callback) {
|
function sendRequestToServer(type, address, callback) {
|
||||||
let xmlhttp = new XMLHttpRequest();
|
let xmlhttp = new XMLHttpRequest();
|
||||||
|
|
||||||
|
|||||||
BIN
icons/PlayerUploadFailedIconSponsorBlocker256px.png
Normal file
BIN
icons/PlayerUploadFailedIconSponsorBlocker256px.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
BIN
icons/PlayerUploadIconSponsorBlocker256px.png
Normal file
BIN
icons/PlayerUploadIconSponsorBlocker256px.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
@@ -22,6 +22,8 @@
|
|||||||
"icons/IconSponsorBlocker256px.png",
|
"icons/IconSponsorBlocker256px.png",
|
||||||
"icons/PlayerStartIconSponsorBlocker256px.png",
|
"icons/PlayerStartIconSponsorBlocker256px.png",
|
||||||
"icons/PlayerStopIconSponsorBlocker256px.png",
|
"icons/PlayerStopIconSponsorBlocker256px.png",
|
||||||
|
"icons/PlayerUploadIconSponsorBlocker256px.png",
|
||||||
|
"icons/PlayerUploadFailedIconSponsorBlocker256px.png",
|
||||||
"icons/upvote.png",
|
"icons/upvote.png",
|
||||||
"icons/downvote.png"
|
"icons/downvote.png"
|
||||||
],
|
],
|
||||||
|
|||||||
9
popup.js
9
popup.js
@@ -241,14 +241,17 @@ function getSponsorTimesMessage(sponsorTimes) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function clearTimes() {
|
function clearTimes() {
|
||||||
//check if the player controls should be toggled
|
//send new sponsor time state to tab
|
||||||
if (sponsorTimes.length > 0 && sponsorTimes[sponsorTimes.length - 1].length < 2) {
|
if (sponsorTimes.length > 0) {
|
||||||
|
let visibility = sponsorTimes[sponsorTimes.length - 1].length >= 2;
|
||||||
chrome.tabs.query({
|
chrome.tabs.query({
|
||||||
active: true,
|
active: true,
|
||||||
currentWindow: true
|
currentWindow: true
|
||||||
}, function(tabs) {
|
}, function(tabs) {
|
||||||
chrome.tabs.sendMessage(tabs[0].id, {
|
chrome.tabs.sendMessage(tabs[0].id, {
|
||||||
message: "toggleStartSponsorButton"
|
message: "changeStartSponsorButton",
|
||||||
|
visibility: visibility,
|
||||||
|
uploadButtonVisible: false
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user