Guest User

move notification to postbox column

a guest
Jul 11th, 2024
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        move notification to postbox column
  3. // @namespace   724a
  4. // @match       https://mstdn.nere9.help/*
  5. // @grant       none
  6. // @version     1.0
  7. // @author      724a
  8. // @description 通知を投稿の下に移動する
  9. // @grant       GM_addStyle
  10. // @run-at      document-idle
  11. // @license     CC0
  12. // ==/UserScript==
  13.  
  14. /*
  15. Note
  16.  
  17. 投稿欄のエリアと同じクラスを持つ要素を作り、そこに投稿欄と通知欄を移動する。CSSを微調整して違和感なくする。
  18. 投稿欄のエリアにある検索結果用の要素を通知の下に移動する。
  19.  
  20. 通知欄の設定があふれるのでそこはサイズ基準を調整して対策。
  21. この実装の場合は検索結果は両方を覆うことができるのでUXが良い。
  22. */
  23.  
  24. const custom_style = `
  25. #move_drawer_pager{
  26.   flex-direction: column;
  27. }
  28.  
  29. #move_notification_column{
  30.   flex-grow: 1;
  31.   width: auto;
  32.   padding-left: 0;
  33.   padding-right: 0;
  34.  
  35.   container-type: size;
  36. }
  37.  
  38. #move_drawer_orig_pager,
  39. #move_drawer_innner{
  40.   display: block;
  41. }
  42.  
  43. #move_drawer_innner{
  44.   position: relative;
  45.   height: auto;
  46. }
  47.  
  48. #move_search_result{
  49.   position: absolute;
  50.   z-index: 2;
  51. }
  52.  
  53. #move_notification_column > div.column-header__wrapper > div.column-header__collapsible{
  54.   max-height: 70cqh;
  55. }
  56.  
  57. #move_notification_column > div.column-header__wrapper > div.column-header__collapsible.collapsed{
  58.   max-height: 0;
  59. }
  60. .;
  61. `
  62.  
  63. const selectors = {
  64.   drawer: '.drawer',
  65.   pager: '.drawer__pager',
  66.   inner: '.drawer__inner:has(.compose-form)',
  67.   search_result: '.drawer__inner:has(.search-results)',
  68.   notification: '.column:has(div.column-header__wrapper > .column-header > button > i.fa-bell)'
  69. }
  70.  
  71.  
  72. // settings
  73. const load_wait = 2; // タイムラインロードされるまで何秒待つか。
  74.  
  75. const main = () => {
  76.   console.log('[Move notification]Started');
  77.  
  78.   GM_addStyle(custom_style);
  79.  
  80.   const drawer = document.querySelector(selectors.drawer);
  81.   const orig_pager = document.querySelector(selectors.pager);
  82.   const notification = document.querySelector(selectors.notification);
  83.   const inner = document.querySelector(selectors.inner);
  84.   const search_result = document.querySelector(selectors.search_result);
  85.  
  86.   if(!drawer || !orig_pager || !notification || !inner || !search_result){
  87.     console.error("[Move notification]Can't find elements");
  88.     return;
  89.   }
  90.  
  91.   const new_pager = document.createElement('div');
  92.   drawer.append(new_pager);
  93.   new_pager.id = "move_drawer_pager";
  94.   new_pager.classList.add(selectors.pager.replace('.', ''));
  95.  
  96.   orig_pager.classList.remove(selectors.pager.replace('.', ''));
  97.   orig_pager.id = 'move_drawer_orig_pager';
  98.  
  99.   notification.id = 'move_notification_column';
  100.   inner.id = 'move_drawer_innner'
  101.   search_result.id = 'move_search_result'
  102.  
  103.   new_pager.append(orig_pager);
  104.   new_pager.append(notification);
  105.   new_pager.append(search_result);
  106. }
  107.  
  108.  
  109. setTimeout(main, load_wait * 1000);
Advertisement
Add Comment
Please, Sign In to add comment