xx圈按时间排序

try to take over the world!

目前為 2023-01-17 提交的版本,檢視 最新版本

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 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();
})();