Search code examples
firefox-addongreasemonkey

GM_setClipboard not copying to clipboard


I am working on a GreaseMonkey script that grabs a cookie and copies it to the clipboard. It is grabbing the cookie correctly, but not copying it to my clipboard.

// ==UserScript==
// @name           The OW Helper
// @namespace      You
// @version        1.0
// @include        *.outwar.com/*
// @exclude        *.outwar.com/myaccount*

// @require        http://code.jquery.com/jquery-latest.js
// @grant          GM_setClipboard

// ==/UserScript==


    var sessid = document.cookie.split('rg_sess_id=')[1].split(';')[0];
    var btn1 = document.createElement("button");
    btn1.appendChild(document.createTextNode("COPY RG_SESS_ID"));
    btn1.setAttribute('title', sessid);
    btn1.setAttribute('style', 'font-family: "Verdana" !important; background-color: inherit; width:160px; padding:4px; margin-bottom: 1px; color: #FFF !important; font-weight:bold !important; border:1px; cursor: pointer;');
    btn1.addEventListener('mouseover', function() {
        this.title = sessid
    }, false);
    btn1.addEventListener("click", function() {
        GM_setClipboard(sessid, "text")
    }, false);


    $("div#accordian ul li").last().append("<li><hr color=#C50202></li>");
    $("div#accordian ul li").last().append(btn1);
    $("div#accordian ul li").last().append("<li><hr color=#C50202></li>");

What am I missing here? I've searched other posts but nothing seems to have this issue and I can't seem to find anything that i haven't included.


Solution

  • If you are using GM4 (e.g. current GreaseMonkey), then GM_setClipboard is not supported and you should use GM.setClipboard.