First commit
This commit is contained in:
commit
a6ef71be6d
4 changed files with 76 additions and 0 deletions
6
README
Normal file
6
README
Normal file
|
@ -0,0 +1,6 @@
|
|||
My personal userstyles / userscripts for Cohost.
|
||||
|
||||
cohost-top-bar.css: unstuck the sticky top bar
|
||||
cohost-dir-auto.js: set dir="auto" on elements that ought to have it
|
||||
|
||||
If you have improvements for any of these, feel free to send me an ask over on Cohost.
|
24
UNLICENSE
Normal file
24
UNLICENSE
Normal file
|
@ -0,0 +1,24 @@
|
|||
This is free and unencumbered software released into the public domain.
|
||||
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
distribute this software, either in source code form or as a compiled
|
||||
binary, for any purpose, commercial or non-commercial, and by any
|
||||
means.
|
||||
|
||||
In jurisdictions that recognize copyright laws, the author or authors
|
||||
of this software dedicate any and all copyright interest in the
|
||||
software to the public domain. We make this dedication for the benefit
|
||||
of the public at large and to the detriment of our heirs and
|
||||
successors. We intend this dedication to be an overt act of
|
||||
relinquishment in perpetuity of all present and future rights to this
|
||||
software under copyright law.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
For more information, please refer to [http://unlicense.org]
|
41
cohost-dir-auto.js
Normal file
41
cohost-dir-auto.js
Normal file
|
@ -0,0 +1,41 @@
|
|||
// ==UserScript==
|
||||
// @name Cohost dir="auto"
|
||||
// @version 1
|
||||
// @grant none
|
||||
// @match https://cohost.org/*
|
||||
// ==/UserScript==
|
||||
|
||||
const selectors = [
|
||||
'textarea', // Post/comment editor fields
|
||||
'.co-prose', // User-created non-inline content
|
||||
].join(',');
|
||||
|
||||
function applyDirAuto(tree) {
|
||||
if (tree.matches(selectors)) {
|
||||
tree.dir = 'auto';
|
||||
}
|
||||
for (const post of tree.querySelectorAll(selectors)) {
|
||||
post.dir = 'auto';
|
||||
}
|
||||
}
|
||||
|
||||
// Apply dir="auto" to elements that are there already on page load
|
||||
applyDirAuto(document.documentElement);
|
||||
|
||||
// New posts are loaded dynamically using JavaScript, so we need to react to new elements being added
|
||||
const observer = new MutationObserver((mutations) => {
|
||||
for (const mutation of mutations) {
|
||||
for (const node of mutation.addedNodes) {
|
||||
if (node.nodeType === Node.ELEMENT_NODE) {
|
||||
applyDirAuto(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// There is seemingly no good way to refer to the post list, so let's err on the side of firing too often
|
||||
const contentsContainer = document.getElementById('app');
|
||||
observer.observe(contentsContainer, {
|
||||
subtree: true,
|
||||
childList: true,
|
||||
});
|
5
cohost-top-bar.css
Normal file
5
cohost-top-bar.css
Normal file
|
@ -0,0 +1,5 @@
|
|||
@-moz-document domain("cohost.org") {
|
||||
header.fixed {
|
||||
position: unset;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue