Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

GreasemonkeyJavaScript Copy to Clipboard button

By: a guest on Feb 28th, 2012  |  syntax: None  |  size: 0.92 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <SCRIPT LANGUAGE="JavaScript">
  2.     <!-- Begin
  3.     function copyit(theField) {
  4.     var selectedText = document.selection;
  5.     if (selectedText.type == 'Text') {
  6.     var newRange = selectedText.createRange();
  7.     theField.focus();
  8.     theField.value = newRange.text;
  9.     } else {
  10.     alert('Alert: Select The text in the textarea then click on this button');
  11.     }
  12.     }
  13.     // End -->
  14.     </script>
  15.     <input onclick="copyit(this.form.text_select)" type="button" value="Click Here to Copy the Highlighted Text" name="copy_button">
  16.        
  17. var tc = textToCopy.replace(/nn/g, 'n');
  18. if (window.clipboardData) // IE
  19. {
  20.   window.clipboardData.setData("Text", tc);
  21. }
  22. else
  23. {
  24.   unsafeWindow.netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
  25.   const clipboardHelper = Components.classes
  26.       ["@mozilla.org/widget/clipboardhelper;1"].
  27.       getService(Components.interfaces.nsIClipboardHelper);
  28.   clipboardHelper.copyString(tc);
  29. }