resize-o-don

resizable columns in mastodon

当前为 2022-11-04 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name resize-o-don
  3. // @license DWTFYW
  4. // @namespace http://pureandapplied.com.au/resizodon
  5. // @version 0.3.2
  6. // @description resizable columns in mastodon
  7. // @author stib
  8. // @match https://*.social/*
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=aus.social
  10. // @grant none
  11. // @run-at document-idle
  12. // ==/UserScript==
  13.  
  14.  
  15. (function() {
  16. function makeResizable () {
  17. let cols =[];
  18. for (let a = 0; a < arguments.length; a++){
  19. let divs = document.getElementsByClassName(arguments[a]);
  20. for (let d = 0; d < divs.length; d++){
  21. cols.push(divs[d]);
  22. }
  23. }
  24.  
  25. for(let i=0; i< cols.length - 1; i++){
  26. cols[i].style.resize = "horizontal";
  27. cols[i].style.flexShrink = 0;
  28. resizeObserver.observe(cols[i]);
  29. //cols[i].style.width = '350px';
  30. }
  31. if (cols.length){
  32. cols[cols.length -1].resize = "horizontal";
  33. cols[cols.length -1].style.flex = "1 1 auto";
  34. }
  35. //==== make all the font sizes the same =========
  36. // if you want highlighted posts to have
  37. // the default larger font size,
  38. // comment out the next two lines
  39. // by putting // at the front
  40. const s = document.getElementsByClassName("status__content__text");
  41. for (let i = 0; i < s.length; i++){ s[i].style.fontSize = "15px" }
  42. //===============================================
  43. };
  44.  
  45. const resizeObserver = new ResizeObserver((entries) => {
  46. for (const entry of entries) {
  47. if (entry.contentBoxSize) {
  48. setupResizing();
  49. }
  50. }
  51. })
  52. function setupResizing(){
  53. makeResizable('drawer', 'column');
  54.  
  55. };
  56. // Tampermonkey on Chrome seems to run scripts before the document is fully loaded.
  57. // So this fixes that. Using firefox would fix it better, peeps.
  58. // Convenience function to execute your callback only after document.readyState === 'complete'
  59. // modified version of code found here https://github.com/Tampermonkey/tampermonkey/issues/1279
  60. // Gives up after 1 minute.
  61. function runWhenReady(callback) {
  62. var numAttempts = 0;
  63. var tryNow = function() {
  64. if ( document.readyState === 'complete') {
  65. callback();
  66. } else {
  67. numAttempts++;
  68. if (numAttempts >= 34) {
  69. console.warn('Giving up after 34 attempts. document not complete');
  70. } else {
  71. setTimeout(tryNow, 250 * Math.pow(1.1, numAttempts));
  72. }
  73. }
  74. };
  75. tryNow();
  76. }
  77. runWhenReady(setupResizing);
  78. })();