peertubeify-estensione-fire.../youtube.js

47 lines
1.6 KiB
JavaScript

/* This file is part of PeerTubeify.
*
* PeerTubeify is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PeerTubeify is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerTubeify. If not, see <https://www.gnu.org/licenses/>.
*/
const watchURL = (host, uuid) => `https://${host}/videos/watch/${uuid}`;
const thumbnailURL = (host, path) => `https://${host}${path}`;
const title = document.title.slice(0, document.title.lastIndexOf(' -'));
if (title) {
browser.runtime.sendMessage({
query: title,
}).then(video => {
document.querySelector('.title').insertAdjacentElement('afterend', videoLink(video));
});
}
function htmlToElement(html) {
const template = document.createElement('template');
template.innerHTML = html.trim();
return template.content.firstChild;
}
function videoLink(video) {
const url = watchURL(video.account.host, video.uuid);
return htmlToElement(`
<a style="display: flex; align-items: center; margin: 2rem 0;" href=${url}>
<img src="${thumbnailURL(video.account.host, video.thumbnailPath)}">
<p style="font-size: 18px; margin-left: 1rem; color: var(--ytd-video-primary-info-renderer-title-color, var(--yt-primary-text-color));">
${video.account.host}
</p>:
</a>
`);
}