User JS
From Soyjak Wiki, The Free Soycyclopedia
On soyjak.party users can add custom javascript under Options->User JS in the top right of the page to customize their browsing experience.
Code Snippets
Preview for Youtube Videos
Show preview for youtube video links.
(function youtubeInlinePreviews() {
const re = /(?:youtube\.com\/watch\?v=|youtu\.be\/)(.{11})/;
const previewTemplate = (videoId) => `<img
style="max-width:255px;max-height:255px"
src="https://i.ytimg.com/vi/${videoId}/hqdefault.jpg"
/>`;
Array.from(document.querySelectorAll(".body a"))
.filter((link) => link.href.match(re))
.forEach((link) => {
const videoId = link.href.match(re)[1];
const inlinePreview = previewTemplate(videoId);
link.innerHTML = inlinePreview;
});
})();