Upgrade xenforo media addon for mastodon support.

bnew

Veteran
Joined
Nov 1, 2015
Messages
42,966
Reputation
7,267
Daps
131,556
more people are joining Mastodon instances and it'd be great if thecoli supported embedded posts from there.

Added Mastodon

Mastodon is a federated social network, with instances hosted on many different domains, each with different rules and moderation. Currently only the main instance hosted at https://mastodon.social is supported.

Also, the CSS for Amazon fallback links has been slightly tweaked. There should be no visible change.
 

bnew

Veteran
Joined
Nov 1, 2015
Messages
42,966
Reputation
7,267
Daps
131,556
I don't know nothing about tech shyt in relation to the site breh. This would be Brook and/or whoever he hired after cook left.

Fred.
can you pass the msg along?
 
  • Dap
Reactions: hex

bnew

Veteran
Joined
Nov 1, 2015
Messages
42,966
Reputation
7,267
Daps
131,556
they have another update

Added support for custom Mastodon instances, updated Tumblr

To configure which instances are allowed, go to the add-on's options page or search for Mastodon in the admin panel and select Mastodon hosts.

Tumblr has been updated to use the v2 embed.


list of mastodon instances here


lots of academics post great content there.

 

bnew

Veteran
Joined
Nov 1, 2015
Messages
42,966
Reputation
7,267
Daps
131,556
I got chatgpt to make a userscript that would load mastodon links like twitter posts.

it basically determines if a link is a mastodon link based on the @Username and post id. it's then add to the end /embed.js for each mastodon instance link with it's unique domain.

Code:
// ==UserScript==
// @name         Mastodon Embed Links
// @version      1
// @description  Embed Mastodon posts in Xenforo-compatible forums
// @match        https://www.thecoli.com/threads/*
// @match        https://thecoli.com/threads/*
// ==/UserScript==

(function() {
    'use strict';

    // Regex pattern to match Mastodon links
    const mastodonRegex = /^https?:\/\/([a-z\d-_]+\.)*([a-z\d-_]+)\.([a-z]{2,})(\/@[a-zA-Z0-9-_]+\/\d+)/;

    // Find all links on the page
    const links = document.getElementsByTagName("a");
    for (let i = 0; i < links.length; i++) {
        const link = links[i];
        const href = link.getAttribute("href");

        // Check if the link matches the Mastodon regex pattern
        if (mastodonRegex.test(href)) {
            const match = href.match(mastodonRegex);
            const username = match[4].split("/")[1];
            const postID = match[4].split("/")[2];
            const domain = match[2];

            // Create the iframe embed code
            const embedUrl = `${href}/embed`;
            const scriptSrc = `https://${domain}/embed.js`;
            const iframe = document.createElement("iframe");
            iframe.src = embedUrl;
            iframe.classList.add("mastodon-embed");
            iframe.style.maxWidth = '550px';
            iframe.style.border = "0";
            iframe.style.width = '100%';
            iframe.style.height = '400px';
            iframe.setAttribute("allowfullscreen", "allowfullscreen");
            const script = document.createElement("script");
            script.src = scriptSrc;
            script.async = true;
            iframe.appendChild(script);

            // Replace the link with the embedded post
            link.parentNode.replaceChild(iframe, link);

            // Listen for the "load" event on the iframe
            iframe.addEventListener("load", () => {
                // Get the width and height of the content inside the iframe
                const iframeContentWidth = iframe.contentWindow.document.body.offsetWidth;
                const iframeContentHeight = iframe.contentWindow.document.body.offsetHeight;

                // Set the width and height of the iframe to the size of the content
                iframe.width = iframeContentWidth;
                iframe.height = iframeContentHeight;
            });

        }
    }
})();

To use this script:
  1. Install the Tampermonkey browser extension if you haven't already.
  2. Open the Tampermonkey dashboard and click on the "Create a new script" button.
  3. Replace the default content with the userscript provided above.
  4. Save the script (Ctrl+S or Command+S) and make sure it's enabled in Tampermonkey.

some posts with a mastodon link.



AjsW1Bq.png
 
Last edited:

bnew

Veteran
Joined
Nov 1, 2015
Messages
42,966
Reputation
7,267
Daps
131,556
I updated the userscript, it now supports embedding threads.net posts similar to twitter embeds and supports embedding x.com posts.
if the x.com url is marked NSFW by twitter than the embed won't load just like regular twitter embeds currently don't.
Code:
// ==UserScript==
// @name         Mastodon Embed Links
// @version      1.1.3
// @description  Embed Mastodon posts in Xenforo-compatible forums
// @match        https://www.thecoli.com/threads/*
// @match        https://thecoli.com/threads/*
// ==/UserScript==

