A small icon will prompt up after you selected some text, move the cursor over the icon will copy the selected text to clipboard
< Rückmeldungen auf hover_autocopy
// ==UserScript==
// @id hover_autocopy@userscript.org
// @name hover_autocopy
// @version 1.0
// @namespace hover_autocopy@userscript.org
// @description A small icon will prompt up after you selected some text, move the cursor over the icon will copy the selected text to clipboard
// @include /^https?|file.*/
// @icon https://mediacru.sh/lJD7Ki1bV9ow.png
// @run-at document-end
// @grant GM_setClipboard
// ==/UserScript==
if (typeof GM_setClipboard != 'function') alert('Your UserScript client has no GM_setClipboard support');
var delay = 3000, div = document.createElement('div'), style = document.createElement('style'), stext;
var css = '\
#copytext {\
background-image: url(https://mediacru.sh/lJD7Ki1bV9ow.png);\
background-repeat: no-repeat;\
background-size: 100% 100%;\
display: none;\
height: 32px;\
position: fixed;\
width: 32px;\
z-index: 10000;\
}\
';
div.setAttribute('id', 'copytext');
document.body.appendChild(div);
style.innerHTML = css;
document.body.appendChild(style);
document.addEventListener('mouseup', function(e) {
if (e.button != 0 || !e.target) return;
if (e.target.nodeName.match(/TEXTAREA|INPUT/)) {
var sel = document.activeElement, textarea = sel.value.substring(sel.selectionStart, sel.selectionEnd);
stext = textarea;
} else stext = getSelection().toString();
if (stext) {
div.style.display = "block";
div.style.left = (e.clientX - 20) + 'px';
div.style.top = (e.clientY - 44) + 'px';
setTimeout(function() {div.style.display = "none"}, delay);
} }, false);
div.addEventListener('mouseover', function(e) {
div.style.display = "none";
GM_setClipboard(stext);
var sel = document.activeElement;
sel.selectionStart = sel.selectionEnd;
}, false);
hover_copy_input&textarea_fix_by_Jixun.patch
26a27,29 > // Fix: shared storage in memory > var stext, prevTimer = 0; > 28a32,33 > clearTimeout (prevTimer); > 30,31c35,42 < if (e.button != 0) return; < var stext = getSelection().toString(); --- > if (e.button != 0 || !t) return; > > stext = ['INPUT', 'TEXTAREA'].indexOf (t.tagName) == -1 > // If is not textbox or textarea, > ? document.getSelection().toString() > // ... or is it? > : t.value.substring(t.selectionStart, t.selectionEnd); > 37c48 < setTimeout(function() { --- > prevTimer = setTimeout(function() { 45a57,58 > clearTimeout (prevTimer); > 48c61 < if (e.button == 0) GM_setClipboard(getSelection().toString()); --- > if (e.button == 0) GM_setClipboard(stext);
Or, the patched version as shown below.
// ==UserScript== // @id hover_autocopy@userscript.org // @name hover_autocopy // @version 1.0 // @namespace hover_autocopy@userscript.org // @description A small icon will prompt up after you selected some text, move the cursor over the icon will copy the selected text to clipboard // @include http* // @include file* // @run-at document-end // @grant GM_setClipboard // ==/UserScript== var icon_delay = 3000; // if (typeof GM_setClipboard != 'function') alert('Your UserScript client has no GM_setClipboard support'); var icon_css = '#copytext_icon{\ background-image:url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAYCAYAAAGabn0pAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAIGNIUk0AAHolAACAgwAA+f8AAIDpAAB1MAAA6mAAADqYAAAXb5JfxUYAAAMxSURBVHjaLMkxCoAwAASwnF+t0HcJ7eInz8FugaQtuOcAVxJJ3vXs4t+DwgcAAP//Yvz//z9M+X8GBgZGZBUMyWlJDEwMDAyCSILlAAAAAP//YkAD/5E5yWlJDCxoku8ZGBj+J6clwcQYsemEu+j///8MAAAAAP//YoR5BMkz5QwMDHsYGBjOMiLpusvAwKCcnJYEU83IhCSpxMDA8H/urHmMDAwMrgwMDHCHKUEFdiO54T0jNu8wMDAwwow3xubi////MwAAAAD//3SS0QnDMAxEnzNCVvAqzQhdoIF2hHSEZAWDvUhWyAwZIStcf2SQG3wgEEJCpzs1bD2qDW5gA55ArMVqkY81hKCcinIqMp6fnMrXuC83JXt2GCbTDrslAufw13S5g6Or78DD8tE0bzZf7kN6iMA5v1+HCcniPFfnF5qQhCR+AAAA//+UlE0OgjAQhT/YY+IWd14Bj4CJxjUcQBM8ghxBjwAJHICd0aVH0CPgXhaayAFwM01qqSFO0vQnfZ3Oe6+1sm0wrfPwxZHLcIzFsr2wsR0BleiabpJ1DcRABtyLvIyV722ZK+l3wBWYFnl5E7mif64dNI8mAyjy8iU6h7/AoYk+Hc9bbZqK5taaO03PWi0uVwv8id/jyjFYfcrpB2/kde277QHEnhdg7hrPHGAPmEC9pFSNHSPrUOjZZ7qvOyCxcKC3QH1bypnWDaK3zduBAn9YrXYUhIEg+rBKbandNmrtGQKKtQHbCHqEeARzhCwktcQjmCMkIOnNFWzTaTOBcdmf4sAW2Z3s7Jt583aNSuKhLjpycRKllB+tjfAfSyhoyvKY6Dhn6ylTj6nWAQj3h3hJ61Uui5AKmRBbAGCcy+LJ7h9vxKZTCwCP9t6WpBTRsJDLIgVwpc/6V8RORQ2C4NL3/U6dJwUSdIjom8CZhupam0wnWG9WNpcTccAZmAdtFNKcDf9Uw33OUHP/aCjByMJSjvTIXy/zxczGhxufUOpdUuq1iG2IfO0D+f4Qc3nr+KuCB+VKUzt692UZ2YcGkmJx2RPkZNqg1LB6S+r+8hgPAEIN7OrjhtL21MxLj5RLYnOnLrwHAF7uNkmwOR4MAAAAAElFTkSuQmCC");\ background-repeat:no-repeat;background-size:100% 100%;\ position:fixed;width:20px;height:20px;z-index:10000;display:none}' var icondiv = document.createElement('div'); icondiv.setAttribute('id', 'copytext_icon'); document.body.appendChild(icondiv); var iconcss = document.createElement('style'); iconcss.innerHTML = icon_css; document.body.appendChild(iconcss); // Fix: shared storage in memory var stext, prevTimer = 0; document.addEventListener('mouseup', function(e) { clearTimeout (prevTimer); var t = e.target; if (e.button != 0 || !t) return; stext = ['INPUT', 'TEXTAREA'].indexOf (t.tagName) == -1 // If is not textbox or textarea, ? document.getSelection().toString() // ... or is it? : t.value.substring(t.selectionStart, t.selectionEnd); // console.log(stext); if (stext) { icondiv.style.display = "block"; icondiv.style.left = (e.clientX - 20) + 'px'; icondiv.style.top = (e.clientY - 40) + 'px'; prevTimer = setTimeout(function() { icondiv.style.display = "none" }, icon_delay); } }, false); icondiv.addEventListener('mouseover', function(e) { clearTimeout (prevTimer); icondiv.style.display = "none"; // console.log(getSelection().toString()); if (e.button == 0) GM_setClipboard(stext); }, false);
Thankyou soooo much both of you ❤srazzano❤ and JixunMoe.
They both work perfectly for TEXTAREA and Searchbars!
I like both Icons but I will stick with my red one because it stands out more to find.
I did attempt to request the enhancements with the original author awhile ago and got no response.
It seems to me that srazzano's code is very different from the original, and it does contain the 2 enhancements (textarea/searchbox)... which minds me to think it can be posted for others with a new title name (Copy SelectedText ?) and with the author as srazzano.
But not sure how all that works.
So glad to see you around here srazzano.
I would miss you too much if you were gone too long.
Both of you...
What I added to my version was to unselect the text in the textarea, after the copy-text icon is hovered, as to eliminate the copy-text icon from re-emerging on etnry back into the textarea.
You're welcome, glad to see it works.
What I added to my version was to unselect the text in the textarea
Oh... I did not notice that. I see that now.
Will observe that more. Thanks srazzano ❤!
I test the Srazzano script but i have a Alert Popup about:
// @grant GM_setClipboard
which say :
"Your UserScript client has no GM_setClipboard support"
Why ?
Normally it should work , no ?
Strangely, the orginal script (which work perfectly) have the same grant rule don't show this alert ....
Firefox 48.0.2
Please add autocopy to textarea
Ort...
Could you please add the ability for the auto copy to function inside compose textboxes?
I do much copy text and move it around when composing for posts.
Example: This greasyfork compose textbox. (textarea)
And maybe the option to copy from Searchboxes.
Thankyou.