xx圈按时间排序

try to take over the world!

当前为 2023-01-17 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         xx圈按时间排序
// @license      WTFPL
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  try to take over the world!
// @author       Yxxx
// @match        https://ee.bytedance.net/malaita/pc/*
// @icon         https://ee.bytedance.net/malaita/static/img/malaita.png
// @grant        GM_registerMenuCommand
// @grant        GM_unregisterMenuCommand
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        unsafeWindow
// @run-at       document-start
// ==/UserScript==

(function () {
    const MENU_ALL = [
        ['menu_time_order', '帖子按时间排序', true, () => { switchMenuCommand('menu_time_order'); alert('请手动刷新页面以生效.'); }],
        ['menu_filter_new_bytedancer', '过滤新人报道 TODO', true, () => { switchMenuCommand('menu_filter_new_bytedancer') }],
        ['menu_filter_anonymous', '过滤匿名 TODO', true, () => { switchMenuCommand('menu_filter_anonymous') }],
        ['menu_post_blackword_list', '过滤词列表 (逗号分隔) TODO', '', () => { }],
        ['menu_debug_menu', 'DEBUG MENU', 0, () => { console.log(MENU_VALUE, REGISITED_MENU_ID) }]
    ];
    const MENU_VALUE = {};
    const REGISITED_MENU_ID = [];

    function registerMenuCommand() {
        if (REGISITED_MENU_ID.length >= MENU_ALL.length) {
            REGISITED_MENU_ID.forEach(id => GM_unregisterMenuCommand(id));
            REGISITED_MENU_ID.length = 0;
        }
        MENU_ALL.forEach(([key, name, defaultValue, handler]) => {
            let v = MENU_VALUE[key] ?? GM_getValue(key);
            if (v == null){
                GM_setValue(key, defaultValue);
                v = defaultValue;
            };
            MENU_VALUE[key] = v;
            const menuId = GM_registerMenuCommand(`${v === true ? '✅  ' : v === false ? '❌  ': ''}${name}`, handler);
            REGISITED_MENU_ID.push(menuId);
        });
    }

    function switchMenuCommand(key) {
        const currentValue = MENU_VALUE[key];
        GM_setValue(key, !currentValue);
        MENU_VALUE[key] = !currentValue;
        registerMenuCommand();
    }

    const originFetch = fetch;
    console.log(originFetch)
    window.unsafeWindow.fetch = (url, options) => {
        return originFetch(url, options).then(async (response) => {
            console.log('hack: ', url, options)
            if(MENU_VALUE.menu_time_order && url === '/malaita/v2/user/settings/'){
                console.log('hit');
                const responseClone = response.clone();
                let res = await responseClone.json();
                res.feed_type = 1;
                console.log(res);
                const responseNew = new Response(JSON.stringify(res), response);
                return responseNew;
            }else{
                return response;
            }
        });
    };

    registerMenuCommand();
})();