resizable columns in mastodon
当前为
// ==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);
})();