mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2026-01-29 22:00:56 +03:00
Merge master
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import Config from "./config";
|
||||
|
||||
import { SponsorTime, CategorySkipOption, CategorySelection, VideoID, SponsorHideType, FetchResponse } from "./types";
|
||||
import { SponsorTime, CategorySkipOption, VideoID, SponsorHideType, FetchResponse, VideoInfo, StorageChangesObject } from "./types";
|
||||
|
||||
import { ContentContainer } from "./types";
|
||||
import Utils from "./utils";
|
||||
@@ -26,7 +26,7 @@ let sponsorTimes: SponsorTime[] = null;
|
||||
let sponsorVideoID: VideoID = null;
|
||||
|
||||
// JSON video info
|
||||
let videoInfo: any = null;
|
||||
let videoInfo: VideoInfo = null;
|
||||
//the channel this video is about
|
||||
let channelID: string;
|
||||
|
||||
@@ -54,6 +54,9 @@ let durationListenerSetUp = false;
|
||||
// Is the video currently being switched
|
||||
let switchingVideos = null;
|
||||
|
||||
// Made true every videoID change
|
||||
let firstEvent = false;
|
||||
|
||||
// Used by the play and playing listeners to make sure two aren't
|
||||
// called at the same time
|
||||
let lastCheckTime = 0;
|
||||
@@ -179,7 +182,7 @@ function messageListener(request: Message, sender: unknown, sendResponse: (respo
|
||||
*
|
||||
* @param {String} changes
|
||||
*/
|
||||
function contentConfigUpdateListener(changes) {
|
||||
function contentConfigUpdateListener(changes: StorageChangesObject) {
|
||||
for (const key in changes) {
|
||||
switch(key) {
|
||||
case "hideVideoPlayerControls":
|
||||
@@ -244,6 +247,8 @@ function resetValues() {
|
||||
switchingVideos = true;
|
||||
}
|
||||
|
||||
firstEvent = true;
|
||||
|
||||
// Reset advert playing flag
|
||||
isAdPlaying = false;
|
||||
}
|
||||
@@ -363,7 +368,7 @@ function handleMobileControlsMutations(): void {
|
||||
|
||||
if (previewBar !== null) {
|
||||
if (document.body.contains(previewBar.container)) {
|
||||
updatePreviewBarPositionMobile(document.getElementsByClassName(mobileYouTubeSelector)[0]);
|
||||
updatePreviewBarPositionMobile(document.getElementsByClassName(mobileYouTubeSelector)[0] as HTMLElement);
|
||||
|
||||
return;
|
||||
} else {
|
||||
@@ -397,7 +402,7 @@ function createPreviewBar(): void {
|
||||
const el = document.querySelectorAll(selector);
|
||||
|
||||
if (el && el.length && el[0]) {
|
||||
previewBar = new PreviewBar(el[0], onMobileYouTube, onInvidious);
|
||||
previewBar = new PreviewBar(el[0] as HTMLElement, onMobileYouTube, onInvidious);
|
||||
|
||||
updatePreviewBar();
|
||||
|
||||
@@ -410,7 +415,7 @@ function createPreviewBar(): void {
|
||||
* Triggered every time the video duration changes.
|
||||
* This happens when the resolution changes or at random time to clear memory.
|
||||
*/
|
||||
function durationChangeListener() {
|
||||
function durationChangeListener(): void {
|
||||
updateAdFlag();
|
||||
updatePreviewBar();
|
||||
}
|
||||
@@ -545,6 +550,12 @@ async function sponsorsLookup(id: string) {
|
||||
video.addEventListener('play', () => {
|
||||
switchingVideos = false;
|
||||
|
||||
// If it is not the first event, then the only way to get to 0 is if there is a seek event
|
||||
// This check makes sure that changing the video resolution doesn't cause the extension to think it
|
||||
// gone back to the begining
|
||||
if (!firstEvent && video.currentTime === 0) return;
|
||||
firstEvent = false;
|
||||
|
||||
// Check if an ad is playing
|
||||
updateAdFlag();
|
||||
|
||||
@@ -578,6 +589,8 @@ async function sponsorsLookup(id: string) {
|
||||
}
|
||||
});
|
||||
video.addEventListener('ratechange', () => startSponsorSchedule());
|
||||
// Used by videospeed extension (https://github.com/igrigorik/videospeed/pull/740)
|
||||
video.addEventListener('videoSpeed_ratechange', () => startSponsorSchedule());
|
||||
video.addEventListener('pause', () => {
|
||||
// Reset lastCheckVideoTime
|
||||
lastCheckVideoTime = -1;
|
||||
@@ -740,7 +753,7 @@ function startSkipScheduleCheckingForStartSponsors() {
|
||||
* Get the video info for the current tab from YouTube
|
||||
*/
|
||||
function getVideoInfo() {
|
||||
sendRequestToCustomServer('GET', "https://www.youtube.com/get_video_info?video_id=" + sponsorVideoID, function(xmlhttp, error) {
|
||||
sendRequestToCustomServer('GET', "https://www.youtube.com/get_video_info?video_id=" + sponsorVideoID, function(xmlhttp) {
|
||||
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
|
||||
const decodedData = decodeURIComponent(xmlhttp.responseText).match(/player_response=([^&]*)/)[1];
|
||||
if (!decodedData) {
|
||||
@@ -798,13 +811,13 @@ function getYouTubeVideoID(url: string) {
|
||||
/**
|
||||
* This function is required on mobile YouTube and will keep getting called whenever the preview bar disapears
|
||||
*/
|
||||
function updatePreviewBarPositionMobile(parent: Element) {
|
||||
function updatePreviewBarPositionMobile(parent: HTMLElement) {
|
||||
if (document.getElementById("previewbar") === null) {
|
||||
previewBar.updatePosition(parent);
|
||||
}
|
||||
}
|
||||
|
||||
function updatePreviewBar() {
|
||||
function updatePreviewBar(): void {
|
||||
if(isAdPlaying) {
|
||||
previewBar.set([], [], 0);
|
||||
return;
|
||||
@@ -1051,7 +1064,7 @@ function createButton(baseID, title, callback, imageName, isDraggable=false): bo
|
||||
newButton.classList.add("playerButton");
|
||||
newButton.classList.add("ytp-button");
|
||||
newButton.setAttribute("title", chrome.i18n.getMessage(title));
|
||||
newButton.addEventListener("click", (event: Event) => {
|
||||
newButton.addEventListener("click", () => {
|
||||
callback();
|
||||
});
|
||||
|
||||
@@ -1435,8 +1448,6 @@ function submitSponsorTimes() {
|
||||
//it can't update to this info yet
|
||||
closeInfoMenu();
|
||||
|
||||
const currentVideoID = sponsorVideoID;
|
||||
|
||||
if (sponsorTimesSubmitting !== undefined && sponsorTimesSubmitting.length > 0) {
|
||||
submissionNotice = new SubmissionNotice(skipNoticeContentContainer, sendSubmitMessage);
|
||||
}
|
||||
@@ -1583,7 +1594,7 @@ function sendRequestToCustomServer(type, fullAddress, callback) {
|
||||
callback(xmlhttp, false);
|
||||
};
|
||||
|
||||
xmlhttp.onerror = function(ev) {
|
||||
xmlhttp.onerror = function() {
|
||||
callback(xmlhttp, true);
|
||||
};
|
||||
}
|
||||
@@ -1595,7 +1606,7 @@ function sendRequestToCustomServer(type, fullAddress, callback) {
|
||||
/**
|
||||
* Update the isAdPlaying flag and hide preview bar/controls if ad is playing
|
||||
*/
|
||||
function updateAdFlag() {
|
||||
function updateAdFlag(): void {
|
||||
const wasAdPlaying = isAdPlaying;
|
||||
isAdPlaying = document.getElementsByClassName('ad-showing').length > 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user