From 560d63a20a0d299674118aa51cfaabaf8ed4ac5b Mon Sep 17 00:00:00 2001 From: John Livingston Date: Fri, 19 Feb 2021 15:19:20 +0100 Subject: [PATCH] Work in progress. --- assets/style.css | 1 + client/videowatch-client-plugin.js | 17 ++++++++++++++++- main.js | 3 ++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/assets/style.css b/assets/style.css index 84d62abb..5b052a1c 100644 --- a/assets/style.css +++ b/assets/style.css @@ -1,4 +1,5 @@ iframe.peertube-plugin-livechat { + border: 1px solid black; width: 100%; height: 300px; resize: vertical; diff --git a/client/videowatch-client-plugin.js b/client/videowatch-client-plugin.js index 1054888d..b4d1a319 100644 --- a/client/videowatch-client-plugin.js +++ b/client/videowatch-client-plugin.js @@ -1,3 +1,16 @@ +function parseUUIDs (s) { + if (!s) { + return [] + } + let a = s.split('\n') + a = a.map(line => { + return line.replace(/#.*$/, '') + .replace(/^\s+/, '') + .replace(/\s+$/, '') + }) + return a.filter(line => line !== '') +} + function register ({ registerHook, peertubeHelpers }) { registerHook({ target: 'action:video-watch.player.loaded', @@ -5,7 +18,7 @@ function register ({ registerHook, peertubeHelpers }) { peertubeHelpers.getSettings().then(s => { const liveOn = !!s['chat-all-lives'] const nonLiveOn = !!s['chat-all-non-lives'] - const uuids = s['chat-videos-list'] ? s['chat-videos-list'].split('\n') : [] + const uuids = parseUUIDs(s['chat-videos-list']) const iframeUri = s['chat-uri'] || '' if ( iframeUri === '' ) { console.log('[peertube-plugin-livechat] no uri, can\'t add chat.') @@ -38,6 +51,8 @@ function register ({ registerHook, peertubeHelpers }) { const iframe = document.createElement('iframe') iframe.setAttribute('src', chatUrl) iframe.setAttribute('class', 'peertube-plugin-livechat') + iframe.setAttribute('sandbox', 'allow-same-origin allow-scripts allow-popups') + iframe.setAttribute('frameborder', '0') parent.prepend(iframe) }) } diff --git a/main.js b/main.js index 10cbe175..24bd33eb 100644 --- a/main.js +++ b/main.js @@ -29,7 +29,8 @@ async function register ({ type: 'input-textarea', default: '', descriptionHTML: 'Videos UUIDs for which we want a chat. ' + - 'Can be non-live videos. One per line. ' + + 'Can be non-live videos. One per line.
' + + 'You can add comments: everything after the # character will be stripped off, and empty lines ignored.
' + 'Don\'t add private videos, the UUIDs will be send to frontend.', private: false })