* [Unrelated] updated module name for existing liveview module * Updated toggle component and moved MP index table to a liveview * [WIP] reverted MP index table; added source count to MP index * Moved new live table to sources index * Added 'enabled' boolean to sources * Got 'enabled' logic working re: downloading pending media * Updated sources context to do the right thing when a source is updated * Docs and tests * Updated slow indexing to maintain its old schedule if re-enabled * Hooked up the enabled toggle to the sources page * [Unrelated] added direct links to various tabs on the sources table * More tests * Removed unneeded guard in * Removed outdated comment
44 lines
1.2 KiB
JavaScript
44 lines
1.2 KiB
JavaScript
window.copyTextToClipboard = async (text) => {
|
|
// Navigator clipboard api needs a secure context (https)
|
|
if (navigator.clipboard && window.isSecureContext) {
|
|
await navigator.clipboard.writeText(text)
|
|
} else {
|
|
const textArea = document.createElement('textarea')
|
|
textArea.value = text
|
|
// Move textarea out of the viewport so it's not visible
|
|
textArea.style.position = 'absolute'
|
|
textArea.style.left = '-999999px'
|
|
|
|
document.body.prepend(textArea)
|
|
textArea.select()
|
|
|
|
try {
|
|
document.execCommand('copy')
|
|
} catch (error) {
|
|
console.error(error)
|
|
} finally {
|
|
textArea.remove()
|
|
}
|
|
}
|
|
}
|
|
|
|
window.copyWithCallbacks = async (text, onCopy, onAfterDelay, delay = 4000) => {
|
|
await window.copyTextToClipboard(text)
|
|
onCopy()
|
|
setTimeout(onAfterDelay, delay)
|
|
}
|
|
|
|
window.markVersionAsSeen = (versionString) => {
|
|
localStorage.setItem('seenVersion', versionString)
|
|
}
|
|
|
|
window.isVersionSeen = (versionString) => {
|
|
return localStorage.getItem('seenVersion') === versionString
|
|
}
|
|
|
|
window.dispatchFor = (elementOrId, eventName, detail = {}) => {
|
|
const element =
|
|
typeof elementOrId === 'string' ? document.getElementById(elementOrId) : elementOrId
|
|
|
|
element.dispatchEvent(new CustomEvent(eventName, { detail }))
|
|
}
|