(function() {
    'use strict';

    // Regex pattern to match Mastodon and x.com links
    const mastodonRegex = /^https?:\/\/([a-z\d-_]+\.)*([a-z\d-_]+)\.([a-z]{2,})(\/@[a-zA-Z0-9-_]+(@[a-zA-Z0-9-_]+)?\/\d+|\/@[a-zA-Z0-9-_]+\/post\/\w+|\/t\/\w+)/;
    const xcomRegex = /^https?:\/\/(www\.)?x\.com\/.*\/status\/(\d+)/;

    // Find all links on the page
    const links = document.getElementsByTagName("a");
    for (let i = 0; i < links.length; i++) {
        const link = links[i];
        let href = link.getAttribute("href");

        // Check if the link matches the Mastodon regex pattern
        if (mastodonRegex.test(href)) {
            const match = href.match(mastodonRegex);
            const username = match[4].split("/")[1];
            let domain = match[2];
            const postID = match[4].split("/")[2];

            // Check if there are two "@" symbols in the URL
            if ((username.match(/@/g) || []).length === 2) {
                // Rewrite the URL
                domain = username.split("@")[2];
                href = `https://${domain}/@${username.split("@")[1]}/${postID}`;
            }

            // Create the iframe embed code
            const embedUrl = `${href}/embed`;
            const scriptSrc = `https://${domain}/embed.js`;
            const iframe = document.createElement("iframe");
            iframe.src = embedUrl;
            iframe.classList.add("mastodon-embed", "gh-fit");
            iframe.style.maxWidth = '550px';
            iframe.style.border = "0";
            iframe.style.width = '100%';
            iframe.style.height = '620px';
            iframe.style.maxHeight = '650px';
            iframe.style.overflow = 'hidden';
            iframe.setAttribute("allowfullscreen", "allowfullscreen");
            const script = document.createElement("script");
            script.src = scriptSrc;
            script.async = true;
            iframe.appendChild(script);

            // Replace the link with the embedded post
            link.parentNode.replaceChild(iframe, link);
        }
        // Check if the link matches the x.com regex pattern
        else if (xcomRegex.test(href)) {
            const match = href.match(xcomRegex);
            const postID = match[2];

            // Create the iframe embed code
            const embedUrl = `https://s9e.github.io/iframe/2/twitter.min.html#${postID}`;
            const iframe = document.createElement("iframe");
            iframe.setAttribute("data-s9e-mediaembed", "twitter");
            iframe.setAttribute("allow", "autoplay *");
            iframe.setAttribute("allowfullscreen", "");
            iframe.setAttribute("scrolling", "no");
            iframe.style.height = '1210px';
            iframe.style.width = '550px';
            iframe.src = embedUrl;
            iframe.setAttribute("loading", "eager");

           // Replace the link with the embedded post
           link.parentNode.replaceChild(iframe, link);
        }
    }

    function fit() {
        var iframes = document.querySelectorAll("iframe.gh-fit")

        for(var id = 0; id < iframes.length; id++) {
           var win = iframes[id].contentWindow
           var doc = win.document
           var html = doc.documentElement
           var body = doc.body

           if(body) {
               body.style.overflowX = "scroll"; // scrollbar-jitter fix
               body.style.overflowY = "hidden";
           }

           if(html) {
               html.style.overflowX = "scroll"; // scrollbar-jitter fix
               html.style.overflowY = "hidden";
               var style = win.getComputedStyle(html);
               iframes[id].width = parseInt(style.getPropertyValue("width")); // round value
               iframes[id].height = parseInt(style.getPropertyValue("height"));
           }
       }

       requestAnimationFrame(fit);
   }

   addEventListener("load", requestAnimationFrame.bind(this, fit));
})();


one particular issue with the userscript is that it doesn't embed a mastodon url like this https://mstdn.social/@theseeduneed@mastodon.social/111259225096817564
it needs to be like https://mastodon.social/@theseeduneed/111259225096817564 instead.

The userscript you provided is designed to replace certain types of links on a webpage with embedded posts. Here’s what it does when it encounters each of the URLs you provided:

  1. https://twitter.com/BaldyNFL/status/1709212004026548631: This URL matches the x.com regex pattern in the userscript. The script will replace this link with an embedded post from x.com. The embedded post will be displayed in an iframe with a height of 693px and a width of 550px.
  2. https://mstdn.social/@noelreports/111275312521478534: This URL matches the Mastodon regex pattern in the userscript. The script will replace this link with an embedded post from Mastodon. The embedded post will be displayed in an iframe with a height of 620px and a width of 100% (up to a maximum width of 550px).
Please note that the userscript only modifies links that are present on the page at the time the script runs (i.e., when the page loads). If new links are added to the page after it loads, those links will not be modified by the script.


The userscript you provided is designed to embed Mastodon posts and x.com links in Xenforo-compatible forums.

When the userscript encounters the URL `https://twitter.com/SamAdlerBell/status/1715800138273226959`, it will match the URL with the `xcomRegex` regular expression pattern. This pattern is designed to match URLs from x.com that contain a status ID.

Once a match is found, the script extracts the status ID from the URL (in this case, `1715800138273226959`). It then creates an iframe element and sets its source (`src`) to an embed URL that includes this status ID. The iframe is then used to replace the original link on the page.

This means that instead of seeing a simple link to the x.com post, viewers of the page will see the embedded post directly on the page. This makes it easier for users to view the content without having to navigate away from the page.

Please note that this userscript is set to run on pages that match `https://www.thecoli.com/threads/*` and `https://thecoli.com/threads/*` as specified in the `@match` metadata. If you want this script to run on different pages, you would need to modify these match patterns accordingly.


edit:
test with urls in these threads

https://www.thecoli.com/search/search/?keywords=https://x.com/&users=&date=
https://www.thecoli.com/search/search/?keywords=https://www.threads.net/&users=&date=
https://www.thecoli.com/search/search/?keywords=https://mastodon.social/&users=&date=
 
Last edited:
  • Dap
Reactions: hex
Top