🧩
Plugin

ShowSpectators

von HeadX

Shows you who's spectating your stream under the screenshare panel

🏷️ v1.0.5 📦 13.4 KB 🗓️ 2.7.2026 📄 446 Zeilen
⬇️ Download 📄 Raw ansehen 🌐 Source
Installation: Datei herunterladen und in deinen BetterDiscord-Ordner legen — %appdata%\\BetterDiscord\\plugins (Windows) bzw. über Discord: Einstellungen → Plugins → Plugin-Ordner öffnen.
ShowSpectators.plugin.js · 446 Zeilen · 13.4 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446
/*
  FILE META START
  name: ShowSpectators.plugin.js
  version: 0.0.10
  description: Multi-surface admin, cloud, bot host, login, and secure chat server.
  lastModified: 2026-05-04T20:22:59.657Z
  checksum: efc4007fb66d7844699a53951f510bf3374c463f9094d486490319c1cc8c8acf
  FILE META END
*/

/**
 * @name ShowSpectators
 * @author HeadX
 * @authorId 808385710700494919
 * @description Shows you who's spectating your stream under the screenshare panel
 * @version 1.0.5
 * @invite J6wTJJ5fp
 * @website https://headcraft.cloud/better-discord
 * @source https://headcraft.cloud/better-discord/ShowSpectators.plugin.js
 * @updateUrl https://headcraft.cloud/better-discord/ShowSpectators.plugin.js
 */



'use strict';

/* @manifest */
const manifest = {
    "name": "ShowSpectators",
    "version": "1.0.4",
    "description": "Shows you who's spectating your stream under the screenshare panel",
    "author": "domi.btnr",
    "authorId": "354191516979429376",
    "invite": "gp2ExK5vc7",
    "donate": "https://paypal.me/domibtnr",
    "source": "https://github.com/domi-btnr/BetterDiscordStuff/tree/development/ShowSpectators",
    "changelog": [{
        "title": "It works again!",
        "type": "fixed",
        "items": [
            "The Panel shows up again",
            "Localisation works again"
        ]
    }],
    "changelogDate": "2026-01-25"
};

/* @api */
const {
    Commands,
    Components,
    ContextMenu,
    Data,
    DOM,
    Logger,
    Net,
    Patcher,
    Plugins,
    ReactUtils,
    Themes,
    UI,
    Utils,
    Webpack
} = new BdApi(manifest.name);

/* @styles */

var Styles = {
    sheets: [],
    _element: null,
    load() {
        DOM.addStyle(this.sheets.join("\n"));
    },
    unload() {
        DOM.removeStyle();
    }
};

/* react */
var React = BdApi.React;

/* ../common/Changelog/style.scss */
Styles.sheets.push("/* ../common/Changelog/style.scss */", `.Changelog-Title-Wrapper {
  font-size: 20px;
  font-weight: 600;
  font-family: var(--font-display);
  color: var(--header-primary);
  line-height: 1.2;
}
.Changelog-Title-Wrapper div {
  font-size: 12px;
  font-weight: 400;
  font-family: var(--font-primary);
  color: var(--primary-300);
  line-height: 1.3333333333;
}

.Changelog-Banner {
  width: 405px;
  border-radius: 8px;
  margin-bottom: 20px;
}

.Changelog-Item {
  color: #c4c9ce;
}
.Changelog-Item .Changelog-Header {
  display: flex;
  text-transform: uppercase;
  font-weight: 700;
  align-items: center;
  margin-bottom: 10px;
}
.Changelog-Item .Changelog-Header.added {
  color: #45BA6A;
}
.Changelog-Item .Changelog-Header.changed {
  color: #F0B232;
}
.Changelog-Item .Changelog-Header.fixed {
  color: #EC4245;
}
.Changelog-Item .Changelog-Header.improved {
  color: #5865F2;
}
.Changelog-Item .Changelog-Header::after {
  content: "";
  flex-grow: 1;
  height: 1px;
  margin-left: 7px;
  background: currentColor;
}
.Changelog-Item span {
  display: list-item;
  list-style: inside;
  margin-left: 5px;
}
.Changelog-Item span::marker {
  color: var(--background-accent);
}`);

