2021-12-10 14:15:38 +00:00
|
|
|
function register ({ registerHook, registerSettingsScript, registerClientRoute, peertubeHelpers }) {
|
2019-07-16 09:53:38 +00:00
|
|
|
registerHook({
|
2019-07-22 12:08:20 +00:00
|
|
|
target: 'action:application.init',
|
|
|
|
handler: () => onApplicationInit(peertubeHelpers)
|
2019-07-16 09:53:38 +00:00
|
|
|
})
|
2019-07-22 13:38:26 +00:00
|
|
|
|
2021-03-26 07:30:43 +00:00
|
|
|
registerHook({
|
|
|
|
target: 'action:auth-user.information-loaded',
|
2021-04-22 09:35:02 +00:00
|
|
|
handler: ({ user }) => {
|
|
|
|
console.log('User information loaded.', user)
|
|
|
|
|
|
|
|
fetch('/api/v1/users/me', {
|
|
|
|
method: 'GET',
|
|
|
|
headers: peertubeHelpers.getAuthHeader()
|
|
|
|
}).then(res => res.json())
|
|
|
|
.then(data => console.log('Hi %s.', data.username))
|
|
|
|
}
|
2021-03-26 07:30:43 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
registerHook({
|
|
|
|
target: 'action:auth-user.logged-in',
|
|
|
|
handler: () => console.log('User logged in.')
|
|
|
|
})
|
|
|
|
|
|
|
|
registerHook({
|
|
|
|
target: 'action:auth-user.logged-out',
|
|
|
|
handler: () => console.log('User logged out.')
|
|
|
|
})
|
|
|
|
|
2019-07-22 13:38:26 +00:00
|
|
|
// Videos list
|
|
|
|
|
|
|
|
registerHook({
|
2019-07-22 14:40:52 +00:00
|
|
|
target: 'filter:api.trending-videos.videos.list.params',
|
2019-07-22 13:38:26 +00:00
|
|
|
handler: params => Object.assign({}, params, { sort: '-views' })
|
|
|
|
})
|
|
|
|
|
|
|
|
registerHook({
|
2019-07-22 14:40:52 +00:00
|
|
|
target: 'filter:api.trending-videos.videos.list.result',
|
2019-07-22 13:38:26 +00:00
|
|
|
handler: result => addSymbolToVideoNameResult(result, '<3')
|
|
|
|
})
|
|
|
|
|
|
|
|
registerHook({
|
2019-07-22 14:40:52 +00:00
|
|
|
target: 'filter:api.local-videos.videos.list.params',
|
2019-07-22 13:38:26 +00:00
|
|
|
handler: params => Object.assign({}, params, { sort: '-views' })
|
|
|
|
})
|
|
|
|
|
|
|
|
registerHook({
|
2019-07-22 14:40:52 +00:00
|
|
|
target: 'filter:api.local-videos.videos.list.result',
|
2019-07-22 13:38:26 +00:00
|
|
|
handler: result => addSymbolToVideoNameResult(result, ':)')
|
|
|
|
})
|
|
|
|
|
|
|
|
registerHook({
|
2019-07-22 14:40:52 +00:00
|
|
|
target: 'filter:api.recently-added-videos.videos.list.params',
|
2019-07-22 13:38:26 +00:00
|
|
|
handler: params => Object.assign({}, params, { filter: 'all-local' })
|
|
|
|
})
|
|
|
|
|
|
|
|
registerHook({
|
2019-07-22 14:40:52 +00:00
|
|
|
target: 'filter:api.recently-added-videos.videos.list.result',
|
2019-07-22 13:38:26 +00:00
|
|
|
handler: result => addSymbolToVideoNameResult(result, 'o/')
|
|
|
|
})
|
|
|
|
|
|
|
|
registerHook({
|
2019-07-22 14:40:52 +00:00
|
|
|
target: 'filter:api.user-subscriptions-videos.videos.list.params',
|
2019-07-22 13:38:26 +00:00
|
|
|
handler: params => Object.assign({}, params, { sort: '-views' })
|
|
|
|
})
|
|
|
|
|
|
|
|
registerHook({
|
2019-07-22 14:40:52 +00:00
|
|
|
target: 'filter:api.user-subscriptions-videos.videos.list.result',
|
2019-07-22 13:38:26 +00:00
|
|
|
handler: result => addSymbolToVideoNameResult(result, ':D')
|
|
|
|
})
|
|
|
|
|
2019-12-05 16:27:20 +00:00
|
|
|
registerHook({
|
|
|
|
target: 'filter:internal.common.svg-icons.get-content.result',
|
|
|
|
handler: (result, params) => {
|
|
|
|
if (params.name === 'syndication') {
|
|
|
|
return '<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"><circle cx="50" cy="50" r="50"/></svg>'
|
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-06-30 14:44:42 +00:00
|
|
|
registerHook({
|
|
|
|
target: 'filter:left-menu.links.create.result',
|
|
|
|
handler: (result) => {
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
key: 'in-my-stuff',
|
|
|
|
title: 'In my stuff',
|
|
|
|
links: [
|
2021-12-10 14:15:38 +00:00
|
|
|
{
|
2021-06-30 14:44:42 +00:00
|
|
|
path: '/about',
|
|
|
|
icon: 'alert',
|
|
|
|
shortLabel: 'About',
|
|
|
|
label: 'About'
|
2021-12-10 14:15:38 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
path: peertubeHelpers.getBasePluginClientPath() + '/my-super/route',
|
|
|
|
icon: '',
|
|
|
|
shortLabel: 'super route',
|
|
|
|
label: 'Super route'
|
2021-06-30 14:44:42 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
].concat(result)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-07-26 07:42:52 +00:00
|
|
|
// Router hooks
|
|
|
|
|
|
|
|
registerHook({
|
|
|
|
target: 'action:router.navigation-end',
|
|
|
|
handler: params => console.log('New URL! %s.', params.path)
|
|
|
|
})
|
|
|
|
|
2021-03-23 10:59:43 +00:00
|
|
|
// Modal hooks
|
|
|
|
|
|
|
|
registerHook({
|
|
|
|
target: 'action:modal.video-download.shown',
|
|
|
|
handler: () => {
|
|
|
|
console.log('Video download modal shown')
|
|
|
|
|
|
|
|
document.getElementById('download-torrent').checked = true
|
|
|
|
document.getElementById('download-direct').parentElement.style.display = 'none'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-07-22 14:40:52 +00:00
|
|
|
// Fake hook
|
2019-07-22 13:38:26 +00:00
|
|
|
|
|
|
|
registerHook({
|
2019-07-22 14:40:52 +00:00
|
|
|
target: 'fakeHook',
|
|
|
|
handler: () => console.log('fake hook')
|
2019-07-22 13:38:26 +00:00
|
|
|
})
|
|
|
|
|
2021-04-09 13:19:32 +00:00
|
|
|
|
|
|
|
// Settings
|
|
|
|
|
|
|
|
registerSettingsScript({
|
|
|
|
isSettingHidden: options => {
|
|
|
|
if (options.setting.name === 'my-markdown-area' && options.formValues.select === '2') {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
})
|
2021-12-10 14:15:38 +00:00
|
|
|
|
|
|
|
// Routes
|
|
|
|
|
|
|
|
registerClientRoute({
|
|
|
|
route: 'my-super/route',
|
|
|
|
onMount: ({ rootEl }) => {
|
|
|
|
rootEl.innerHTML = 'hello'
|
|
|
|
}
|
|
|
|
})
|
2019-07-16 09:53:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export {
|
|
|
|
register
|
|
|
|
}
|
2019-07-16 14:00:11 +00:00
|
|
|
|
2019-07-22 12:08:20 +00:00
|
|
|
function onApplicationInit (peertubeHelpers) {
|
2019-07-16 14:00:11 +00:00
|
|
|
console.log('Hello application world')
|
|
|
|
|
|
|
|
const baseStaticUrl = peertubeHelpers.getBaseStaticRoute()
|
|
|
|
const imageUrl = baseStaticUrl + '/images/chocobo.png'
|
|
|
|
|
|
|
|
const topLeftBlock = document.querySelector('.top-left-block')
|
|
|
|
|
|
|
|
topLeftBlock.style.backgroundImage = 'url(' + imageUrl + ')'
|
2019-07-26 12:45:53 +00:00
|
|
|
|
|
|
|
peertubeHelpers.translate('User name')
|
|
|
|
.then(translation => console.log('Translated User name by ' + translation))
|
2021-03-26 07:30:43 +00:00
|
|
|
|
|
|
|
peertubeHelpers.getServerConfig()
|
|
|
|
.then(config => console.log('Got server config.', config))
|
2019-07-16 14:00:11 +00:00
|
|
|
}
|
2019-07-22 13:38:26 +00:00
|
|
|
|
|
|
|
function addSymbolToVideoNameResult (result, symbol) {
|
|
|
|
result.data.forEach(v => v.name += ' ' + symbol)
|
|
|
|
|
|
|
|
return {
|
|
|
|
data: result.data,
|
|
|
|
total: result.total
|
|
|
|
}
|
|
|
|
}
|