Bluesky embed

Embed bluesky posts on the blue websight

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Bluesky embed
// @namespace    http://tampermonkey.net/
// @version      2024-11-19
// @description  Embed bluesky posts on the blue websight
// @author       Milan
// @match        https://*.websight.blue/thread/*
// @license      MIT
// @icon         https://lore.capital/static/blueshi.png
// @connect      embed.bsky.app
// @grant        GM_xmlhttpRequest
// ==/UserScript==


const EMBED_URL = 'https://embed.bsky.app';

function scan(node) {
    if (node === void 0) { node = document; }
    const embeds = node.querySelectorAll('[data-bluesky-uri]');
    for (let i = 0; i < embeds.length; i++) {
        const id = String(Math.random()).slice(2);
        const embed = embeds[i];
        const aturi = embed.getAttribute('data-bluesky-uri');
        if (!aturi) {
            continue;
        }
        const ref_url = location.origin + location.pathname;
        const searchParams = new URLSearchParams();
        searchParams.set('id', id);
        if (ref_url.startsWith('http')) {
            searchParams.set('ref_url', encodeURIComponent(ref_url));
        }
        const iframe = document.createElement('iframe');
        iframe.setAttribute('data-bluesky-id', id);
        iframe.src = "".concat(EMBED_URL, "/embed/").concat(aturi.slice('at://'.length), "?").concat(searchParams.toString());
        iframe.width = '100%';
        iframe.style.border = 'none';
        iframe.style.display = 'block';
        iframe.style.flexGrow = '1';
        iframe.frameBorder = '0';
        iframe.scrolling = 'no';
        const container = document.createElement('div');
        container.style.maxWidth = '600px';
        container.style.width = '100%';
        container.style.marginTop = '10px';
        container.style.marginBottom = '10px';
        container.style.display = 'flex';
        container.className = 'bluesky-embed';
        container.appendChild(iframe);
        embed.replaceWith(container);
    }
}

(function() {
    'use strict';

    window.bluesky = window.bluesky || {
        scan: scan,
    };

    window.addEventListener('message', function (event) {
        if (event.origin !== EMBED_URL) {
            return;
        }
        var id = event.data.id;
        if (!id) {
            return;
        }
        var embed = document.querySelector("[data-bluesky-id=\"".concat(id, "\"]"));
        if (!embed) {
            return;
        }
        var height = event.data.height;
        if (height) {
            embed.style.height = "".concat(height, "px");
        }
    });

    const node_list = document.querySelectorAll(".message a[href^='https:\/\/bsky']");
    Array.from(node_list).forEach(link => {
        const oembed_url = "https://embed.bsky.app/oembed?mode=dark&url=";
        GM_xmlhttpRequest({
            method: "GET",
            url: oembed_url + link.href,
            headers: {
                "Content-Type": "application/json"
            },
            onload: function(response) {
                const embed = JSON.parse(response.responseText).html;
                link.parentElement.innerHTML += embed;
                scan();
            }
        });
    });

})();