From 208e39ebd42152b23b94ee5ce79c662ced077b02 Mon Sep 17 00:00:00 2001 From: Ealhad Date: Fri, 23 Nov 2018 08:53:55 +0100 Subject: [PATCH] Fix bugs deleting all saved time entries use ResumeManager class MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The first one is a stupid mistake due to the fact I was only testing with one video at a time, so I didn't notice that the first item of the list was getting deleted if the entry wasn't found. The second one: I didn't like the `setInterval`, because I couldn't stop it, but I didn't think of another solution first. Now the function calls itself with a `setTimeout`, only when it knows the video hasn't ended yet — no infinite calls anymore. And each time we get a new video, we `runResume()`, whith the ResumeManager class handling the preferences. This code can clearly be improved, but bug's fixed. --- extension/manifest.json | 2 +- package.json | 2 +- src/peertube.ts | 39 ++++++++++++++++++++---------------- src/resume.ts | 44 ++++++++++++++++++++++++++++++++--------- 4 files changed, 59 insertions(+), 28 deletions(-) diff --git a/extension/manifest.json b/extension/manifest.json index d5d8cfe..565c4c6 100644 --- a/extension/manifest.json +++ b/extension/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "PeerTubeify", - "version": "0.5.1", + "version": "0.5.1.1", "description": "On YouTube, displays a link to the same video on PeerTube, if it exists.", "homepage_url": "https://gitlab.com/Ealhad/peertubeify", "icons": { diff --git a/package.json b/package.json index 97b19ea..99de3f8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "peertubeify", - "version": "0.5.1", + "version": "0.5.1a", "description": "PeerTubeify is a browser extension to help discovering which YouTube videos are also available on PeerTube.", "main": "webpack.config.js", "dependencies": {}, diff --git a/src/peertube.ts b/src/peertube.ts index 726bd2f..b525579 100644 --- a/src/peertube.ts +++ b/src/peertube.ts @@ -19,7 +19,7 @@ import * as browser from 'webextension-polyfill'; import { htmlToElement, getPeertubeVideoURL } from './util'; import { MessageKind, RedirectType } from './types'; -import { runResume } from './resume'; +import { ResumeManager } from './resume'; import Preferences from './preferences'; const thumbnailURL = (host, path) => `https://${host}${path}`; @@ -60,22 +60,6 @@ async function peertubeify() { } } -const throttledPeertubeify = _.throttle(1000, peertubeify); -const observer = new MutationObserver(function(mutationsList) { - for (const mutation of mutationsList) { - if ((mutation.target as Element).id == 'video-element-wrapper') { - throttledPeertubeify(); - runResume(); - } - } -}); -runResume(); - -observer.observe(document.body, { - childList: true, - subtree: true, -}) - const videoLink = (url, video) => htmlToElement(`