xx圈按时间排序

try to take over the world!

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

  1. // ==UserScript==
  2. // @name xx圈按时间排序
  3. // @license WTFPL
  4. // @namespace http://tampermonkey.net/
  5. // @version 0.2
  6. // @description try to take over the world!
  7. // @author Yxxx
  8. // @match https://ee.bytedance.net/malaita/pc/*
  9. // @icon https://ee.bytedance.net/malaita/static/img/malaita.png
  10. // @grant GM_registerMenuCommand
  11. // @grant GM_unregisterMenuCommand
  12. // @grant GM_getValue
  13. // @grant GM_setValue
  14. // @grant unsafeWindow
  15. // @run-at document-start
  16. // ==/UserScript==
  17.  
  18. (function () {
  19. const MENU_ALL = [
  20. ['menu_time_order', '帖子按时间排序', true, () => { switchMenuCommand('menu_time_order'); alert('请手动刷新页面以生效.'); }],
  21. ['menu_filter_new_bytedancer', '过滤新人报道 TODO', true, () => { switchMenuCommand('menu_filter_new_bytedancer') }],
  22. ['menu_filter_anonymous', '过滤匿名 TODO', true, () => { switchMenuCommand('menu_filter_anonymous') }],
  23. ['menu_post_blackword_list', '过滤词列表 (逗号分隔) TODO', '', () => { }],
  24. ['menu_debug_menu', 'DEBUG MENU', 0, () => { console.log(MENU_VALUE, REGISITED_MENU_ID) }]
  25. ];
  26. const MENU_VALUE = {};
  27. const REGISITED_MENU_ID = [];
  28.  
  29. function registerMenuCommand() {
  30. if (REGISITED_MENU_ID.length >= MENU_ALL.length) {
  31. REGISITED_MENU_ID.forEach(id => GM_unregisterMenuCommand(id));
  32. REGISITED_MENU_ID.length = 0;
  33. }
  34. MENU_ALL.forEach(([key, name, defaultValue, handler]) => {
  35. let v = MENU_VALUE[key] ?? GM_getValue(key);
  36. if (v == null){
  37. GM_setValue(key, defaultValue);
  38. v = defaultValue;
  39. };
  40. MENU_VALUE[key] = v;
  41. const menuId = GM_registerMenuCommand(`${v === true ? '✅ ' : v === false ? '❌ ': ''}${name}`, handler);
  42. REGISITED_MENU_ID.push(menuId);
  43. });
  44. }
  45.  
  46. function switchMenuCommand(key) {
  47. const currentValue = MENU_VALUE[key];
  48. GM_setValue(key, !currentValue);
  49. MENU_VALUE[key] = !currentValue;
  50. registerMenuCommand();
  51. }
  52.  
  53.    const originFetch = fetch;
  54.    console.log(originFetch)
  55.    window.unsafeWindow.fetch = (url, options) => {
  56.        return originFetch(url, options).then(async (response) => {
  57.            console.log('hack: ', url, options)
  58.            if(MENU_VALUE.menu_time_order && url === '/malaita/v2/user/settings/'){
  59. console.log('hit');
  60.                const responseClone = response.clone();
  61.                let res = await responseClone.json();
  62. res.feed_type = 1;
  63. console.log(res);
  64.                const responseNew = new Response(JSON.stringify(res), response);
  65.                return responseNew;
  66.           }else{
  67.                return response;
  68.           }
  69.       });
  70.   };
  71.  
  72. registerMenuCommand();
  73. })();