From 25a0304fd398552c510cb7e175c496e3c699fff0 Mon Sep 17 00:00:00 2001 From: Zankaria Date: Sun, 9 Feb 2025 00:45:49 +0100 Subject: [PATCH 1/3] style.css: incorporate 3rd party embeds css --- stylesheets/style.css | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/stylesheets/style.css b/stylesheets/style.css index 815e1853..26b5cb75 100644 --- a/stylesheets/style.css +++ b/stylesheets/style.css @@ -2081,3 +2081,24 @@ span.orangeQuote { float: right; margin: 0em 1em; } + +/* Included embeds */ + +.tiktok-embed { + float: left; + margin: 0.6em 1em 0.2em 0.2em; + border-radius: 8px; + overflow: hidden; + max-width: min-content; + min-width: 325px; +} + +.tiktok-embed > iframe { + display: block; + visibility: unset; + border: none; + overflow: hidden; + width: 325px; + height: 739px; + max-height: 739px; +} From 91e54fb6bfabc9659f5fe63392a7407234c6db42 Mon Sep 17 00:00:00 2001 From: Zankaria Date: Sun, 9 Feb 2025 00:45:31 +0100 Subject: [PATCH 2/3] config.php: add tiktok video embed --- inc/config.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/inc/config.php b/inc/config.php index 25031bfb..e324fcf1 100644 --- a/inc/config.php +++ b/inc/config.php @@ -1231,6 +1231,12 @@ ' ], + [ + '/^https?:\/\/(\w+\.)?tiktok\.com\/@[a-z0-9\-_]+\/video\/([0-9]+)\?.*$/i', + '
+ +
' + ], array( '/^https?:\/\/(\w+\.)?vimeo\.com\/(\d{2,10})(\?.+)?$/i', '' From d72cd82257d906655d673ccd08990df13602f2c0 Mon Sep 17 00:00:00 2001 From: Zankaria Date: Sun, 16 Mar 2025 22:12:04 +0100 Subject: [PATCH 3/3] tiktok.js: add tiktok embed client integration --- js/tiktok.js | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 js/tiktok.js diff --git a/js/tiktok.js b/js/tiktok.js new file mode 100644 index 00000000..f8f88746 --- /dev/null +++ b/js/tiktok.js @@ -0,0 +1,80 @@ +/* + * Don't load the 3rd party embedded content player unless the image is clicked. + * This increases performance issues when many videos are embedded on the same page and privacy. + * + * Released under the MIT license + * Copyright (c) 2013 Michael Save + * Copyright (c) 2013-2014 Marcin Ɓabanowski + * Copyright (c) 2025 Zankaria Auxa + * + * Usage: + * $config['embedding'][0] = figure it out plz; + * $config['additional_javascript'][] = 'js/tiktok.js'; + */ + +onReady(function() { + const REMOVE = '[Remove]'; + const EMBED = '[Embed]'; + + function makeEmbedNode(videoId, width, height) { + const iframe = document.createElement('iframe'); + iframe.setAttribute('type', 'text/html'); + iframe.width = width; + iframe.height = height; + iframe.referrerPolicy = 'no-referrer'; + iframe.src = `https://www.tiktok.com/embed/v2/${videoId}`; + iframe.sandbox.add('allow-popups', 'allow-popups-to-escape-sandbox', 'allow-scripts', 'allow-top-navigation', 'allow-same-origin') + iframe.classList.add('full-image'); + return iframe; + } + + function addEmbedButton(node) { + const contents = node.firstElementChild; + const embedUrl = node.dataset.videoId; + const embedWidth = node.dataset.iframeWidth; + const embedHeight = node.dataset.iframeHeight; + + const span = document.createElement('span'); + span.textContent = EMBED; + + let iframeDefault = null; + + node.addEventListener('click', function(e) { + e.preventDefault(); + + if (span.textContent == REMOVE) { + contents.style.display = ''; + + if (iframeDefault !== null) { + iframeDefault.remove(); + } + + span.textContent = EMBED; + } else { + if (iframeDefault === null) { + iframeDefault = makeEmbedNode(embedUrl, embedWidth, embedHeight); + } + node.insertBefore(iframeDefault, node.firstElementChild); + + contents.style.display = 'none'; + span.text(REMOVE); + } + }); + + node.appendChild(span); + } + + const embeds = document.getElementsByClassName('tiktok-embed'); + for (let i = 0; i < embeds.length; i++) { + addEmbedButton(embeds[i]); + } + + // Allow to work with auto-reload.js, etc. + document.addEventListener('new_post', function(e)) { + const post = e.detail; + const embeds = post.getElementsByClassName('tiktok-embed'); + for (let i = 0; i < embeds.length; i++) { + addEmbedButton(embeds[i]); + } + } +});