Pail/utils.js

24 lines
875 B
JavaScript
Raw Normal View History

const NEW_PAGE_DELAY = 1000
const CURRENT_PAGE_DELAY = 300
const getClassNameElementsArray = className =>
Array.from(document.getElementsByClassName(className))
/// Runs on "complete" load and when `https://website.tld#this-hash-value` changes
const addFix = fixFunc => {
window.addEventListener('load', () => setTimeout(fixFunc, NEW_PAGE_DELAY))
addEventListener('hashchange', () => setTimeout(fixFunc, CURRENT_PAGE_DELAY))
}
const getFileName = () => getClassNameElementsArray('file-breadcrumbs-segment-highlighted').map(e => e.innerText)[0]
const getCurrentUser = () => {
return getClassNameElementsArray("user-dropdown-trigger")[0].title.replace(/(.*\()|\)/g, '')
}
2023-02-07 15:04:56 -05:00
const addStyle = css => {
const styleElement = document.createElement('style')
styleElement.innerText = css.replaceAll("\n", " ")
document.head.appendChild(styleElement)
}