8chan - global gallery mod

Modifies the advanced media viewer (turn it on in site's settings) to consider the whole thread its gallery, not just the post, also ads focus to image you open with arrow keys

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         8chan - global gallery mod
// @namespace    8chan_ggm
// @version      2026-07-31
// @description  Modifies the advanced media viewer (turn it on in site's settings) to consider the whole thread its gallery, not just the post, also ads focus to image you open with arrow keys
// @author       Owyn
// @match        https://8chan.moe/*
// @match        https://8chan.st/*
// @match        http://alephchvkipd2houttjirmgivro5pxullvcgm4c47ptm7mhubbja6kad.onion/*
// @grant        unsafeWindow
// @run-at       document-start
// @sandbox      JavaScript
// @compatible   Chrome
// @compatible   Firefox
// ==/UserScript==

(function() {
    'use strict';

    // mediaLink.closest('.panelUploads')?.querySelectorAll('.imgLink') // - how gallery is populated
    const originalClosest = unsafeWindow.Element.prototype.closest;
    if(typeof exportFunction === "function")
    {
        wrapper_closest = exportFunction(wrapper_closest , unsafeWindow); // TM magic
    }
    unsafeWindow.Element.prototype.closest = wrapper_closest;
    function wrapper_closest (selectors) {
        if(selectors == ".panelUploads")
        {
            console.log(`they wanted Closest [${selectors}] but we returned doc.body and focused this:`, this);
            this.scrollIntoView();
            return document.body;
        }
        else return originalClosest.call(this, selectors);
    };
})();