-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
16 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,16 @@ | ||
{"tiddlers":{"$:/config/linonetwo/copy-on-select/CopyTimeout":{"title":"$:/config/linonetwo/copy-on-select/CopyTimeout","text":"0.6"},"$:/config/linonetwo/copy-on-select/ShowNotificationOnCopy":{"title":"$:/config/linonetwo/copy-on-select/ShowNotificationOnCopy","text":"yes"},"$:/plugins/linonetwo/copy-on-select/copy-on-select.js":{"title":"$:/plugins/linonetwo/copy-on-select/copy-on-select.js","text":"exports.name = 'copy-on-select';\nexports.platforms = ['browser'];\nexports.after = ['story'];\nexports.synchronous = true;\n\nexports.startup = function () {\n // we won't do copy on select on text editor, otherwise you can't select and override text in the editor or text input\n function checkIfElementIsEditor(element) {\n if (!element || !element.nodeName) return false;\n const isEditableElement = ['INPUT', 'TEXTAREA', 'BUTTON'].includes(element.nodeName);\n if (!isEditableElement) {\n if (!element.className || !element.className.toLowerCase) return false;\n }\n const isTextEditor = element.className.toLowerCase().includes('codemirror');\n const isSlateEditor = element.dataset.slateEditor || element.dataset.slateNode || element.dataset.slateLeaf || element.dataset.slateString;\n\n return isEditableElement || isTextEditor || isSlateEditor;\n }\n // if we start selection on editor, we prevent the following execution of this script\n let copyOnSelectPreventCopy = false;\n /** mousedown and wait for 1s to copy */\n let copyTimeoutNotDone = true;\n /** 0.6s */\n let copyTimeout = 0.6;\n let showNotification = true;\n const loadConfig = () => {\n copyTimeout = Number($tw.wiki.getTiddlerText('$:/config/linonetwo/copy-on-select/CopyTimeout', '1')) || 0.6;\n if (!isFinite(copyTimeout)) {\n copyTimeout = 0.6;\n }\n showNotification = $tw.wiki.getTiddlerText('$:/config/linonetwo/copy-on-select/ShowNotificationOnCopy') === 'yes';\n };\n let copyTimeoutHandler = 0;\n let copyReadyTimeoutHandler = 0;\n\n const cleanUp = () => {\n copyTimeoutNotDone = true;\n copyOnSelectPreventCopy = false;\n clearTimeout(copyTimeoutHandler);\n document.removeEventListener('mousemove', startCopyReadyCountDownCallback);\n };\n\n /**\n * remove the tailing \\n when copying title\n * And display a notification\n */\n const copyTextModifier = (event) => {\n const selection = document.getSelection();\n let copiedText = selection.toString();\n if (copiedText.endsWith('\\n')) {\n copiedText = copiedText.substring(0, copiedText.length - 1);\n }\n // if selection is empty, don't do anything\n if (!copiedText) return;\n event.preventDefault();\n event.clipboardData.setData('text/plain', copiedText);\n\n // DEBUG: console showNotification\n console.log(`showNotification`, showNotification);\n if (showNotification) {\n $tw.wiki.addTiddler({ title: '$:/state/notification/copy-on-select', text: `Copy\\n\\n${copiedText}` });\n $tw.notifier.display('$:/state/notification/copy-on-select');\n /** display copied text in notification */\n // const truncateLength = 30;\n // if (copiedText.length > truncateLength) {\n // copiedText = `${copiedText.substring(0, 30)} ...`;\n // }\n }\n };\n /** Copy on select, copy document selection when mouse is down for a while */\n const onCopy = () => {\n /** NodeList from root html to current element, can't get selection info. So need to use `document.execCommand('copy')` instead of copy .innerText */\n const elementsUnderMouse = document.querySelectorAll(':hover');\n\n const copyPrevented =\n copyTimeoutNotDone || copyOnSelectPreventCopy || !elementsUnderMouse?.length || Array.from(elementsUnderMouse).some(checkIfElementIsEditor);\n if (copyPrevented) {\n return;\n }\n\n // this will only work for 2 times. On 3 times, it will not get called, no way around this.\n document.addEventListener('copy', copyTextModifier);\n /** $tw.utils.copyToClipboard(copiedText); can't copy image or html h1 format */\n // does not work on safari https://stackoverflow.com/questions/71340178/combination-of-document-addeventlistener-and-document-execcommandcopy-does-n/71372287#71372287\n document.execCommand('copy');\n document.removeEventListener('copy', copyTextModifier);\n };\n\n function startCopyReadyCountDown() {\n // when mouse move, reset the timeout, so we won't copy while user still selecting\n document.addEventListener('mousemove', startCopyReadyCountDownCallback);\n }\n function startCopyReadyCountDownCallback() {\n clearTimeout(copyTimeoutHandler);\n copyTimeoutHandler = setTimeout(onCopy, copyTimeout * 1000);\n }\n\n document.addEventListener('mousedown', () => {\n const elementsUnderMouse = document.querySelectorAll(':hover');\n\n if (!elementsUnderMouse?.length || Array.from(elementsUnderMouse).some(checkIfElementIsEditor)) {\n copyOnSelectPreventCopy = true;\n } else {\n copyOnSelectPreventNextCopy = false;\n // if hold mouse till copyTimeout, means timeout done, then \"not done\" is false\n copyTimeoutNotDone = false;\n loadConfig();\n startCopyReadyCountDown();\n }\n });\n\n document.addEventListener('mouseup', () => {\n cleanUp();\n });\n};\n","creator":"LinOnetwo","type":"application/javascript","module-type":"startup"},"$:/plugins/linonetwo/copy-on-select/readme":{"title":"$:/plugins/linonetwo/copy-on-select/readme","created":"20200414135748497","modified":"20200602062349232","creator":"LinOnetwo","type":"text/vnd.tiddlywiki","text":"Copy what you are selecting inside the wiki into the clipboard when holding mouse for 1 second\n\n!! 动机 Motivation\n\n我已经习惯了用方便的[[Copy On Select|https://addons.mozilla.org/en-US/firefox/addon/copy-on-select]] Firefox 插件,现在到了 TiddlyWiki 里我经常还是以为选中了就复制了,然后黏贴到别的地方才发现其实并没有复制,很不习惯。\n\n所以我自己重新写了一个适配 TiddlyWiki 的选中即复制脚本。\n\nI've gotten used to using the handy [[Copy On Select|https://addons.mozilla.org/en-US/firefox/addon/copy-on-select]] Firefox plugin, but now in TiddlyWiki I often still think I've copied it when I select it, and then I found out that I hadn't copied it until I pasted it somewhere else, which was very uncomfortable.\n\nSo I rewrote my own copy-on-selection script for TiddlyWiki.\n\n!! 用法 Usage\n\n选中编辑器、按钮等区域以外的任何文本,并保持按住鼠标一秒,就复制选中的内容。\n\n这个插件里的条件语句让它在编辑器等特殊区域内不会起作用,以免干扰「全选黏贴覆盖原有内容」等操作。\n\nSelect any text outside the editor, buttons, etc., and hold the mouse down for a second to copy the selected content.\n\nThe conditional statement in this plugin makes it not work in special areas like the editor, so as not to interfere with operations like \"select all and paste overwrite\".\n"},"$:/plugins/linonetwo/copy-on-select/settings":{"title":"$:/plugins/linonetwo/copy-on-select/settings","text":"<$edit-text tag=input tiddler=\"$:/config/linonetwo/copy-on-select/CopyTimeout\" field=\"text\" /> <$link to=\"$:/config/linonetwo/copy-on-select/CopyTimeout\">When mouse stop moving for how many second, starts copy.</$link> \n\n<$checkbox tiddler=\"$:/config/linonetwo/copy-on-select/ShowNotificationOnCopy\" field=\"text\" checked=\"yes\" unchecked=\"no\" default=\"no\"> <$link to=\"$:/config/linonetwo/copy-on-select/ShowNotificationOnCopy\">Show Notification On Copy</$link> </$checkbox>\n"}}} | ||
[ | ||
{ | ||
"author": "LinOnetwo", | ||
"core-version": ">=5.1.22", | ||
"dependents": "", | ||
"description": "Copy what you are selecting inside the wiki into the clipboard when holding mouse for 1 second", | ||
"list": "readme settings", | ||
"plugin-type": "plugin", | ||
"text": "{\"tiddlers\":{\"$:/plugins/linonetwo/copy-on-select/config\":{\"title\":\"$:/plugins/linonetwo/copy-on-select/config\",\"tags\":\"$:/tags/ControlPanel/SettingsTab\",\"caption\":\"Plugin Setting\",\"text\":\"These settings let you customise the behaviour of copy-on-select plugin.\\n\\n---\\n\\n!! Title\\n\\nDescription\\n\\n;Show Notification\\n:<$checkbox tiddler=\\\"$:/plugins/linonetwo/copy-on-select/configs/ShowNotificationOnCopy\\\" field=\\\"text\\\" checked=\\\"yes\\\" unchecked=\\\"\\\"> <$link to=\\\"$:/config/linonetwo/copy-on-select/ShowNotificationOnCopy\\\">Show Notification On Copy</$link></$checkbox>\\n;CopyTimeout\\n:<$edit-text tiddler=\\\"$:/plugins/linonetwo/copy-on-select/configs/CopyTimeout\\\" tabindex=-1 focus=false cancelPopups=\\\"yes\\\" fileDrop=no tag=\\\"input\\\" /> <$link to=\\\"$:/config/linonetwo/copy-on-select/CopyTimeout\\\">When mouse stop moving for how many second, starts copy.</$link>\\n\"},\"$:/config/linonetwo/copy-on-select/CopyTimeout\":{\"title\":\"$:/config/linonetwo/copy-on-select/CopyTimeout\",\"text\":\"0.6\"},\"$:/config/linonetwo/copy-on-select/ShowNotificationOnCopy\":{\"title\":\"$:/config/linonetwo/copy-on-select/ShowNotificationOnCopy\",\"text\":\"yes\"},\"$:/plugins/linonetwo/copy-on-select/readme\":{\"title\":\"$:/plugins/linonetwo/copy-on-select/readme\",\"created\":\"20200414135748497\",\"modified\":\"20200602062349232\",\"creator\":\"LinOnetwo\",\"type\":\"text/vnd.tiddlywiki\",\"text\":\"Copy what you are selecting inside the wiki into the clipboard when holding mouse for 1 second\\n\\n!! 动机 Motivation\\n\\n我已经习惯了用方便的[[Copy On Select|https://addons.mozilla.org/en-US/firefox/addon/copy-on-select]] Firefox 插件,现在到了 TiddlyWiki 里我经常还是以为选中了就复制了,然后黏贴到别的地方才发现其实并没有复制,很不习惯。\\n\\n所以我自己重新写了一个适配 TiddlyWiki 的选中即复制脚本。\\n\\nI've gotten used to using the handy [[Copy On Select|https://addons.mozilla.org/en-US/firefox/addon/copy-on-select]] Firefox plugin, but now in TiddlyWiki I often still think I've copied it when I select it, and then I found out that I hadn't copied it until I pasted it somewhere else, which was very uncomfortable.\\n\\nSo I rewrote my own copy-on-selection script for TiddlyWiki.\\n\\n!! 用法 Usage\\n\\n选中编辑器、按钮等区域以外的任何文本,并保持按住鼠标一秒,就复制选中的内容。\\n\\n这个插件里的条件语句让它在编辑器等特殊区域内不会起作用,以免干扰「全选黏贴覆盖原有内容」等操作。\\n\\nSelect any text outside the editor, buttons, etc., and hold the mouse down for a second to copy the selected content.\\n\\nThe conditional statement in this plugin makes it not work in special areas like the editor, so as not to interfere with operations like \\\"select all and paste overwrite\\\".\\n\"},\"$:/plugins/linonetwo/copy-on-select/tree\":{\"title\":\"$:/plugins/linonetwo/copy-on-select/tree\",\"type\":\"text/vnd.tiddlywiki\",\"text\":\"<<tree prefix:\\\"$:/plugins/linonetwo/copy-on-select/\\\">>\"},\"$:/plugins/linonetwo/copy-on-select/copy-on-select.js\":{\"creator\":\"LinOnetwo\",\"title\":\"$:/plugins/linonetwo/copy-on-select/copy-on-select.js\",\"type\":\"application/javascript\",\"module-type\":\"startup\",\"Modern.TiddlyDev#Origin\":\"copy-on-select.ts\",\"text\":\"\\\"use strict\\\";exports.name=\\\"copy-on-select\\\",exports.platforms=[\\\"browser\\\"],exports.after=[\\\"story\\\"],exports.synchronous=!0,exports.startup=function(){function t(e){var t,o,n;return!(!e||!e.nodeName||!((t=[\\\"INPUT\\\",\\\"TEXTAREA\\\",\\\"BUTTON\\\"].includes(e.nodeName))||e.className&&e.className.toLowerCase))&&(o=e.className.toLowerCase().includes(\\\"codemirror\\\"),n=e.dataset.slateEditor||e.dataset.slateNode||e.dataset.slateLeaf||e.dataset.slateString,t||o||n)}let o=!1,n=!0,s=.6,i=!0;let e=0;const r=e=>{let t=document.getSelection().toString();(t=t.endsWith(\\\"\\\\n\\\")?t.substring(0,t.length-1):t)&&(e.preventDefault(),e.clipboardData.setData(\\\"text/plain\\\",t),console.log(\\\"showNotification\\\",i),i)&&($tw.wiki.addTiddler({title:\\\"$:/state/notification/copy-on-select\\\",text:`Copy\\n\\n`+t}),$tw.notifier.display(\\\"$:/state/notification/copy-on-select\\\"))},a=()=>{var e=document.querySelectorAll(\\\":hover\\\");n||o||!(null!=e&&e.length)||Array.from(e).some(t)||(document.addEventListener(\\\"copy\\\",r),document.execCommand(\\\"copy\\\"),document.removeEventListener(\\\"copy\\\",r))};function c(){clearTimeout(e),e=setTimeout(a,1e3*s)}document.addEventListener(\\\"mousedown\\\",()=>{var e=document.querySelectorAll(\\\":hover\\\");null==e||!e.length||Array.from(e).some(t)?o=!0:(o=!1,n=!1,s=Number($tw.wiki.getTiddlerText(\\\"$:/config/linonetwo/copy-on-select/CopyTimeout\\\",\\\"1\\\"))||.6,isFinite(s)||(s=.6),i=\\\"yes\\\"===$tw.wiki.getTiddlerText(\\\"$:/config/linonetwo/copy-on-select/ShowNotificationOnCopy\\\"),document.addEventListener(\\\"mousemove\\\",c))}),document.addEventListener(\\\"mouseup\\\",()=>{n=!0,o=!1,clearTimeout(e),document.removeEventListener(\\\"mousemove\\\",c)})};\"}}}", | ||
"title": "$:/plugins/linonetwo/copy-on-select", | ||
"type": "application/json", | ||
"version": "1.0.0", | ||
"Modern.TiddlyDev#SHA256-Hashed": "0270b75e28342bae9f7df937e66a0548a27e29182938ee70c196970400a971d9", | ||
"name": "copy-on-select" | ||
} | ||
] |
This file was deleted.
Oops, something went wrong.