Skip to content

Instantly share code, notes, and snippets.

@satyr
Created May 5, 2009 16:09
Show Gist options
  • Save satyr/107030 to your computer and use it in GitHub Desktop.
Save satyr/107030 to your computer and use it in GitHub Desktop.
Automatically copies the selected text on Ubiquity panel.
function startup_autocopy(){function cmd_(){}
getU(autocopy);
function autocopy(U){
U.__msgPanel.addEventListener('mouseup', function copy(e){
var s = e.view.getSelection() +'';
s && CmdUtils.copyToClipboard(s);
}, true);
}
function getU(fn){
waitU(Utils.currentChromeWindow);
Cc['@mozilla.org/observer-service;1'].getService(Ci.nsIObserverService)
.addObserver({
observe: function(subject, topic, data){
subject.addEventListener('load', this, false);
},
handleEvent: function({originalTarget: doc}){
doc.removeEventListener('load', this, false);
if(doc.location.href === 'chrome://browser/content/browser.xul')
waitU(doc.defaultView);
},
}, 'toplevel-window-ready', false);
function waitU(W){
if(W.gUbiquity) fn(W.gUbiquity, W);
else Utils.setTimeout(function(){ waitU(W) }, 42);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment