implement GM_setClipboard #1514

Closed
0rt opened this Issue Feb 9, 2012 · 15 comments

Comments

Projects
None yet
7 participants

0rt commented Feb 9, 2012

useful for return string result for users. It's considerable safe than current hack like bind onclick event with UniversalXPConnect then grant the privilege.

xioimwy commented Apr 16, 2012

This would be very good addition. Simple but useful. Please add.

0rt commented Sep 1, 2012

It's simple, a naive implement:
0rt/greasemonkey@f249439

Many works will greatly benefit from able to save string to clipboard ( you see how many site take Flash as work-around to let them access the clipboard :) )

0rt commented Sep 1, 2012

Scriptish's version is more sophisticated, it provide HTML rich-text support, but won't be hard to implement anyway, even plain string would be more than useful

https://github.com/scriptish/scriptish/wiki/GM_setClipboard

Skeeve commented Mar 18, 2013

Now that FireFox has removed this UniversalXPConnect stuff, I'd love to see GM_setClipboard.

Skeeve commented Mar 18, 2013

I tried to apply your changes to my GreasMonkey but all I see in the javascript console, when I use GM_setClipboard is:
ReferenceError: GM_setClipboard is not defined @ ...

Skeeve commented Mar 18, 2013

Update: My Fault! It worked but I tried to call it from within the page, where it's no longer known.

Skeeve commented Mar 19, 2013

I strongly support your proposal!

Here is an example GM script which will place a small clipboard icon in the upper left window corner. When clicking on it, it will take the current location URL, which is in my case an ugly SharePoint URL, changes it a bit and places it into the clipboard. I often used this as a Bookmarklet, but since FF19 (or 17?) it's no longer possible to access the clipboard. So here we have an alternative.

// ==UserScript==
// @name URL to Clipboard
// @namespace ClipboardCopy
// @include http://sharepoint.*
// @include https://sharepoint.*
// @grant GM_setClipboard
// @grant GM_addStyle
//
// ==/UserScript==

var clipboardsrc='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8%2F9hAAAABmJLR0QAAAAAAAD5Q7t%2FAAABQElEQVQ4y62TzUoCURTHfzPOBNoDRC3c10OU1KpScNXCFkKzigoCwV1PIEKY%2BAAKd9EqaBu07A0SIsyIPhRXgeHk3HtbDIkyenPRf3Xu%2BfhxzuFcMKhSrelKtaZNObYpmNpY5y8544%2BP51sNcHndBMCyLDLpXSDsYi%2BzCkC9mqNYercigLubc7IHV6yFeXQ6XRYTCdI727Se2iwlU5SKK7M7GHx1AbhvNke%2BcXtrM2UeYeh%2FAnBydBhJLDsOTPFPLFEGg6mLkp7HaT4fQkwArWRoxONIzxsVx4QgJgSFIDCPoLWm7DjkbJtlIZBAt9FAKEX24RFabTNASk0hCEII8FKvA7D%2F%2BsYsTQJUeHQjiG2T6PUwKdIBgO%2F7HPf7zKMJQCA1Silc152rOAIAuDhLGgsWXJvvoZoOGA%2BY9PsP%2FkU%2F50d335jMQX4AAAAASUVORK5CYII%3D';
var body = document.getElementsByTagName('body')[0];
if (!body) { return; }
var img= document.createElement('img');
img.src= clipboardsrc;
img.setAttribute("class", 'clipboard_image');
img.setAttribute("title", 'Copy url of main frame');
img.addEventListener("click", function(){
GM_setClipboard(
encodeURI(
decodeURIComponent(
window.location.href.replace(
/\b(DispForm.aspx?ID=\d+)&./, "$1"
).replace(
/^(https?://[^/]+).
\bRootFolder=/, "$1"
).replace(
/&.*/, ''
)
)
)
)
}, false);
body.appendChild(img);

GM_addStyle('
img.clipboard_image {
padding: 0px;
border: 2px;
position: fixed;
top: 0px;
left: 0px;
cursor:pointer;
}
');

Collaborator

arantius commented Mar 19, 2013

Support for this feature seems strong. Moved it into the next release milestone. It might get bumped, but that means it's in the plans.

Contributor

janekptacijarabaci commented Mar 22, 2013

Thanks and me too.
Btw, also Tampermonkey supports GM_setClipboard.

Collaborator

arantius commented May 23, 2013

Set clipboard is not mentioned in Tampermonkey's forums nor documentation about their APIs.

But it is in their source:
http://code.google.com/p/tampermonkey/source/browse/trunk/src/environment.js?r=91#1030
http://code.google.com/p/tampermonkey/source/browse/trunk/src/environment.js?r=91#1126

Signature appears to be function(data, type, callback). Data and callback are clear; "text" is supported for type but I don't know what else would be, and I can't find any decent Chrome docs about the underlying API either.

https://github.com/scriptish/scriptish/wiki/GM_setClipboard
Scriptish has a version that accepts text and html for type.

@arantius arantius closed this in 4523f8f May 23, 2013

Collaborator

arantius commented Jun 7, 2013

This feature is now in 1.10beta1; let me know if it works for you:
https://addons.mozilla.org/en-US/firefox/addon/greasemonkey/versions/?page=1#version-1.10beta1

Drezzler commented Aug 2, 2015

Is this feature actually working ?

Contributor

Ventero commented Aug 2, 2015

@Drezzler: Seems to be working just fine for me with GM 3.3 (and current git HEAD) in FF39.

Drezzler commented Aug 3, 2015

hmm , i am having a hard trying to get it work even with static text ...I am on windows 8.1 and using firefox 38.0.5 , upgrading firefox to FF39 now though .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment