User JS

From Soyjak Wiki, The Free Soycyclopedia
Revision as of 17:25, 26 May 2021 by Soyward (talk | contribs) (Created page with "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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

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;

});

})();