xx 圈按时间排序

xxx

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

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