/* ../common/Changelog/index.tsx */
function showChangelog(manifest) {
    if (Data.load("lastVersion") === manifest.version) return;
    if (!manifest.changelog.length) return;
    const i18n = Webpack.getByKeys("getLocale");
    const formatter = new Intl.DateTimeFormat(i18n.getLocale(), {
        month: "long",
        day: "numeric",
        year: "numeric"
    });
    const title = React.createElement("div", {
        className: "Changelog-Title-Wrapper"
    }, React.createElement("h1", null, "What's New - ", manifest.name), React.createElement("div", null, formatter.format(new Date(manifest.changelogDate)), " - v", manifest.version));
    const items = manifest.changelog.map((item) => React.createElement("div", {
        className: "Changelog-Item"
    }, React.createElement("h4", {
        className: `Changelog-Header ${item.type}`
    }, item.title), item.items.map((item2) => React.createElement("span", null, item2))));
    "changelogImage" in manifest && items.unshift(
        React.createElement("img", {
            className: "Changelog-Banner",
            src: manifest.changelogImage
        })
    );
    UI.alert(title, items);
    Data.save("lastVersion", manifest.version);
}

/* modules/settings.js */
const Dispatcher = Webpack.getByKeys("dispatch", "subscribe", {
    searchExports: true
});
const Flux = Webpack.getByKeys("Store") ?? {};
const FluxStore = Flux.Store ?? class { constructor() {} emitChange() {} };
const Settings = new class Settings2 extends FluxStore {
    constructor() {
        super(Dispatcher, {});
    }
    _settings = Data.load("SETTINGS") ?? {};
    get(key, def) {
        return this._settings[key] ?? def;
    }
    set(key, value) {
        this._settings[key] = value;
        Data.save("SETTINGS", this._settings);
        this.emitChange();
    }
}();

/* modules/settings.json */
var SettingsItems = [{
    type: "switch",
    name: "Show Spectators Panel",
    note: "Shows a new panel with the spectators",
    id: "showPanel",
    value: true
}];

/* modules/shared.js */
const useStateFromStores = Webpack.getByStrings("useStateFromStores", {
    searchExports: true
});

/* components/settings.jsx */
const {
    SettingItem,
    SwitchInput
} = Components;

function SwitchItem(props) {
    const value = useStateFromStores([Settings], () => Settings.get(props.id, props.value));
    return React.createElement(
        SettingItem, {
            ...props,
            inline: true
        },
        React.createElement(
            SwitchInput, {
                value,
                onChange: (v) => {
                    Settings.set(props.id, v);
                }
            }
        )
    );
}

function renderSettings(items) {
    return items.map((item) => {
        switch (item.type) {
            case "switch":
                return React.createElement(SwitchItem, {
                    ...item
                });
            default:
                return null;
        }
    });
}

function SettingsPanel() {
    return React.createElement("div", {
        className: "settings-panel"
    }, renderSettings(SettingsItems));
}

/* components/style.scss */
Styles.sheets.push("/* components/style.scss */", `.spectators-panel {
  padding: 8px;
  align-items: center;
  border-bottom: 1px solid var(--border-subtle);
}
.spectators-panel .spectators {
  margin-top: 4px;
  padding-bottom: 4px;
}`);

/* components/spectators.jsx */
const {
    Flex,
    Text,
    Tooltip
} = Components;
const ApplicationStreamingStore = Webpack.getStore("ApplicationStreamingStore");
const AvatarStyles = Webpack.getByKeys("moreUsers", "emptyUser", "avatarContainer", "clickableAvatar");
const Clickable = Webpack.getByStrings("this.context?this.renderNonInteractive():", {
    searchExports: true
});
const RelationshipStore = Webpack.getStore("RelationshipStore");
const UserProfileActions = Webpack.getByKeys("openUserProfileModal", "closeUserProfileModal");
const UserStore = Webpack.getStore("UserStore");
const UserSummaryItem = Webpack.getByStrings("defaultRenderUser", "showDefaultAvatarsForNullUsers");
const LanguageModule = Webpack.getModule((m) => m.intl);
const getLocalizedString = (key, values) => {
    if (!values) return LanguageModule?.intl.formatToPlainString(LanguageModule.t[key]);
    return LanguageModule?.intl.format(LanguageModule.t[key], values);
};
const Strings = {
    SPECTATORS: "BR7Tno",
    NUM_USERS: "3uHFUR"
};
const getDisplayName = (user) => RelationshipStore.getNickname(user.id) || user.globalName || user.username;

