Twitter mobile file browser unlocked

Open the full file browser instead of just the recent media panel when attaching an image/video.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Twitter mobile file browser unlocked
// @namespace    http://tampermonkey.net/
// @version      2025-04-29
// @author       mesmere
// @description  Open the full file browser instead of just the recent media panel when attaching an image/video.
// @match        https://twitter.com/*
// @match        https://x.com/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        window.onurlchange
// @run-at       document-idle
// @license      MIT
// ==/UserScript==

function attempt(remainingElems = 2) {
    if (window.location.href.match(/^https:\/\/(twitter|x)\.com\/compose\/post$/) === null) {
        return;
    }
    const fileInputElems = document.querySelectorAll("input[type=file]");

    for (const fileInputElem of fileInputElems) {
        // Mobile browser file-picker behavior is determined by the HTMLInputElement.accept property.
        fileInputElem.accept = "";
    }

    // There are two separate file inputs on the page and one can load a long time before the other.
    if (fileInputElems.length < remainingElems) {
        window.setTimeout(attempt, 200, remainingElems - fileInputElems.length);
    }
}
attempt();
window.addEventListener("urlchange", attempt);