resize-o-don

resizable columns in mastodon

目前為 2022-11-04 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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);
})();