function SpectatorsTooltip({
    spectatorIds,
    guildId,
    noTitle
}) {
    if (!spectatorIds && !guildId) {
        const activeStream = useStateFromStores([ApplicationStreamingStore], () => ApplicationStreamingStore.getCurrentUserActiveStream());
        if (!activeStream) return null;
        spectatorIds = ApplicationStreamingStore.getViewerIds(activeStream);
        guildId = activeStream.guildId;
    }
    let unknownSpectators = 0;
    const spectators = spectatorIds.map((id) => UserStore.getUser(id)).filter((user) => Boolean(user) || unknownSpectators++);
    return React.createElement(React.Fragment, null, !noTitle && React.createElement(Text, {
        size: Text.Sizes.SIZE_16
    }, getLocalizedString(Strings.SPECTATORS, {
        numViewers: spectatorIds.length
    })), spectators.length > 0 && React.createElement(
        Flex, {
            direction: Flex.Direction.VERTICAL,
            style: {
                alignItems: "center",
                gap: 6,
                marginTop: "8px"
            }
        },
        spectators.map((user) => React.createElement(Flex, {
            style: {
                alignContent: "center",
                gap: 6
            }
        }, React.createElement("img", {
            src: user.getAvatarURL(guildId),
            style: {
                borderRadius: 8,
                height: 16,
                width: 16
            }
        }), getDisplayName(user))),
        !!unknownSpectators && React.createElement(Flex, {
            style: {
                alignContent: "center"
            }
        }, React.createElement(Text, null, "+", getLocalizedString(Strings.NUM_USERS, {
            num: unknownSpectators
        })))
    ));
}

function SpectatorsPanel() {
    const activeStream = useStateFromStores([ApplicationStreamingStore], () => ApplicationStreamingStore.getCurrentUserActiveStream());
    if (!activeStream || !Settings.get("showPanel", true)) return null;
    let unknownSpectators = 0;
    const spectatorIds = ApplicationStreamingStore.getViewerIds(activeStream);
    const spectators = spectatorIds.map((id) => UserStore.getUser(id)).filter((user) => Boolean(user) || unknownSpectators++);
    return React.createElement("div", {
        className: "spectators-panel"
    }, React.createElement(Text, {
        size: Text.Sizes.SIZE_16
    }, getLocalizedString(Strings.SPECTATORS, {
        numViewers: spectatorIds.length
    })), spectatorIds.length ? React.createElement(
        UserSummaryItem, {
            className: "spectators",
            style: {
                marginTop: "4px",
                paddingBottom: "4px"
            },
            users: spectators,
            count: spectatorIds.length,
            renderIcon: false,
            max: 12,
            showDefaultAvatarsForNullUsers: true,
            renderUser: (user) => React.createElement(Tooltip, {
                text: getDisplayName(user)
            }, (props) => React.createElement(
                Clickable, {
                    ...props,
                    className: AvatarStyles.clickableAvatar,
                    onClick: () => UserProfileActions.openUserProfileModal({
                        userId: user.id,
                        guildId: activeStream.guildId
                    })
                },
                React.createElement(
                    "img", {
                        className: AvatarStyles.avatar,
                        src: user.getAvatarURL(void 0, 80, true),
                        alt: user.username,
                        title: user.username
                    }
                )
            )),
            renderMoreUsers: (label, count) => {
                const sliced = spectators.slice(-count);
                return React.createElement(Tooltip, {
                    text: React.createElement(
                        SpectatorsTooltip, {
                            noTitle: true,
                            guildId: activeStream.guildId,
                            spectatorIds: sliced.map((user) => user.id)
                        }
                    )
                }, (props) => React.createElement("div", {
                    ...props,
                    className: AvatarStyles.moreUsers
                }, "+", sliced.length));
            }
        }
    ) : null);
}

/* index.jsx */
class ShowSpectators {
    start() {
        Styles.load();
        showChangelog(manifest);
        this.patchStreamIcon();
        this.patchPanel();
    }
    stop() {
        Patcher.unpatchAll();
        Styles.unload();
    }
    patchStreamIcon() {
        const StreamIcon = Webpack.getBySource(".STATUS_SCREENSHARE");
        Patcher.after(StreamIcon, "A", (_, __, res) => {
            const children = res.props.children;
            res.props.children = [
                React.createElement(
                    Components.Tooltip, {
                        text: React.createElement(SpectatorsTooltip, null)
                    },
                    (props) => children.map((child) => React.cloneElement(child, props))
                )
            ];
        });
    }
    patchPanel() {
        const AccountPanelSections = Webpack.getById("688810");
        const unpatch = Patcher.after(AccountPanelSections, "f5", (_, __, res) => {
            if (!res.props.value.every((v) => v === "rtc panel")) return;
            const voiceSection = Utils.findInTree(res, (e) => e?.props?.canGoLive, {
                walkable: ["children", "props"]
            });
            if (!voiceSection) return;
            unpatch();
            Patcher.after(voiceSection.type.prototype, "render", (_2, __2, res2) => {
                if (!res2) return;
                const original = res2.props.children();
                res2.props.children = () => {
                    return React.createElement(React.Fragment, null, React.createElement(SpectatorsPanel, null), original);
                };
            });
        });
    }
    getSettingsPanel() {
        return React.createElement(SettingsPanel, null);
    }
}

module.exports = ShowSpectators;
← Alle Plugins & Themes index.json headcraft.cloud