mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-11 14:07:13 +03:00
Merge pull request #104 from ajayyy/experimental-ajay
Edit panel additions
This commit is contained in:
@@ -141,7 +141,7 @@ function submitVote(type, UUID, callback) {
|
|||||||
function submitTimes(videoID, callback) {
|
function submitTimes(videoID, callback) {
|
||||||
//get the video times from storage
|
//get the video times from storage
|
||||||
let sponsorTimeKey = 'sponsorTimes' + videoID;
|
let sponsorTimeKey = 'sponsorTimes' + videoID;
|
||||||
chrome.storage.sync.get([sponsorTimeKey], function(result) {
|
chrome.storage.sync.get([sponsorTimeKey, "userID"], function(result) {
|
||||||
let sponsorTimes = result[sponsorTimeKey];
|
let sponsorTimes = result[sponsorTimeKey];
|
||||||
let userID = result.userID;
|
let userID = result.userID;
|
||||||
|
|
||||||
|
|||||||
10
content.js
10
content.js
@@ -119,6 +119,16 @@ function messageListener(request, sender, sendResponse) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (request.message == "skipToTime") {
|
||||||
|
v.currentTime = request.time;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request.message == "getCurrentTime") {
|
||||||
|
sendResponse({
|
||||||
|
currentTime: v.currentTime
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (request.message == "getChannelURL") {
|
if (request.message == "getChannelURL") {
|
||||||
sendResponse({
|
sendResponse({
|
||||||
channelURL: channelURL
|
channelURL: channelURL
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "SponsorBlock for YouTube - Skip Sponsorships",
|
"name": "SponsorBlock for YouTube - Skip Sponsorships",
|
||||||
"short_name": "SponsorBlock",
|
"short_name": "SponsorBlock",
|
||||||
"version": "1.0.31",
|
"version": "1.0.33",
|
||||||
"description": "Skip over sponsorship on YouTube videos. Report sponsors on videos you watch to save the time of others.",
|
"description": "Skip over sponsorship on YouTube videos. Report sponsors on videos you watch to save the time of others.",
|
||||||
"content_scripts": [
|
"content_scripts": [
|
||||||
{
|
{
|
||||||
|
|||||||
10
popup.css
10
popup.css
@@ -80,8 +80,14 @@ h1.popupElement {
|
|||||||
|
|
||||||
.mediumLink.popupElement {
|
.mediumLink.popupElement {
|
||||||
font-size: 15px;
|
font-size: 15px;
|
||||||
padding-left: 15px;
|
margin-left: 25px;
|
||||||
padding-right: 15px;
|
margin-right: 25px;
|
||||||
|
text-decoration: underline;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tinyLink.popupElement {
|
||||||
|
font-size: 10px;
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,6 +93,8 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
</b>
|
</b>
|
||||||
|
|
||||||
|
<br/>
|
||||||
|
|
||||||
<button id="clearTimes" class="smallButton popupElement">Clear Times</button>
|
<button id="clearTimes" class="smallButton popupElement">Clear Times</button>
|
||||||
|
|
||||||
|
|||||||
113
popup.js
113
popup.js
@@ -208,14 +208,18 @@ function runThePopup() {
|
|||||||
|
|
||||||
function onTabs(tabs) {
|
function onTabs(tabs) {
|
||||||
chrome.tabs.sendMessage(tabs[0].id, {message: 'getVideoID'}, function(result) {
|
chrome.tabs.sendMessage(tabs[0].id, {message: 'getVideoID'}, function(result) {
|
||||||
if (result.videoID) {
|
if (result != undefined && result.videoID) {
|
||||||
loadTabData(tabs, result.videoid);
|
currentVideoID = result.videoID;
|
||||||
}
|
|
||||||
|
loadTabData(tabs);
|
||||||
|
} else if (result == undefined && chrome.runtime.lastError) {
|
||||||
|
//this isn't a YouTube video then, or at least the content script is not loaded
|
||||||
|
displayNoVideo();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadTabData(tabs, currentVideoID) {
|
function loadTabData(tabs) {
|
||||||
|
|
||||||
if (!currentVideoID) {
|
if (!currentVideoID) {
|
||||||
//this isn't a YouTube video then
|
//this isn't a YouTube video then
|
||||||
displayNoVideo();
|
displayNoVideo();
|
||||||
@@ -469,8 +473,11 @@ function runThePopup() {
|
|||||||
let index = i;
|
let index = i;
|
||||||
deleteButton.addEventListener("click", () => deleteSponsorTime(index));
|
deleteButton.addEventListener("click", () => deleteSponsorTime(index));
|
||||||
|
|
||||||
let spacer = document.createElement("span");
|
let previewButton = document.createElement("span");
|
||||||
spacer.innerText = " ";
|
previewButton.id = "sponsorTimePreviewButton" + i;
|
||||||
|
previewButton.innerText = "Preview";
|
||||||
|
previewButton.className = "mediumLink popupElement";
|
||||||
|
previewButton.addEventListener("click", () => previewSponsorTime(index));
|
||||||
|
|
||||||
let editButton = document.createElement("span");
|
let editButton = document.createElement("span");
|
||||||
editButton.id = "sponsorTimeEditButton" + i;
|
editButton.id = "sponsorTimeEditButton" + i;
|
||||||
@@ -492,19 +499,46 @@ function runThePopup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
currentSponsorTimeContainer.innerText = currentSponsorTimeMessage;
|
currentSponsorTimeContainer.innerText = currentSponsorTimeMessage;
|
||||||
currentSponsorTimeContainer.addEventListener("click", () => editSponsorTime(index));
|
|
||||||
|
|
||||||
sponsorTimesContainer.appendChild(currentSponsorTimeContainer);
|
sponsorTimesContainer.appendChild(currentSponsorTimeContainer);
|
||||||
sponsorTimesContainer.appendChild(deleteButton);
|
sponsorTimesContainer.appendChild(deleteButton);
|
||||||
|
|
||||||
//only if it is a complete sponsor time
|
//only if it is a complete sponsor time
|
||||||
if (sponsorTimes[i].length > 1) {
|
if (sponsorTimes[i].length > 1) {
|
||||||
|
sponsorTimesContainer.appendChild(previewButton);
|
||||||
sponsorTimesContainer.appendChild(editButton);
|
sponsorTimesContainer.appendChild(editButton);
|
||||||
|
|
||||||
|
currentSponsorTimeContainer.addEventListener("click", () => editSponsorTime(index));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return sponsorTimesContainer;
|
return sponsorTimesContainer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function previewSponsorTime(index) {
|
||||||
|
let skipTime = sponsorTimes[index][0];
|
||||||
|
|
||||||
|
if (document.getElementById("startTimeMinutes" + index) != null) {
|
||||||
|
//edit is currently open, use that time
|
||||||
|
|
||||||
|
skipTime = getSponsorTimeEditTimes("startTime", index);
|
||||||
|
|
||||||
|
//save the edit
|
||||||
|
saveSponsorTimeEdit(index, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
chrome.tabs.query({
|
||||||
|
active: true,
|
||||||
|
currentWindow: true
|
||||||
|
}, tabs => {
|
||||||
|
chrome.tabs.sendMessage(
|
||||||
|
tabs[0].id, {
|
||||||
|
message: "skipToTime",
|
||||||
|
time: skipTime - 2
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function editSponsorTime(index) {
|
function editSponsorTime(index) {
|
||||||
if (document.getElementById("startTimeMinutes" + index) != null) {
|
if (document.getElementById("startTimeMinutes" + index) != null) {
|
||||||
@@ -517,6 +551,13 @@ function runThePopup() {
|
|||||||
|
|
||||||
let sponsorTimeContainer = document.getElementById("sponsorTimeContainer" + index);
|
let sponsorTimeContainer = document.getElementById("sponsorTimeContainer" + index);
|
||||||
|
|
||||||
|
//the button to set the current time
|
||||||
|
let startTimeNowButton = document.createElement("span");
|
||||||
|
startTimeNowButton.id = "startTimeNowButton" + index;
|
||||||
|
startTimeNowButton.innerText = "(Now)";
|
||||||
|
startTimeNowButton.className = "tinyLink popupElement";
|
||||||
|
startTimeNowButton.addEventListener("click", () => setEditTimeToCurrentTime("startTime", index));
|
||||||
|
|
||||||
//get sponsor time minutes and seconds boxes
|
//get sponsor time minutes and seconds boxes
|
||||||
let startTimeMinutes = document.createElement("input");
|
let startTimeMinutes = document.createElement("input");
|
||||||
startTimeMinutes.id = "startTimeMinutes" + index;
|
startTimeMinutes.id = "startTimeMinutes" + index;
|
||||||
@@ -531,7 +572,7 @@ function runThePopup() {
|
|||||||
startTimeSeconds.type = "text";
|
startTimeSeconds.type = "text";
|
||||||
startTimeSeconds.value = getTimeInFormattedSeconds(sponsorTimes[index][0]);
|
startTimeSeconds.value = getTimeInFormattedSeconds(sponsorTimes[index][0]);
|
||||||
startTimeSeconds.style.width = "60px";
|
startTimeSeconds.style.width = "60px";
|
||||||
|
|
||||||
let endTimeMinutes = document.createElement("input");
|
let endTimeMinutes = document.createElement("input");
|
||||||
endTimeMinutes.id = "endTimeMinutes" + index;
|
endTimeMinutes.id = "endTimeMinutes" + index;
|
||||||
endTimeMinutes.className = "sponsorTime popupElement";
|
endTimeMinutes.className = "sponsorTime popupElement";
|
||||||
@@ -545,6 +586,13 @@ function runThePopup() {
|
|||||||
endTimeSeconds.type = "text";
|
endTimeSeconds.type = "text";
|
||||||
endTimeSeconds.value = getTimeInFormattedSeconds(sponsorTimes[index][1]);
|
endTimeSeconds.value = getTimeInFormattedSeconds(sponsorTimes[index][1]);
|
||||||
endTimeSeconds.style.width = "60px";
|
endTimeSeconds.style.width = "60px";
|
||||||
|
|
||||||
|
//the button to set the current time
|
||||||
|
let endTimeNowButton = document.createElement("span");
|
||||||
|
endTimeNowButton.id = "endTimeNowButton" + index;
|
||||||
|
endTimeNowButton.innerText = "(Now)";
|
||||||
|
endTimeNowButton.className = "tinyLink popupElement";
|
||||||
|
endTimeNowButton.addEventListener("click", () => setEditTimeToCurrentTime("endTime", index));
|
||||||
|
|
||||||
let colonText = document.createElement("span");
|
let colonText = document.createElement("span");
|
||||||
colonText.innerText = ":";
|
colonText.innerText = ":";
|
||||||
@@ -557,6 +605,7 @@ function runThePopup() {
|
|||||||
sponsorTimeContainer.removeChild(sponsorTimeContainer.firstChild);
|
sponsorTimeContainer.removeChild(sponsorTimeContainer.firstChild);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sponsorTimeContainer.appendChild(startTimeNowButton);
|
||||||
sponsorTimeContainer.appendChild(startTimeMinutes);
|
sponsorTimeContainer.appendChild(startTimeMinutes);
|
||||||
sponsorTimeContainer.appendChild(colonText);
|
sponsorTimeContainer.appendChild(colonText);
|
||||||
sponsorTimeContainer.appendChild(startTimeSeconds);
|
sponsorTimeContainer.appendChild(startTimeSeconds);
|
||||||
@@ -564,6 +613,7 @@ function runThePopup() {
|
|||||||
sponsorTimeContainer.appendChild(endTimeMinutes);
|
sponsorTimeContainer.appendChild(endTimeMinutes);
|
||||||
sponsorTimeContainer.appendChild(colonText);
|
sponsorTimeContainer.appendChild(colonText);
|
||||||
sponsorTimeContainer.appendChild(endTimeSeconds);
|
sponsorTimeContainer.appendChild(endTimeSeconds);
|
||||||
|
sponsorTimeContainer.appendChild(endTimeNowButton);
|
||||||
|
|
||||||
//add save button and remove edit button
|
//add save button and remove edit button
|
||||||
let saveButton = document.createElement("span");
|
let saveButton = document.createElement("span");
|
||||||
@@ -577,16 +627,37 @@ function runThePopup() {
|
|||||||
|
|
||||||
sponsorTimesContainer.replaceChild(saveButton, editButton);
|
sponsorTimesContainer.replaceChild(saveButton, editButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setEditTimeToCurrentTime(idStartName, index) {
|
||||||
|
chrome.tabs.query({
|
||||||
|
active: true,
|
||||||
|
currentWindow: true
|
||||||
|
}, tabs => {
|
||||||
|
chrome.tabs.sendMessage(
|
||||||
|
tabs[0].id,
|
||||||
|
{message: "getCurrentTime"},
|
||||||
|
function (response) {
|
||||||
|
let minutes = document.getElementById(idStartName + "Minutes" + index);
|
||||||
|
let seconds = document.getElementById(idStartName + "Seconds" + index);
|
||||||
|
|
||||||
|
minutes.value = getTimeInMinutes(response.currentTime);
|
||||||
|
seconds.value = getTimeInFormattedSeconds(response.currentTime);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//id start name is whether it is the startTime or endTime
|
||||||
|
//gives back the time in seconds
|
||||||
|
function getSponsorTimeEditTimes(idStartName, index) {
|
||||||
|
let minutes = document.getElementById(idStartName + "Minutes" + index);
|
||||||
|
let seconds = document.getElementById(idStartName + "Seconds" + index);
|
||||||
|
|
||||||
|
return parseInt(minutes.value) * 60 + parseFloat(seconds.value);
|
||||||
|
}
|
||||||
|
|
||||||
function saveSponsorTimeEdit(index) {
|
function saveSponsorTimeEdit(index, closeEditMode = true) {
|
||||||
let startTimeMinutes = document.getElementById("startTimeMinutes" + index);
|
sponsorTimes[index][0] = getSponsorTimeEditTimes("startTime", index);
|
||||||
let startTimeSeconds = document.getElementById("startTimeSeconds" + index);
|
sponsorTimes[index][1] = getSponsorTimeEditTimes("endTime", index);
|
||||||
|
|
||||||
let endTimeMinutes = document.getElementById("endTimeMinutes" + index);
|
|
||||||
let endTimeSeconds = document.getElementById("endTimeSeconds" + index);
|
|
||||||
|
|
||||||
sponsorTimes[index][0] = parseInt(startTimeMinutes.value) * 60 + parseFloat(startTimeSeconds.value);
|
|
||||||
sponsorTimes[index][1] = parseInt(endTimeMinutes.value) * 60 + parseFloat(endTimeSeconds.value);
|
|
||||||
|
|
||||||
//save this
|
//save this
|
||||||
let sponsorTimeKey = "sponsorTimes" + currentVideoID;
|
let sponsorTimeKey = "sponsorTimes" + currentVideoID;
|
||||||
@@ -602,9 +673,11 @@ function runThePopup() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
displaySponsorTimes();
|
if (closeEditMode) {
|
||||||
|
displaySponsorTimes();
|
||||||
|
|
||||||
showSubmitTimesIfNecessary();
|
showSubmitTimesIfNecessary();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//deletes the sponsor time submitted at an index
|
//deletes the sponsor time submitted at an index
|
||||||
|
|||||||
Reference in New Issue
Block a user