diff --git a/package.json b/package.json index 62e33218c5..0a43726a62 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/plugins/disable-autoplay/front.js b/plugins/disable-autoplay/front.js index eb1b72db9e..532405de25 100644 --- a/plugins/disable-autoplay/front.js +++ b/plugins/disable-autoplay/front.js @@ -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 }) }; diff --git a/plugins/precise-volume/front.js b/plugins/precise-volume/front.js index 84241fb893..4bb606cd12 100644 --- a/plugins/precise-volume/front.js +++ b/plugins/precise-volume/front.js @@ -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 */ diff --git a/plugins/quality-changer/front.js b/plugins/quality-changer/front.js index d167776c50..9972c97fa5 100644 --- a/plugins/quality-changer/front.js +++ b/plugins/quality-changer/front.js @@ -9,7 +9,7 @@ const qualitySettingsButton = ElementFromFile( module.exports = () => { - document.addEventListener('apiLoaded', setup); + document.addEventListener('apiLoaded', setup, { once: true, passive: true }); } function setup(event) { diff --git a/plugins/sponsorblock/back.js b/plugins/sponsorblock/back.js index 3c7eb5b4e8..0f16f1023f 100644 --- a/plugins/sponsorblock/back.js +++ b/plugins/sponsorblock/back.js @@ -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 []; } }; diff --git a/plugins/sponsorblock/front.js b/plugins/sponsorblock/front.js index 4f248bfa9f..45d739b2ef 100644 --- a/plugins/sponsorblock/front.js +++ b/plugins/sponsorblock/front.js @@ -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 }) }; diff --git a/providers/song-info-front.js b/providers/song-info-front.js index 80c2e99026..31748cd3e5 100644 --- a/providers/song-info-front.js +++ b/providers/song-info-front.js @@ -15,5 +15,5 @@ module.exports = () => { const data = e.detail.getPlayerResponse(); ipcRenderer.send("song-info-request", JSON.stringify(data)); }); - }) + }, { once: true, passive: true }) }; diff --git a/providers/video-element.js b/providers/video-element.js deleted file mode 100644 index 7be61c8996..0000000000 --- a/providers/video-element.js +++ /dev/null @@ -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); - } -}; diff --git a/yarn.lock b/yarn.lock index 2a52e14e44..33cca1d930 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"