PageSourceSearch

https://m.wingu.se/embed.js

js wingu.se collected 2026-09-29 15:08:39 UTC 3,821 bytes, 153 lines download raw bytes

1// @ts-check
2(function (allowedPrefixes) {
3  'use strict';
4
5  /**
6   * @param {() => void} loaded
7   */
8  var ready = function (loaded) {
9    if (document.readyState === 'complete') {
10      loaded();
11    } else {
12      document.addEventListener('readystatechange', function () {
13        if (document.readyState === 'complete') {
14          loaded();
15        }
16      });
17    }
18  };
19
20  /**
21   * @param {Map} map
22   */
23  var generateId = function (map) {
24    var id = 0,
25      failCount = 0,
26      idBuffer = new Uint32Array(1);
27
28    while (id === 0 || map.has(id)) {
29      id = crypto.getRandomValues(idBuffer)[0];
30      failCount++;
31
32      if (failCount > 100) {
33        // give up and assign (easily guessable) unique number if getRandomValues is broken or no luck
34        id = -(map.size + 1);
35        break;
36      }
37    }
38
39    return id;
40  };
41
42  ready(function () {
43    /** @type {Map<number, HTMLQuoteElement | HTMLIFrameElement>} */
44    var embeds = new Map();
45
46    window.addEventListener('message', function (e) {
47      var data = e.data || {};
48
49      if (
50        typeof data !== 'object' ||
51        data.type !== 'setHeight' ||
52        !embeds.has(data.id)
53      ) {
54        return;
55      }
56
57      var embed = embeds.get(data.id);
58
59      if (embed instanceof HTMLIFrameElement) {
60        embed.height = data.height;
61      }
62
63      if (embed instanceof HTMLQuoteElement) {
64        var iframe = embed.querySelector('iframe');
65
66        if (!iframe || ('source' in e && iframe.contentWindow !== e.source)) {
67          return;
68        }
69
70        iframe.height = data.height;
71
72        var placeholder = embed.querySelector('a');
73
74        if (!placeholder) return;
75
76        embed.removeChild(placeholder);
77      }
78    });
79
80    // Legacy embeds
81    document.querySelectorAll('iframe.mastodon-embed').forEach((iframe) => {
82      var id = generateId(embeds);
83
84      embeds.set(id, iframe);
85
86      iframe.allow = 'fullscreen';
87      iframe.sandbox = 'allow-scripts allow-same-origin allow-popups';
88      iframe.style.border = 0;
89      iframe.style.overflow = 'hidden';
90      iframe.style.display = 'block';
91
92      iframe.onload = function () {
93        iframe.contentWindow.postMessage(
94          {
95            type: 'setHeight',
96            id: id,
97          },
98          '*',
99        );
100      };
101
102      iframe.onload(); // In case the script is executing after the iframe has already loaded
103    });
104
105    // New generation of embeds
106    document
107      .querySelectorAll('blockquote.mastodon-embed')
108      .forEach((container) => {
109        var id = generateId(embeds);
110
111        embeds.set(id, container);
112
113        var iframe = document.createElement('iframe');
114        var embedUrl = new URL(container.getAttribute('data-embed-url'));
115
116        if (embedUrl.protocol !== 'https:' && embedUrl.protocol !== 'http:')
117          return;
118        if (
119          allowedPrefixes.every(
120            (allowedPrefix) => !embedUrl.toString().startsWith(allowedPrefix),
121          )
122        )
123          return;
124
125        iframe.src = embedUrl.toString();
126        iframe.width = container.clientWidth;
127        iframe.height = 0;
128        iframe.allow = 'fullscreen';
129        iframe.sandbox = 'allow-scripts allow-same-origin allow-popups';
130        iframe.style.border = 0;
131        iframe.style.overflow = 'hidden';
132        iframe.style.display = 'block';
133
134        iframe.onload = function () {
135          iframe.contentWindow.postMessage(
136            {
137              type: 'setHeight',
138              id: id,
139            },
140            '*',
141          );
142        };
143
144        container.appendChild(iframe);
145      });
146  });
147})(
148  document.currentScript &&
149    document.currentScript.tagName.toUpperCase() === 'SCRIPT' &&
150    document.currentScript.dataset.allowedPrefixes
151    ? document.currentScript.dataset.allowedPrefixes.split(' ')
152    : [],
153);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.