Compare commits

...

12 Commits

Author SHA1 Message Date
Ajay Ramachandran
c4da85340a Merge pull request #277 from ajayyy/experimental
Fixed regex to support Firefox
2020-02-11 14:10:47 -05:00
Ajay Ramachandran
ec59c7e0f9 Increase version number. 2020-02-11 14:10:11 -05:00
Ajay Ramachandran
2454cd9a39 Fixed regex to support Firefox. 2020-02-11 12:29:19 -05:00
Ajay Ramachandran
c19e2bea29 Merge pull request #274 from ajayyy/experimental
Various fixes
2020-02-10 22:35:54 -05:00
Ajay Ramachandran
2f2c1ad49b Increased version number. 2020-02-10 22:32:15 -05:00
Ajay Ramachandran
657aff2167 Removed use of Invidious API.
Resolves https://github.com/ajayyy/SponsorBlock/issues/189.
2020-02-10 22:27:54 -05:00
Ajay Ramachandran
2450457fe5 Fixed close button on dark theme.
Resolves https://github.com/ajayyy/SponsorBlock/issues/196
2020-02-10 21:54:11 -05:00
Ajay Ramachandran
ba9e42e6f0 Forced auto skip if previewing sponsor.
Resolves https://github.com/ajayyy/SponsorBlock/issues/222
2020-02-10 21:49:17 -05:00
Ajay Ramachandran
f05d80523b Made it unpause when previewing a sponsor.
Resolves https://github.com/ajayyy/SponsorBlock/issues/222
2020-02-10 21:39:39 -05:00
Ajay Ramachandran
d2779aba86 Fix editing not adding numbers.
Resolves https://github.com/ajayyy/SponsorBlock/issues/273.
2020-02-10 18:03:09 -05:00
Ajay Ramachandran
852912a42b Fixed inlines sponsor popup.
Fixes https://github.com/ajayyy/SponsorBlock/issues/272
2020-02-10 17:12:52 -05:00
Ajay Ramachandran
45e0f87f9f Reformatted manifest. 2020-02-09 11:14:40 -05:00
4 changed files with 75 additions and 50 deletions

View File

