X Media Grid Restore

Restores X's legacy profile media grid while the original feature remains available.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

作者のサイトでサポートを受ける。または、このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         X Media Grid Restore
// @namespace    https://github.com/QuantumDeus/x-media-grid-restore
// @version      0.1.0
// @description  Restores X's legacy profile media grid while the original feature remains available.
// @author       QuantumDeus
// @license      MIT
// @homepageURL  https://github.com/QuantumDeus/x-media-grid-restore
// @supportURL   https://github.com/QuantumDeus/x-media-grid-restore/issues
// @match        https://x.com/*
// @run-at       document-start
// @sandbox      raw
// @grant        none
// @noframes
// ==/UserScript==

(() => {
  "use strict";

  const FLAG_NAMES = [
    "responsive_web_profile_redesign_enabled",
    "rweb_media_carousel_enabled"
  ];

  function disableMediaRedesign(state) {
    const featureSwitch = state?.featureSwitch;
    const configs = [
      featureSwitch?.defaultConfig,
      featureSwitch?.user?.config
    ];

    for (const config of configs) {
      if (!config) continue;

      for (const flagName of FLAG_NAMES) {
        const flag = config[flagName];
        if (flag && typeof flag === "object") {
          flag.value = false;
        }
      }
    }

    return state;
  }

  let initialState;

  try {
    const existingDescriptor = Object.getOwnPropertyDescriptor(
      window,
      "__INITIAL_STATE__"
    );

    if (existingDescriptor && "value" in existingDescriptor) {
      initialState = disableMediaRedesign(existingDescriptor.value);
    }

    Object.defineProperty(window, "__INITIAL_STATE__", {
      configurable: true,
      enumerable: true,
      get() {
        return initialState;
      },
      set(value) {
        initialState = disableMediaRedesign(value);
      }
    });

    Object.defineProperty(window, "__X_MEDIA_GRID_RESTORE__", {
      configurable: false,
      enumerable: false,
      value: Object.freeze({ version: "0.1.0", userscript: true }),
      writable: false
    });
  } catch {
    // Fail closed: leave X untouched if its bootstrap object cannot be patched.
  }
})();