Merge pull request #463 from Araxeus/use-apiLoaded-event-for-time-update

Sponsorblock fix + use new apiLoaded event
This commit is contained in:
th-ch
2021-11-01 12:03:47 +01:00
committed by GitHub
9 changed files with 33 additions and 53 deletions

View File

@ -88,7 +88,7 @@
"ytpl": "^2.2.3"
},
"devDependencies": {
"electron": "^12.1.0",
"electron": "^12.2.2",
"electron-builder": "^22.10.5",
"electron-devtools-installer": "^3.1.1",
"electron-icon-maker": "0.0.5",

View File

@ -1,10 +1,7 @@
const { ontimeupdate } = require("../../providers/video-element");
module.exports = () => {
ontimeupdate((videoElement) => {
if (videoElement.currentTime === 0 && videoElement.duration !== NaN) {
// auto-confirm-when-paused plugin can interfere here if not disabled!
videoElement.pause();
}
});
document.addEventListener('apiLoaded', () => {
document.querySelector('video').addEventListener('loadeddata', e => {
e.target.pause();
})
}, { once: true, passive: true })
};

View File

@ -9,7 +9,7 @@ module.exports = (options) => {
document.addEventListener('apiLoaded', e => {
api = e.detail;
firstRun(options);
})
}, { once: true, passive: true })
};
/** Restore saved volume and setup tooltip */

View File

@ -9,7 +9,7 @@ const qualitySettingsButton = ElementFromFile(
module.exports = () => {
document.addEventListener('apiLoaded', setup);
document.addEventListener('apiLoaded', setup, { once: true, passive: true });
}
function setup(event) {

View File

@ -1,4 +1,5 @@
const fetch = require("node-fetch");
const is = require("electron-is");
const defaultConfig = require("../../config/defaults");
const registerCallback = require("../../providers/song-info");
@ -24,6 +25,7 @@ module.exports = (win, options) => {
});
};
const fetchSegments = async (apiURL, categories) => {
const sponsorBlockURL = `${apiURL}/api/skipSegments?videoID=${videoID}&categories=${JSON.stringify(
categories
@ -45,7 +47,10 @@ const fetchSegments = async (apiURL, categories) => {
);
return sortedSegments;
} catch {
} catch (e) {
if (is.dev()) {
console.log('error on sponsorblock request:', e);
}
return [];
}
};

View File

@ -2,8 +2,6 @@ const { ipcRenderer } = require("electron");
const is = require("electron-is");
const { ontimeupdate } = require("../../providers/video-element");
let currentSegments = [];
module.exports = () => {
@ -11,17 +9,19 @@ module.exports = () => {
currentSegments = segments;
});
ontimeupdate((videoElement) => {
currentSegments.forEach((segment) => {
if (
videoElement.currentTime >= segment[0] &&
videoElement.currentTime <= segment[1]
) {
videoElement.currentTime = segment[1];
if (is.dev()) {
console.log("SponsorBlock: skipping segment", segment);
document.addEventListener('apiLoaded', () => {
document.querySelector('video').addEventListener('timeupdate', e => {
currentSegments.forEach((segment) => {
if (
e.target.currentTime >= segment[0] &&
e.target.currentTime < segment[1]
) {
e.target.currentTime = segment[1];
if (is.dev()) {
console.log("SponsorBlock: skipping segment", segment);
}
}
}
});
});
});
})
}, { once: true, passive: true })
};

View File

@ -15,5 +15,5 @@ module.exports = () => {
const data = e.detail.getPlayerResponse();
ipcRenderer.send("song-info-request", JSON.stringify(data));
});
})
}, { once: true, passive: true })
};

View File

@ -1,22 +0,0 @@
let videoElement = null;
module.exports.ontimeupdate = (cb) => {
const observer = new MutationObserver((mutations, observer) => {
if (!videoElement) {
videoElement = document.querySelector("video");
if (videoElement) {
observer.disconnect();
videoElement.ontimeupdate = () => cb(videoElement);
}
}
});
if (!videoElement) {
observer.observe(document, {
childList: true,
subtree: true,
});
} else {
videoElement.ontimeupdate = () => cb(videoElement);
}
};

View File

@ -3412,10 +3412,10 @@ electron-updater@^4.4.6:
lodash.isequal "^4.5.0"
semver "^7.3.5"
electron@^12.1.0:
version "12.1.0"
resolved "https://registry.yarnpkg.com/electron/-/electron-12.1.0.tgz#615a7f9dbb2fc79cc72361fba9f39d005c697bca"
integrity sha512-joQlYI/nTIrTUldO3GENZ2j225eKar9nTQBSEwSUSWN4h65QGDmXNQ7dbWPmLlkUQWtHhz8lXhFk30OLG9ZjLw==
electron@^12.2.2:
version "12.2.2"
resolved "https://registry.yarnpkg.com/electron/-/electron-12.2.2.tgz#9627594d6b5bb589f00355989d316b6542539e54"
integrity sha512-Oma/nIfvgql9JjAxdB9gQk//qxpJaI6PgMocYMiW4kFyLi+8jS6oGn33QG3FESS//cw09KRnWmA9iutuFAuXtw==
dependencies:
"@electron/get" "^1.0.1"
"@types/node" "^14.6.2"