From a6ef71be6d5258b04c27a54970f74bc65f13bea7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Mon, 10 Jun 2024 19:36:45 +0300 Subject: [PATCH] First commit --- README | 6 ++++++ UNLICENSE | 24 ++++++++++++++++++++++++ cohost-dir-auto.js | 41 +++++++++++++++++++++++++++++++++++++++++ cohost-top-bar.css | 5 +++++ 4 files changed, 76 insertions(+) create mode 100644 README create mode 100644 UNLICENSE create mode 100644 cohost-dir-auto.js create mode 100644 cohost-top-bar.css diff --git a/README b/README new file mode 100644 index 0000000..65fb323 --- /dev/null +++ b/README @@ -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. diff --git a/UNLICENSE b/UNLICENSE new file mode 100644 index 0000000..69843e4 --- /dev/null +++ b/UNLICENSE @@ -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] diff --git a/cohost-dir-auto.js b/cohost-dir-auto.js new file mode 100644 index 0000000..8a5d406 --- /dev/null +++ b/cohost-dir-auto.js @@ -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, +}); diff --git a/cohost-top-bar.css b/cohost-top-bar.css new file mode 100644 index 0000000..2087386 --- /dev/null +++ b/cohost-top-bar.css @@ -0,0 +1,5 @@ +@-moz-document domain("cohost.org") { +header.fixed { + position: unset; +} +}