Greasy Fork

来自缓存

Greasy Fork is available in English.

Twitter (X) Sort By Likes

Forces Twitter (X) to sort by likes instead of relevancy

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Twitter (X) Sort By Likes
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Forces Twitter (X) to sort by likes instead of relevancy
// @author       colleidoscope
// @match        https://x.com/*
// @match        https://twitter.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Create a proxy for XMLHttpRequest
    const XHR = XMLHttpRequest.prototype;
    const open = XHR.open;
    const send = XHR.send;

    // Override the open method
    XHR.open = function(method, url) {
        // Check if this is a TweetDetail request
        if (url.includes('/TweetDetail?')) {
            // Convert URL to URLSearchParams for easier manipulation
            const urlObj = new URL(url);
            const params = new URLSearchParams(urlObj.search);

            // Parse the variables parameter
            const variables = JSON.parse(decodeURIComponent(params.get('variables')));

            // Modify the ranking mode to "Likes"
            variables.rankingMode = "Likes";

            // Update the URL with modified parameters
            params.set('variables', JSON.stringify(variables));
            url = `${urlObj.origin}${urlObj.pathname}?${params.toString()}`;
        }

        // Call the original open method
        return open.apply(this, [method, url]);
    };

    // Override the send method
    XHR.send = function() {
        return send.apply(this, arguments);
    };
})();