From ba2b7e5bc9c62d80f8ef5da6b5aab934a668c8c1 Mon Sep 17 00:00:00 2001 From: ThatOneCalculator Date: Mon, 3 Jul 2023 01:24:34 -0700 Subject: [PATCH] approx height calculation from note menu --- packages/backend/assets/embed.js | 88 ------------------- .../client/src/components/MkEmbedDialog.vue | 7 +- packages/client/src/os.ts | 6 +- packages/client/src/pages/note.embed.vue | 13 +-- packages/client/src/scripts/get-note-menu.ts | 10 ++- 5 files changed, 20 insertions(+), 104 deletions(-) delete mode 100644 packages/backend/assets/embed.js diff --git a/packages/backend/assets/embed.js b/packages/backend/assets/embed.js deleted file mode 100644 index 550ff9bf7c..0000000000 --- a/packages/backend/assets/embed.js +++ /dev/null @@ -1,88 +0,0 @@ -// @ts-check - -/** - * This embed script is from Mastodon. Thank you, website boy! :) - * - * License: AGPLv3, Mastodon gGmbH - * Original source: https://github.com/mastodon/mastodon/blob/main/public/embed.js - * Current source: https://codeberg.org/calckey/calckey/src/branch/develop/packages/backend/assets/embed.js - * From: Eugen Rochko - * Co-authored-by: Rohan Sharma - * Co-authored-by: rinsuki <428rinsuki+git@gmail.com> - * Co-authored-by: Matt Hodges - * Co-authored-by: Claire - * Co-authored-by: Kainoa Kanter -*/ - -(function () { - 'use strict'; - - /** - * @param {() => void} loaded - */ - const ready = function (loaded) { - if (document.readyState === 'complete') { - loaded(); - } else { - document.addEventListener('readystatechange', function () { - if (document.readyState === 'complete') { - loaded(); - } - }); - } - }; - - ready(function () { - /** @type {Map} */ - const iframes = new Map(); - - window.addEventListener('message', function (e) { - const data = e.data || {}; - - if (typeof data !== 'object' || data.type !== 'setHeight' || !iframes.has(data.id)) { - return; - } - - const iframe = iframes.get(data.id); - - if (iframe != null) { - if ('source' in e && iframe.contentWindow !== e.source) { - return; - } - - iframe.height = data.height; - } - - }); - - [].forEach.call(document.querySelectorAll('iframe.embed'), function (iframe) { - // select unique id for each iframe - let id = 0; - let failCount = 0; - const idBuffer = new Uint32Array(1); - while (id === 0 || iframes.has(id)) { - id = crypto.getRandomValues(idBuffer)[0]; - failCount++; - if (failCount > 100) { - // give up and assign (easily guessable) unique number if getRandomValues is broken or no luck - id = -(iframes.size + 1); - break; - } - } - - iframes.set(id, iframe); - - iframe.scrolling = 'no'; - iframe.style.overflow = 'hidden'; - - iframe.onload = function () { - iframe.contentWindow.postMessage({ - type: 'setHeight', - id: id, - }, '*'); - }; - - iframe.onload(); - }); - }); -})(); diff --git a/packages/client/src/components/MkEmbedDialog.vue b/packages/client/src/components/MkEmbedDialog.vue index 0fe596babc..540454b80f 100644 --- a/packages/client/src/components/MkEmbedDialog.vue +++ b/packages/client/src/components/MkEmbedDialog.vue @@ -42,13 +42,16 @@ const modal = shallowRef>(); const props = withDefaults( defineProps<{ id: string; + title?: string; + height?: number; }>(), { - id: "No ID provided!", + title: "Calckey", + height: 600, } ); -const codeblock = ``; +const codeblock = `;`