-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathspacious_mastodon.user.js
64 lines (58 loc) · 2.2 KB
/
spacious_mastodon.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// ==UserScript==
// @name Spaceous Mastodon Helper
// @namespace github.com/RiedleroD/userstyles-riedler
// @version 1.2.1
// @description companion script for spaceous mastodon userstyle
// @author Riedler
// @match https://mas.to/*
// @match https://fosstodon.org/*
// @match https://mastodon.social/*
// @icon https://mas.to/favicon.ico
// @grant none
// @run-at document-idle
// ==/UserScript==
(function() {
'use strict';
console.log("me alive");
function checkSideBar(post){
let content = post.getElementsByClassName('status__content')[0];
//get minimum height by getting 15em in px
let divisor = 12*parseFloat(getComputedStyle(post).fontSize);
let actionbar = post.getElementsByClassName('status__action-bar')[0];
if(content.clientHeight>=divisor){
actionbar.classList.add('sm__force_sidebar');
}else{
//if we previously added it and it changed in the meantime
actionbar.classList.remove('sm__force_sidebar');
}
}
function isPost(element){
return element.classList!=undefined && element.classList.contains('status');
}
const target = document.getElementById('mastodon');
const obconf = { attributes: false, childList: true, subtree: true };
const callback = (mutationList, observer) => {
for(const mutation of mutationList){
for(let node of mutation.addedNodes){
if(isPost(node)){
checkSideBar(node);
}else{
//checking parents for posts
do{
node=node.parentNode;
if(isPost(node)){
checkSideBar(node);
return;
}
}while(node.parentNode!=undefined);
//checking children for posts
for(const e of node.getElementsByClassName('status')){
checkSideBar(e);
}
}
}
}
};
const observer = new MutationObserver(callback);
observer.observe(target, obconf);
})();