@@ -68,7 +68,7 @@ The result is in `dist`.
# Credit # Credit
The awesome [Invidious API](https://github.com/omarroth/invidious/wiki/API) is used to grab the time the video was published. The awesome [Invidious API](https://github.com/omarroth/invidious/wiki/API) used to be used.
Original code from [YTSponsorSkip](https://github.com/OfficialNoob/YTSponsorSkip), but not much of the code is left. Original code from [YTSponsorSkip](https://github.com/OfficialNoob/YTSponsorSkip), but not much of the code is left.

View File

@@ -1,11 +1,10 @@
{ {
"name": "__MSG_fullName__", "name": "__MSG_fullName__",
"short_name": "__MSG_Name__", "short_name": "__MSG_Name__",
"version": "1.2.8", "version": "1.2.12",
"default_locale": "en", "default_locale": "en",
"description": "__MSG_Description__", "description": "__MSG_Description__",
"content_scripts": [ "content_scripts": [{
{
"run_at": "document_start", "run_at": "document_start",
"matches": [ "matches": [
"https://*.youtube.com/*", "https://*.youtube.com/*",
@@ -21,8 +20,7 @@
"./libs/Source+Sans+Pro.css", "./libs/Source+Sans+Pro.css",
"popup.css" "popup.css"
] ]
} }],
],
"web_accessible_resources": [ "web_accessible_resources": [
"icons/LogoSponsorBlocker256px.png", "icons/LogoSponsorBlocker256px.png",
"icons/IconSponsorBlocker256px.png", "icons/IconSponsorBlocker256px.png",

View File

@@ -27,7 +27,7 @@ var hiddenSponsorTimes = [];
var sponsorSkipped = []; var sponsorSkipped = [];
//the video //the video
var v; var video: HTMLVideoElement;
var onInvidious; var onInvidious;
@@ -49,6 +49,10 @@ var channelWhitelisted = false;
// create preview bar // create preview bar
var previewBar = null; var previewBar = null;
// When not null, a sponsor is currently being previewed and auto skip should be enabled.
// This is set to a timeout function when that happens that will reset it after 3 seconds.
var previewResetter: NodeJS.Timeout = null;
//the player controls on the YouTube player //the player controls on the YouTube player
var controls = null; var controls = null;
@@ -85,7 +89,7 @@ var skipNoticeContentContainer = () => ({
unskipSponsorTime, unskipSponsorTime,
sponsorTimes, sponsorTimes,
UUIDs, UUIDs,
v, v: video,
reskipSponsorTime, reskipSponsorTime,
hiddenSponsorTimes, hiddenSponsorTimes,
updatePreviewBar updatePreviewBar
@@ -132,16 +136,29 @@ function messageListener(request: any, sender: any, sendResponse: (response: any
break; break;
case "getVideoDuration": case "getVideoDuration":
sendResponse({ sendResponse({
duration: v.duration duration: video.duration
}); });
break; break;
case "skipToTime": case "skipToTime":
v.currentTime = request.time; video.currentTime = request.time;
// Unpause the video if needed
if (video.paused){
video.play();
}
// Start preview resetter
if (previewResetter !== null){
clearTimeout(previewResetter);
}
previewResetter = setTimeout(() => previewResetter = null, 4000);
return return
case "getCurrentTime": case "getCurrentTime":
sendResponse({ sendResponse({
currentTime: v.currentTime currentTime: video.currentTime
}); });
break; break;
@@ -346,9 +363,9 @@ async function videoIDChange(id) {
function sponsorsLookup(id: string, channelIDPromise?) { function sponsorsLookup(id: string, channelIDPromise?) {
v = document.querySelector('video') // Youtube video player video = document.querySelector('video') // Youtube video player
//there is no video here //there is no video here
if (v == null) { if (video == null) {
setTimeout(() => sponsorsLookup(id, channelIDPromise), 100); setTimeout(() => sponsorsLookup(id, channelIDPromise), 100);
return; return;
} }
@@ -357,7 +374,7 @@ function sponsorsLookup(id: string, channelIDPromise?) {
durationListenerSetUp = true; durationListenerSetUp = true;
//wait until it is loaded //wait until it is loaded
v.addEventListener('durationchange', updatePreviewBar); video.addEventListener('durationchange', updatePreviewBar);
} }
if (channelIDPromise !== undefined) { if (channelIDPromise !== undefined) {
@@ -415,7 +432,7 @@ function sponsorsLookup(id: string, channelIDPromise?) {
//update the preview bar //update the preview bar
//leave the type blank for now until categories are added //leave the type blank for now until categories are added
if (lastPreviewBarUpdate == id || (lastPreviewBarUpdate == null && !isNaN(v.duration))) { if (lastPreviewBarUpdate == id || (lastPreviewBarUpdate == null && !isNaN(video.duration))) {
//set it now //set it now
//otherwise the listener can handle it //otherwise the listener can handle it
updatePreviewBar(); updatePreviewBar();
@@ -427,12 +444,19 @@ function sponsorsLookup(id: string, channelIDPromise?) {
//check if this video was uploaded recently //check if this video was uploaded recently
//use the invidious api to get the time published //use the invidious api to get the time published
sendRequestToCustomServer('GET', "https://invidio.us/api/v1/videos/" + id + '?fields=published', function(xmlhttp, error) { sendRequestToCustomServer('GET', "https://www.youtube.com/get_video_info?video_id=" + id, function(xmlhttp, error) {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
let unixTimePublished = JSON.parse(xmlhttp.responseText).published; let decodedData = decodeURIComponent(xmlhttp.responseText).match(/player_response=([^&]*)/)[1];
if (decodedData === undefined) {
console.error("[SB] Failed at getting video upload date info from YouTube.");
return;
}
let dateUploaded = JSON.parse(decodedData).microformat.playerMicroformatRenderer.uploadDate;
//if less than 3 days old //if less than 3 days old
if ((Date.now() / 1000) - unixTimePublished < 259200) { if (Date.now() - new Date(dateUploaded).getTime() < 259200000) {
//TODO lower when server becomes better //TODO lower when server becomes better
setTimeout(() => sponsorsLookup(id, channelIDPromise), 180000); setTimeout(() => sponsorsLookup(id, channelIDPromise), 180000);
} }
@@ -453,7 +477,7 @@ function sponsorsLookup(id: string, channelIDPromise?) {
//add the event to run on the videos "ontimeupdate" //add the event to run on the videos "ontimeupdate"
if (!Config.config.disableSkipping) { if (!Config.config.disableSkipping) {
v.ontimeupdate = function () { video.ontimeupdate = function () {
sponsorCheck(); sponsorCheck();
}; };
} }
@@ -568,7 +592,7 @@ function updatePreviewBar() {
types.push("previewSponsor"); types.push("previewSponsor");
} }
utils.wait(() => previewBar !== null).then((result) => previewBar.set(allSponsorTimes, types, v.duration)); utils.wait(() => previewBar !== null).then((result) => previewBar.set(allSponsorTimes, types, video.duration));
//update last video id //update last video id
lastPreviewBarUpdate = sponsorVideoID; lastPreviewBarUpdate = sponsorVideoID;
@@ -588,7 +612,7 @@ function whitelistCheck() {
function sponsorCheck() { function sponsorCheck() {
if (Config.config.disableSkipping) { if (Config.config.disableSkipping) {
// Make sure this isn't called again // Make sure this isn't called again
v.ontimeupdate = null; video.ontimeupdate = null;
return; return;
} else if (channelWhitelisted) { } else if (channelWhitelisted) {
return; return;
@@ -619,20 +643,20 @@ function sponsorCheck() {
//don't keep track until they are loaded in //don't keep track until they are loaded in
if (sponsorTimes !== null || sponsorTimesSubmitting.length > 0) { if (sponsorTimes !== null || sponsorTimesSubmitting.length > 0) {
lastTime = v.currentTime; lastTime = video.currentTime;
} }
} }
function checkSponsorTime(sponsorTimes, index, openNotice): boolean { function checkSponsorTime(sponsorTimes, index, openNotice): boolean {
//this means part of the video was just skipped //this means part of the video was just skipped
if (Math.abs(v.currentTime - lastTime) > 1 && lastTime != -1) { if (Math.abs(video.currentTime - lastTime) > 1 && lastTime != -1) {
//make lastTime as if the video was playing normally //make lastTime as if the video was playing normally
lastTime = v.currentTime - 0.0001; lastTime = video.currentTime - 0.0001;
} }
if (checkIfTimeToSkip(v.currentTime, sponsorTimes[index][0], sponsorTimes[index][1]) && !hiddenSponsorTimes.includes(index)) { if (checkIfTimeToSkip(video.currentTime, sponsorTimes[index][0], sponsorTimes[index][1]) && !hiddenSponsorTimes.includes(index)) {
//skip it //skip it
skipToTime(v, index, sponsorTimes, openNotice); skipToTime(video, index, sponsorTimes, openNotice);
//something was skipped //something was skipped
return true; return true;
@@ -652,7 +676,7 @@ function checkIfTimeToSkip(currentVideoTime, startTime, endTime) {
//skip fromt he start time to the end time for a certain index sponsor time //skip fromt he start time to the end time for a certain index sponsor time
function skipToTime(v, index, sponsorTimes, openNotice) { function skipToTime(v, index, sponsorTimes, openNotice) {
if (!Config.config.disableAutoSkip) { if (!Config.config.disableAutoSkip || previewResetter !== null) {
v.currentTime = sponsorTimes[index][1]; v.currentTime = sponsorTimes[index][1];
} }
@@ -690,14 +714,14 @@ function skipToTime(v, index, sponsorTimes, openNotice) {
function unskipSponsorTime(UUID) { function unskipSponsorTime(UUID) {
if (sponsorTimes != null) { if (sponsorTimes != null) {
//add a tiny bit of time to make sure it is not skipped again //add a tiny bit of time to make sure it is not skipped again
v.currentTime = sponsorTimes[UUIDs.indexOf(UUID)][0] + 0.001; video.currentTime = sponsorTimes[UUIDs.indexOf(UUID)][0] + 0.001;
} }
} }
function reskipSponsorTime(UUID) { function reskipSponsorTime(UUID) {
if (sponsorTimes != null) { if (sponsorTimes != null) {
//add a tiny bit of time to make sure it is not skipped again //add a tiny bit of time to make sure it is not skipped again
v.currentTime = sponsorTimes[UUIDs.indexOf(UUID)][1]; video.currentTime = sponsorTimes[UUIDs.indexOf(UUID)][1];
} }
} }
@@ -786,7 +810,7 @@ function startSponsorClicked() {
//send back current time with message //send back current time with message
chrome.runtime.sendMessage({ chrome.runtime.sendMessage({
message: "addSponsorTime", message: "addSponsorTime",
time: v.currentTime, time: video.currentTime,
videoID: sponsorVideoID videoID: sponsorVideoID
}, function(response) { }, function(response) {
//see if the sponsorTimesSubmitting needs to be updated //see if the sponsorTimesSubmitting needs to be updated
@@ -875,6 +899,8 @@ function openInfoMenu() {
closeButton.classList.add("smallLink"); closeButton.classList.add("smallLink");
closeButton.setAttribute("align", "center"); closeButton.setAttribute("align", "center");
closeButton.addEventListener("click", closeInfoMenu); closeButton.addEventListener("click", closeInfoMenu);
// Theme based color
closeButton.style.color = "var(--yt-spec-text-primary)";
//add the close button //add the close button
popup.prepend(closeButton); popup.prepend(closeButton);
@@ -1012,11 +1038,11 @@ function dontShowNoticeAgain() {
} }
function sponsorMessageStarted(callback) { function sponsorMessageStarted(callback) {
v = document.querySelector('video'); video = document.querySelector('video');
//send back current time //send back current time
callback({ callback({
time: v.currentTime time: video.currentTime
}) })
//update button //update button
@@ -1039,8 +1065,8 @@ function submitSponsorTimes() {
if (sponsorTimes != undefined && sponsorTimes.length > 0) { if (sponsorTimes != undefined && sponsorTimes.length > 0) {
//check if a sponsor exceeds the duration of the video //check if a sponsor exceeds the duration of the video
for (let i = 0; i < sponsorTimes.length; i++) { for (let i = 0; i < sponsorTimes.length; i++) {
if (sponsorTimes[i][1] > v.duration) { if (sponsorTimes[i][1] > video.duration) {
sponsorTimes[i][1] = v.duration; sponsorTimes[i][1] = video.duration;
} }
} }
//update sponsorTimes //update sponsorTimes

View File

@@ -38,7 +38,7 @@ class MessageHandler {
//make this a function to allow this to run on the content page //make this a function to allow this to run on the content page
async function runThePopup(messageListener?: MessageListener) { async function runThePopup(messageListener?: MessageListener) {
var messageHandler = new MessageHandler(); var messageHandler = new MessageHandler(messageListener);
utils.localizeHtmlPage(); utils.localizeHtmlPage();
@@ -656,9 +656,9 @@ async function runThePopup(messageListener?: MessageListener) {
tabs[0].id, tabs[0].id,
{message: "getCurrentTime"}, {message: "getCurrentTime"},
function (response) { function (response) {
let minutes = <HTMLInputElement> <unknown> document.getElementById(idStartName + "Minutes" + index); let minutes = <HTMLInputElement> <unknown> document.getElementById(idStartName + "Minutes" + index);
let seconds = <HTMLInputElement> <unknown> document.getElementById(idStartName + "Seconds" + index); let seconds = <HTMLInputElement> <unknown> document.getElementById(idStartName + "Seconds" + index);
minutes.value = String(getTimeInMinutes(response.currentTime)); minutes.value = String(getTimeInMinutes(response.currentTime));
seconds.value = getTimeInFormattedSeconds(response.currentTime); seconds.value = getTimeInFormattedSeconds(response.currentTime);
}); });
@@ -667,11 +667,11 @@ async function runThePopup(messageListener?: MessageListener) {
//id start name is whether it is the startTime or endTime //id start name is whether it is the startTime or endTime
//gives back the time in seconds //gives back the time in seconds
function getSponsorTimeEditTimes(idStartName, index) { function getSponsorTimeEditTimes(idStartName, index): number {
let minutes = <HTMLInputElement> <unknown> document.getElementById(idStartName + "Minutes" + index); let minutes = <HTMLInputElement> <unknown> document.getElementById(idStartName + "Minutes" + index);
let seconds = <HTMLInputElement> <unknown> document.getElementById(idStartName + "Seconds" + index); let seconds = <HTMLInputElement> <unknown> document.getElementById(idStartName + "Seconds" + index);
return parseInt(minutes.value) * 60 + seconds.value; return parseInt(minutes.value) * 60 + parseInt(seconds.value);
} }
function saveSponsorTimeEdit(index, closeEditMode = true) { function saveSponsorTimeEdit(index, closeEditMode = true) {
@@ -679,16 +679,17 @@ async function runThePopup(messageListener?: MessageListener) {
sponsorTimes[index][1] = getSponsorTimeEditTimes("endTime", index); sponsorTimes[index][1] = getSponsorTimeEditTimes("endTime", index);
//save this //save this
Config.config.sponsorTimes.set(currentVideoID, sponsorTimes); Config.config.sponsorTimes.set(currentVideoID, sponsorTimes);
messageHandler.query({
active: true, messageHandler.query({
currentWindow: true active: true,
}, tabs => { currentWindow: true
messageHandler.sendMessage( }, tabs => {
tabs[0].id, messageHandler.sendMessage(
{message: "sponsorDataChanged"} tabs[0].id,
); {message: "sponsorDataChanged"}
}); );
});
if (closeEditMode) { if (closeEditMode) {
displaySponsorTimes(); displaySponsorTimes();
@@ -968,7 +969,7 @@ async function runThePopup(messageListener?: MessageListener) {
secondsDisplay = "0" + secondsDisplay; secondsDisplay = "0" + secondsDisplay;
} }
let formatted = minutes+ ":" + secondsDisplay; let formatted = minutes + ":" + secondsDisplay;
return formatted; return formatted;
} }