141 lines
3.6 KiB
JavaScript
Raw Normal View History

2019-07-16 11:53:38 +02:00
function register ({ registerHook, peertubeHelpers }) {
registerHook({
2019-07-22 14:08:20 +02:00
target: 'action:video-watch.init',
2019-07-16 11:53:38 +02:00
handler: () => console.log('Hello video watch world')
})
2019-07-22 15:38:26 +02:00
registerHook({
target: 'action:video-watch.video.loaded',
2021-04-09 15:19:32 +02:00
handler: ({ videojs, video, playlist }) => {
if (playlist) {
console.log('playlist loaded')
} else {
console.log('video loaded')
}
2021-05-31 17:26:13 +02:00
// Insert element next to the player
{
const elem = document.createElement('div')
elem.className = 'hello-world-h4'
elem.innerHTML = '<h4>Hello everybody! This is an element next to the player</h4>'
elem.style = 'background-color: red; '
document.getElementById('plugin-placeholder-player-next').appendChild(elem)
}
2021-04-09 15:19:32 +02:00
}
2019-07-22 15:38:26 +02:00
})
registerHook({
target: 'filter:api.video-watch.video.get.result',
handler: video => {
video.name += ' \o/'
return video
}
})
registerHook({
target: 'filter:api.video-watch.video-threads.list.result',
handler: result => {
2019-07-22 16:40:52 +02:00
result.data.forEach(c => c.text += ' THREAD')
2019-07-22 15:38:26 +02:00
return result
}
})
registerHook({
target: 'filter:api.video-watch.video-thread-replies.list.result',
handler: result => {
result.children.forEach(c => c.comment.text += ' REPLY DEEP 1')
return result
}
})
registerHook({
target: 'filter:internal.video-watch.player.build-options.result',
handler: (result, params) => {
console.log('Running player build options hook for video %s.', params.video.name)
result.playerOptions.common.inactivityTimeout = 10000
return result
}
})
2020-04-15 16:13:04 +02:00
2021-06-30 16:44:42 +02:00
registerHook({
target: 'filter:internal.player.videojs.options.result',
handler: (options) => {
2022-10-11 11:25:37 +02:00
console.log(options.plugins.p2pMediaLoader)
2021-06-30 16:44:42 +02:00
options.poster = ''
return options
}
})
2022-08-03 10:39:31 +02:00
registerHook({
target: 'action:video-watch.video-threads.loaded',
handler: () => {
console.log('Comments found.', document.querySelectorAll('.comment'));
}
})
2021-12-10 15:15:38 +01:00
for (const hook of [
'filter:api.video-watch.video-playlist-elements.get.result'
]) {
registerHook({
target: hook,
handler: (result) => {
console.log('Running hook %s', hook, result)
return result
}
})
}
2022-08-11 15:28:00 +02:00
// ---------------------------------------------------------------------------
// Share modal
// ---------------------------------------------------------------------------
for (const hook of [
'filter:share.video-embed-code.build.result',
'filter:share.video-playlist-embed-code.build.result',
'filter:share.video-embed-url.build.result',
'filter:share.video-playlist-embed-url.build.result',
'filter:share.video-url.build.result',
'filter:share.video-playlist-url.build.result',
]) {
registerHook({
target: hook,
handler: (result) => {
return result + hook
}
})
}
registerHook({
target: 'action:modal.share.shown',
handler: ({ video, playlist }) => {
if (video) {
const elem = document.createElement('div')
elem.innerHTML = 'video ' + video.name
document.getElementById('plugin-placeholder-share-modal-video-settings').appendChild(elem)
}
if (playlist) {
const elem = document.createElement('div')
elem.innerHTML = 'playlist ' + playlist.displayName
document.getElementById('plugin-placeholder-share-modal-playlist-settings').appendChild(elem)
}
}
})
// ---------------------------------------------------------------------------
2020-04-15 16:13:04 +02:00
peertubeHelpers.notifier.info('you are on the watch page', 'useless', 1000)
2019-07-16 11:53:38 +02:00
}
export {
register
}