From 68996809f0885d45a6a8417c1c51b03f9f225a59 Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Sat, 30 Oct 2021 12:05:03 +0300 Subject: [PATCH 1/6] add apiLoaded event to disable-autoplay plugin --- plugins/disable-autoplay/front.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/plugins/disable-autoplay/front.js b/plugins/disable-autoplay/front.js index eb1b72db9e..49a32a60f0 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', e => { + document.querySelector('video').addEventListener('loadeddata', e => { + e.target.pause(); + }) + }) }; From 62e8e673ebdd1b358a91d9e67c9e13e25f1d18e4 Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Sat, 30 Oct 2021 12:17:32 +0300 Subject: [PATCH 2/6] use apiLoaded 'once' --- plugins/disable-autoplay/front.js | 2 +- plugins/precise-volume/front.js | 2 +- plugins/quality-changer/front.js | 2 +- providers/song-info-front.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/disable-autoplay/front.js b/plugins/disable-autoplay/front.js index 49a32a60f0..70a9b86757 100644 --- a/plugins/disable-autoplay/front.js +++ b/plugins/disable-autoplay/front.js @@ -3,5 +3,5 @@ module.exports = () => { 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..e50620fff1 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..d0417493ae 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/providers/song-info-front.js b/providers/song-info-front.js index 80c2e99026..d134433b5c 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}) }; From 286bc0113e51bffd442a7ad326a79f4895b0e629 Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Sat, 30 Oct 2021 12:43:51 +0300 Subject: [PATCH 3/6] fix sponsorblock plugin --- plugins/disable-autoplay/front.js | 2 +- plugins/sponsorblock/back.js | 15 ++++++++++++++- plugins/sponsorblock/front.js | 28 ++++++++++++++-------------- providers/video-element.js | 22 ---------------------- 4 files changed, 29 insertions(+), 38 deletions(-) delete mode 100644 providers/video-element.js diff --git a/plugins/disable-autoplay/front.js b/plugins/disable-autoplay/front.js index 70a9b86757..c532d0db4c 100644 --- a/plugins/disable-autoplay/front.js +++ b/plugins/disable-autoplay/front.js @@ -1,5 +1,5 @@ module.exports = () => { - document.addEventListener('apiLoaded', e => { + document.addEventListener('apiLoaded', () => { document.querySelector('video').addEventListener('loadeddata', e => { e.target.pause(); }) diff --git a/plugins/sponsorblock/back.js b/plugins/sponsorblock/back.js index 3c7eb5b4e8..775b1c0a6f 100644 --- a/plugins/sponsorblock/back.js +++ b/plugins/sponsorblock/back.js @@ -1,4 +1,12 @@ const fetch = require("node-fetch"); +const is = require("electron-is"); + +// see https://github.com/node-fetch/node-fetch/issues/568#issuecomment-932200523 +// will not be needed if project's electron version >= v15.1.0 (https://github.com/node-fetch/node-fetch/issues/568#issuecomment-932435180) +const https = require("https"); +const agent = new https.Agent({ + rejectUnauthorized: false, +}); const defaultConfig = require("../../config/defaults"); const registerCallback = require("../../providers/song-info"); @@ -24,6 +32,7 @@ module.exports = (win, options) => { }); }; + const fetchSegments = async (apiURL, categories) => { const sponsorBlockURL = `${apiURL}/api/skipSegments?videoID=${videoID}&categories=${JSON.stringify( categories @@ -35,6 +44,7 @@ const fetchSegments = async (apiURL, categories) => { "Content-Type": "application/json", }, redirect: "follow", + agent // fixes error: 'CERT_HAS_EXPIRED' }); if (resp.status !== 200) { return []; @@ -45,7 +55,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..7ae2aa43a2 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/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); - } -}; From 762566cce67fd9616b281508cb34f6dfb45741e2 Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Sat, 30 Oct 2021 12:52:04 +0300 Subject: [PATCH 4/6] lint --- plugins/disable-autoplay/front.js | 2 +- plugins/precise-volume/front.js | 2 +- plugins/quality-changer/front.js | 2 +- plugins/sponsorblock/front.js | 2 +- providers/song-info-front.js | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/disable-autoplay/front.js b/plugins/disable-autoplay/front.js index c532d0db4c..532405de25 100644 --- a/plugins/disable-autoplay/front.js +++ b/plugins/disable-autoplay/front.js @@ -3,5 +3,5 @@ module.exports = () => { document.querySelector('video').addEventListener('loadeddata', e => { e.target.pause(); }) - }, { once: true, passive: true}) + }, { once: true, passive: true }) }; diff --git a/plugins/precise-volume/front.js b/plugins/precise-volume/front.js index e50620fff1..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}) + }, { 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 d0417493ae..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, { once: true, passive: true}); + document.addEventListener('apiLoaded', setup, { once: true, passive: true }); } function setup(event) { diff --git a/plugins/sponsorblock/front.js b/plugins/sponsorblock/front.js index 7ae2aa43a2..6f4048ad15 100644 --- a/plugins/sponsorblock/front.js +++ b/plugins/sponsorblock/front.js @@ -23,5 +23,5 @@ module.exports = () => { } }); }) - }, { once: true, passive: true}) + }, { once: true, passive: true }) }; diff --git a/providers/song-info-front.js b/providers/song-info-front.js index d134433b5c..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}) + }, { once: true, passive: true }) }; From bca22d8e2427a20a1ed0139f0bbe092b1cf554c6 Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Sat, 30 Oct 2021 13:17:47 +0300 Subject: [PATCH 5/6] update electron to v12.2.2 fixes fetch CERT_HAS_EXPIRED error --- package.json | 2 +- plugins/sponsorblock/back.js | 8 -------- yarn.lock | 8 ++++---- 3 files changed, 5 insertions(+), 13 deletions(-) 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/sponsorblock/back.js b/plugins/sponsorblock/back.js index 775b1c0a6f..0f16f1023f 100644 --- a/plugins/sponsorblock/back.js +++ b/plugins/sponsorblock/back.js @@ -1,13 +1,6 @@ const fetch = require("node-fetch"); const is = require("electron-is"); -// see https://github.com/node-fetch/node-fetch/issues/568#issuecomment-932200523 -// will not be needed if project's electron version >= v15.1.0 (https://github.com/node-fetch/node-fetch/issues/568#issuecomment-932435180) -const https = require("https"); -const agent = new https.Agent({ - rejectUnauthorized: false, -}); - const defaultConfig = require("../../config/defaults"); const registerCallback = require("../../providers/song-info"); const { sortSegments } = require("./segments"); @@ -44,7 +37,6 @@ const fetchSegments = async (apiURL, categories) => { "Content-Type": "application/json", }, redirect: "follow", - agent // fixes error: 'CERT_HAS_EXPIRED' }); if (resp.status !== 200) { return []; 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" From d35fef82feb81f305401b7d215504d8110775616 Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Sat, 30 Oct 2021 13:30:38 +0300 Subject: [PATCH 6/6] fix sponsoblock spam updating time --- plugins/sponsorblock/front.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/sponsorblock/front.js b/plugins/sponsorblock/front.js index 6f4048ad15..45d739b2ef 100644 --- a/plugins/sponsorblock/front.js +++ b/plugins/sponsorblock/front.js @@ -14,7 +14,7 @@ module.exports = () => { currentSegments.forEach((segment) => { if ( e.target.currentTime >= segment[0] && - e.target.currentTime <= segment[1] + e.target.currentTime < segment[1] ) { e.target.currentTime = segment[1]; if (is.dev()) {