Skip to content
This repository

implement GM_setClipboard #1514

Closed
0rt opened this Issue February 09, 2012 · 12 comments

5 participants

dindog xioimwy Skeeve arantius janekptacijarabaci
dindog

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

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

dindog

It's simple, a naive implement:
0rt@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 :) )

dindog

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

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

Skeeve

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

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

Skeeve

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;\
}\
');

arantius
Collaborator

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.

janekptacijarabaci

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

arantius
Collaborator

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
arantius
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.