// we won't do copy on select on text editor, otherwise you can't select and override text in the editor or text input
function checkIfElementIsEditor(element) {
if (!element || !element.className || !element.className.toLowerCase || !element.nodeName) return false;
const isEditableElement = ['INPUT', 'TEXTAREA'].includes(element.nodeName);
const isTextEditor = element.className.toLowerCase().includes('codemirror');
return isEditableElement || isTextEditor;
}
// Copy on select, copy document selection when mouse button is up
document.addEventListener('mouseup', function onMouseUp() {
const elementsUnderMouse = document.querySelectorAll(':hover');
if (!elementsUnderMouse || Array.from(elementsUnderMouse).some(checkIfElementIsEditor)) return;
document.execCommand('copy');
});I found $:/tags/StartupAction/Browser will only execute tiddlywi actions, but can't execute javascript.But I have following JS want to execute:
What could I do?I'm currently using WebcataLog to inject Userscript before wiki loading
// we won't do copy on select on text editor, otherwise you can't select and override text in the editor or text input
function checkIfElementIsEditor(element) {
if (!element || !element.nodeName) return false;
const isEditableElement = ['INPUT', 'TEXTAREA', 'BUTTON'].includes(element.nodeName);
if (!isEditableElement) {
if (!element.className || !element.className.toLowerCase) return false;
}
const isTextEditor = element.className.toLowerCase().includes('codemirror');
return isEditableElement || isTextEditor;
}
// if we start selection on editor, we prevent the following execution of this script
let copyOnSelectPreventNextCopy = false;
document.addEventListener('mousedown', function onMouseDown() {
const elementsUnderMouse = document.querySelectorAll(':hover');
if (!elementsUnderMouse || Array.from(elementsUnderMouse).some(checkIfElementIsEditor)) {
copyOnSelectPreventNextCopy = true;
}
});
// Copy on select, copy document selection when mouse button is up
document.addEventListener('mouseup', function onMouseUp() {
const elementsUnderMouse = document.querySelectorAll(':hover');
if (
copyOnSelectPreventNextCopy ||
!elementsUnderMouse ||
Array.from(elementsUnderMouse).some(checkIfElementIsEditor)
) {
copyOnSelectPreventNextCopy = false;
return;
}
document.execCommand('copy');
});--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/56f2c48e-412c-4a76-a7a1-a6751652908a%40googlegroups.com.
tony