resize-o-don

resizable columns in mastodon

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         resize-o-don
// @license      DWTFYW
// @namespace    http://pureandapplied.com.au/resizodon
// @version      0.3.1
// @description  resizable columns in mastodon
// @author       stib
// @match        https://*.social/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=aus.social
// @grant        none
// @run-at        document-idle
// ==/UserScript==


(function() {
    function makeResizable () {
        let cols =[];
        for (let a = 0; a < arguments.length; a++){
            let divs = document.getElementsByClassName(arguments[a]);

            for (let d = 0; d < divs.length; d++){
                console.log(divs[d]);
                cols.push(divs[d]);
            }
        }

        for(let i=0; i< cols.length - 1; i++){
            console.log(cols[i]);
            cols[i].style.resize = "horizontal";
            cols[i].style.flexShrink = 0;
            resizeObserver.observe(cols[i]);
            //cols[i].style.width = '350px';
        }
        if (cols.length){
            cols[cols.length -1].resize = "horizontal";
            cols[cols.length -1].style.flex = "1 1 auto";
        }
    };
    const resizeObserver = new ResizeObserver((entries) => {
        for (const entry of entries) {
            if (entry.contentBoxSize) {
                setupResizing();
            }
        }
    })
    function setupResizing(){
            makeResizable('drawer', 'column');

    };
    // Tampermonkey on Chrome seems to run scripts before the document is fully loaded.
    // So this fixes that. Using firefox would fix it better, peeps.
    // Convenience function to execute your callback only after document.readyState === 'complete'
    // modified version of code found here https://github.com/Tampermonkey/tampermonkey/issues/1279
    // Gives up after 1 minute.
    function runWhenReady(callback) {
        var numAttempts = 0;
        var tryNow = function() {
            if ( document.readyState === 'complete') {
                callback();
            } else {
                numAttempts++;
                if (numAttempts >= 34) {
                    console.warn('Giving up after 34 attempts. document not complete');
                } else {
                    setTimeout(tryNow, 250 * Math.pow(1.1, numAttempts));
                }
            }
        };
        tryNow();
    }
    runWhenReady(setupResizing);
})();