Thanks Lin, I added this to TW-Scripts (will appear next month online)
Best wishes Mohammad On Sat, Apr 11, 2020 at 8:00 PM Lin Onetwo <[email protected]> wrote: > Thank you Eric, that works! > > And @Mohammad I have updated my userscript, fix some bug in it > > // we won't do copy on select on text editor, otherwise you can't select and > override text in the editor or text inputfunction > 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 scriptlet 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 > updocument.addEventListener('mouseup', function onMouseUp() { > const elementsUnderMouse = document.querySelectorAll(':hover'); > > if ( > copyOnSelectPreventNextCopy || > !elementsUnderMouse || > Array.from(elementsUnderMouse).some(checkIfElementIsEditor) > ) { > copyOnSelectPreventNextCopy = false; > return; > } > document.execCommand('copy'); > }); > > > 在 2020年4月11日星期六 UTC+8下午4:26:04,Eric Shulman写道: >> >> On Saturday, April 11, 2020 at 12:08:15 AM UTC-7, Lin Onetwo wrote: >>> >>> 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 >>> >> >> 1) added <script> ... </script> around your code >> 2) tag the tiddler with $:/tags/RawMarkup >> 3) save-and-reload your document >> >> What this does is to add the content of the tagged tiddler to the bottom >> of the <head> section of the document. >> This allows your JS code to be invoked as soon as the document is loaded, >> even before the TWCore wiki is initialized >> >> (see https://tiddlywiki.com/#SystemTag%3A%20%24%3A%2Ftags%2FRawMarkup) >> >> enjoy, >> -e >> >> -- > 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 [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/tiddlywiki/56f2c48e-412c-4a76-a7a1-a6751652908a%40googlegroups.com > <https://groups.google.com/d/msgid/tiddlywiki/56f2c48e-412c-4a76-a7a1-a6751652908a%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/CAAV1gMCAKhxR71s4Y3_%3DaqXQ6ozqaWYE%2BG%3D0JJs-UL3SN%2BWG8Q%40mail.gmail.com.

