Clipboard Contents

Clipboard Contents

Postby srazzano » Fri Mar 11, 2016 1:13 am

Image Clipboard Contents
Updated Apr. 15, 2017 (Removed button's textbox click function).
Updated Apr. 18, 2017 (Added filepicker, in settings, to select toolbarbutton image).
Tested and coded with Waterfox 52.0.1 browser.

This will insert a textbox on right-side of the button, left-side of the button, before urlbar, inside and end of urlbar, or after urlbar, with your clipboard contents, as it occurs.
  • Textbox auto hides/shows depending if there is any clipboard content to display, assuming it is not user hidden
  • Left-click button to hide/show textbox, state is remembered during restarts
  • Middle-click button to clear clipboard
  • Toolbar button on hover will display full clipboard contents in tooltip
  • After dragging button from palette, may need a restart to display button
  • If button relocated, may need to restart to get the textbox to align
  • Set textbox css preferences in the Help tab section
  • Set tooltip css preferences in the script
  • Ctrl + left-click button for Settings dialog
Last edited by srazzano on Thu May 11, 2017 11:36 pm, edited 99 times in total.
srazzano
 
Posts: 1508
Joined: Sat Mar 31, 2012 6:42 pm
Location: Las Vegas, Nevada

Re: Clipboard Contents

Postby BarbieBarb » Tue Mar 15, 2016 11:34 pm

Awesome Custombutton !
Thankyou sooo very much srazzano !
I didn't even think it was possible but you made it possible !
Just a quick glance up to the toolbar and I can see what is in My Clipboard
without having to slide the mouse all the way up to a toolbarbutton and click/hover for results.
Saves me a lot of wasted time as I check on My Clipboard many many times each session.
DISCUSSION viewtopic.php?f=2&t=3701&start=30

Image
BarbieBarb
 
Posts: 751
Joined: Thu Jun 14, 2012 6:14 am

Re: Clipboard Contents

Postby BarbieBarb » Mon Jul 11, 2016 10:25 pm

srazzano
I just upgraded from FF46 to FF48(official version) and this Clipboard Contents custombutton (and several others) are broken.
Is there a fix for this please?
Thankyou

My version if needed (copy to clipboard is not functioning )
Initialization code
Code: Select all
"use strict"; //*** Ctrl + left-click (Button or Textbox) for Settings dialog ***\\

const TYPE_REPEATING_SLACK = Ci.nsITimer.TYPE_REPEATING_SLACK,
  aTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer),
  ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService),
  sss = Cc["@mozilla.org/content/style-sheet-service;1"].getService(Ci.nsIStyleSheetService),
  wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator),
  helpTab = encodeURIComponent(this.Help.split("/*** Textbox CSS ***/\n")[1]),
  aId = this.id,
  aLabel = this.label,
  buttonTooltip = ":  LeftClick=Hide/ShowTEXTBOX   MidClick=ClearClipboard\n\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\
\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\
\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\
\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584",
  textboxTooltip = ":  LeftClick=Hide/ShowBUTTON   MidClick=ClearClipboard\n\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\
\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\
\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\
\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584",
  captionLabel = "Position Textbox",
  settingsTitle = "Clipboard Contents Settings",
  tooltipThemeLabel = "Tooltip Theme",
  radio1Lbael = "Before Button",
  radio2Lbael = "After Button",
  radio3Lbael = "Before Urlbar",
  radio4Lbael = "In/End Urlbar",
  radio5Lbael = "After Urlbar",
  widthLabel = "Textbox Width (in pixels)",
  autoHideLabel = "Hide Textbox When Clipboard Is Empty";
 
var css = new String();

//*** Tooltip CSS, do not remove the back slashes "\" and ensure each new line ends with one ***\\
css = '@namespace url("' + xulns + '");\
  tooltip[label^="' + aLabel + '"] {\
    -moz-appearance: none !important;\
    border: 1px solid #CCC !important;\
    background: beige !important;\
    color: black !important;\
    font-family: monospace !important;\
    padding: 10px !important;\
  }\
';
var cssTooltip = encodeURIComponent(css),
  bar = this.parentNode,
  cont = document.getElementById("urlbar-container"),
  url = document.getElementById("urlbar"),
  textbox = document.createElement("textbox");

pref.root = "extensions.custombuttons.Clipboard_Contents.";
pref.defaults = {
  hideButton: false,
  hideText: false,
  tooltipTheme: true,
  autoHide: false,
  textboxWidth: 80,
  positionText: 2,
  positionLeft: 0,
  positionTop: 0
}

for (let key in pref.defaults) {
  if (pref.defaults.hasOwnProperty(key)) {
    let val = pref.defaults[key];
    switch (typeof val) {
      case "boolean":
        Services.prefs.getDefaultBranch(pref.root).setBoolPref(key, val);
        break;
      case "number":
        Services.prefs.getDefaultBranch(pref.root).setIntPref(key, val);
        break;
      case "string":
        let str = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString);
        str.data = val;
        Services.prefs.getDefaultBranch(pref.root).setComplexValue((key), Ci.nsISupportsString, str);
        break;
} } }

pref.observe = function(prefs, callback) {
  let {root} = pref;
  function observe(subject, topic, data) {
    if (topic != "nsPref:changed") return;
    let pref = data.slice(root.length);
    if (prefs.indexOf(pref) == -1) return;
    callback(pref);
  }
  Services.prefs.addObserver(root, observe, false);
  unload => Services.prefs.removeObserver(root, observe);
}

function pref(key) {
  let {branch, defaults} = pref;
  if (branch == null) branch = Services.prefs.getBranch(pref.root);
  switch (typeof defaults[key]) {
    case "boolean": return branch.getBoolPref(key);
    case "number": return branch.getIntPref(key);
    case "string": return branch.getCharPref(key);
  }
  return null;
}

function getSS(filepath) {
  return ios.newURI("data:text/css," + filepath, null, null);
}

function loadSheet(filepath) {
  sss.loadAndRegisterSheet(getSS(filepath), sss.AGENT_SHEET);
}

function loadAndObserve(prefName, filepath) {
  if (pref(prefName)) loadSheet(filepath);
  pref.observe([prefName], function() {pref(prefName) ? loadSheet(filepath) : unloadSheet(filepath);});
  unload => unloadSheet(filepath);
}

function unloadSheet(filepath) {
  let uri = getSS(filepath);
  if (sss.sheetRegistered(uri, sss.AGENT_SHEET)) sss.unregisterSheet(uri, sss.AGENT_SHEET);
}

function unload(callback, container) {
  let unloaders = unload.unloaders;
  if (unloaders == null) unloaders = unload.unloaders = [];
  if (callback == null) {
    unloaders.slice().forEach(unloader => unloader());
    unloaders.length = 0;
    return;
  }
  if (container != null) {
    container.addEventListener("unload", removeUnloader, false);
    let origCallback = callback;
    callback = function() {
      container.removeEventListener("unload", removeUnloader, false);
      origCallback();
  } }
  function unloader() {
    try {
      callback();
    } catch(ex) {}
  }
  unloaders.push(unloader);
  function removeUnloader() {
    let index = unloaders.indexOf(unloader);
    if (index !== -1) unloaders.splice(index, 1);
  }
  return removeUnloader;
}

function removeDupe(aClass) {
  var dupe = document.getElementsByClassName(aClass);
  for (var i = 1; i < dupe.length; i++) dupe[i].parentNode.removeChild(dupe[i]);
}

function gPref(pref, id) {
  if (gClipboard.read("text") !== "") {
    var bol = gRoot.getBoolPref(pref) !== false ? false : true;
    gRoot.setBoolPref(pref, bol);
    document.getElementById(id).collapsed = bol;
} }

function getSettings() {
  var data = '<?xml version="1.0"?><?xml-stylesheet href="chrome://global/skin/" type="text/css"?>\
    <window xmlns="' + xulns + '" id="clipboard-contents" windowtype="clipboard:contents" title="' + settingsTitle + '" \
      onload="self.onLoad(this)" onblur="close()" onclose="self.onClose(this)" persist="width height">\
      <groupbox id="groupbox1">\
        <caption id="captionLabel" label="' + captionLabel + '"/>\
        <hbox id="hbox1" class="hbox" align="center" pack="center">\
          <radiogroup id="positionText" value="' + pref("positionText") + '" onclick="self.onRadio(this)">\
            <hbox id="hbox1a" class="hbox" align="center" pack="center">\
              <radio id="radio1" class="radio" label="' + radio1Lbael + '" value="1"/>\
              <radio id="radio2" class="radio" label="' + radio2Lbael + '" value="2"/>\
            </hbox>\
            <hbox id="hbox1b" class="hbox" align="center" pack="center">\
              <radio id="radio3" class="radio" label="' + radio3Lbael + '" value="3"/>\
              <radio id="radio4" class="radio" label="' + radio4Lbael + '" value="4"/>\
              <radio id="radio5" class="radio" label="' + radio5Lbael + '" value="5"/>\
            </hbox>\
          </radiogroup>\
        </hbox>\
      </groupbox>\
      <hbox id="hbox2" class="hbox" align="center" pack="center">\
        <label id="widthLabel" value="' + widthLabel + '"/>\
        <textbox id="textboxWidth" value="' + pref("textboxWidth") + '" oninput="self.onTextbox(this)"/>\
        <checkbox id="tooltipTheme" label="' + tooltipThemeLabel + '" checked="' + pref("tooltipTheme") + '" oncommand="self.onCheckbox(this)"/>\
      </hbox>\
      <hbox id="hbox3" class="hbox" align="center" pack="center">\
        <checkbox id="autoHide" label="' + autoHideLabel + '" checked="' + pref("autoHide") + '" oncommand="self.onCheckbox(this)"/>\
      </hbox>\
    </window>';
  data = data.replace(/self/g, "opener.document.getElementById('" + self.id + "')");
  var url = "data:application/vnd.mozilla.xul+xml;text/plain," + encodeURIComponent(data);
  window.openDialog(url, "_blank", "chrome,dialog,resizable");
}

textbox.id = "textbox-content";
textbox.className = "textbox-content";
textbox.width = pref("textboxWidth");

switch (pref("positionText")) {
  case 1: bar.insertBefore(textbox, this); break;
  case 2: bar.insertBefore(textbox, this.nextElementSibling); break;
  case 3: cont.insertBefore(textbox, cont.firstChild); break;
  case 4: url.insertBefore(textbox, url.lastChild.nextElementSibling); break;
  case 5: cont.insertBefore(textbox, cont.lastChild.nextElementSibling); break;
}

removeDupe("textbox-content");

var onTimer = {
  notify: function (aTimer) {
    document.getElementById("textbox-content").textContent = gClipboard.read("text");
    if (gClipboard.read("text") === "" && pref("autoHide")) document.getElementById("textbox-content").collapsed = true;
    else document.getElementById("textbox-content").collapsed = false;
    if (pref("hideText")) document.getElementById("textbox-content").collapsed = true;
    if (gClipboard.read("text") !== "" && !pref("hideText")) document.getElementById("textbox-content").collapsed = false;
} }

aTimer.initWithCallback(onTimer, 100, TYPE_REPEATING_SLACK);

var gRoot = Services.prefs.getBranch(pref.root);

if (pref("hideButton") && pref("hideText")) {
  gRoot.setBoolPref("hideButton", false);
  gRoot.setBoolPref("hideText", false);
}

document.getElementById(aId).collapsed = pref("hideButton");
document.getElementById("textbox-content").collapsed = pref("hideText");

loadSheet(helpTab);
loadAndObserve("tooltipTheme", cssTooltip);

var btn = '\
  tooltip[label^="' + aLabel + '"] {\
    max-width: none !important;\
  }\
  *[customizing] %23' + aId + ' {\
    visibility: visible !important;\
  }\
';
loadSheet(btn);

this.onLoad = function(e) {
  e.moveTo(pref("positionLeft"), pref("positionTop"));
}

this.onCheckbox = function(e) {
  var bool = pref(e.id) != true ? true : false;
  gRoot.setBoolPref(e.id, bool);
}

this.onRadio = function(e) {
  var mrw = wm.getMostRecentWindow("navigator:browser");
  gRoot.setIntPref(e.id, e.value);
  var parent = mrw.document.getElementById("textbox-content").parentNode,
    child = mrw.document.getElementById("textbox-content");
  parent.removeChild(child);
  switch (pref("positionText")) {
    case 1: bar.insertBefore(textbox, this); break;
    case 2: bar.insertBefore(textbox, this.nextElementSibling); break;
    case 3: cont.insertBefore(textbox, cont.firstChild); break;
    case 4: url.insertBefore(textbox, url.lastChild.nextElementSibling); break;
    case 5: cont.insertBefore(textbox, cont.lastChild.nextElementSibling); break;
    default: bar.insertBefore(textbox, this.nextElementSibling);
} }

this.onTextbox = function(e) {
  var mrw = wm.getMostRecentWindow("navigator:browser");
  e.value = e.value.replace(/[^\d+]/g, "");
  gRoot.setIntPref(e.id, e.value);
  mrw.document.getElementById("textbox-content").width = e.value;
}

this.onclick = function (e) {
  if (e.button === 0 && e.ctrlKey) getSettings();
  if (e.button === 0 && !e.ctrlKey) gPref("hideText", "textbox-content");
  if (e.button === 1) gClipboard.write("");
}

textbox.onclick = function (e) {
  if (e.button === 0 && e.ctrlKey) getSettings();
  if (e.button === 0 && !e.ctrlKey) gPref("hideButton", aId);
  if (e.button === 1) gClipboard.write("");
  if (e.button === 2)  e.preventDefault();
}

this.onmouseover = function () {
  var text = gClipboard.read("text");
  this.tooltipText = text ? aLabel + buttonTooltip + "\n\n" + text : aLabel + " (Empty)";
}

textbox.onmouseover = function () {
  var text = gClipboard.read("text");
  textbox.tooltipText = text ? aLabel + textboxTooltip + "\n\n" + text : aLabel + " (Empty)";
}

textbox.onmousedown = function () { return false; }

this.onClose = function(e) {
  gRoot.setIntPref("positionLeft", e.screenX);
  gRoot.setIntPref("positionTop", e.screenY);
}

this.onDestroy = function (reason) {
  if (reason === "delete") {
    unloadSheet(cssTooltip);
    unloadSheet(helpTab);
    var parent = document.getElementById("textbox-content").parentNode, child = document.getElementById("textbox-content");
    parent.removeChild(child);
    Services.prefs.deleteBranch(pref.root);
} }


HELP Tab
Code: Select all
/*
BUTTON: Clipboard Contents (Show Clipboard Textbox
AUTHOR: srazzano
DOWNLOAD BUTTON: http://custombuttons.sourceforge.net/forum/viewtopic.php?f=4&t=3702&sid=8f9921525cb15d1dbb5204143d594dd0
DISCUSSION: http://custombuttons.sourceforge.net/forum/viewtopic.php?f=2&t=3701

Ctrl + left-click (Button or Textbox) for Settings dialog.

To move textbox on window, change:
    position: from relative to fixed
    when assigning pixel values to left: keep right: at auto and vice versa
    when assigning pixel values to top: keep bottom: at auto and vice versa
*/
 
/*===============================================================================================================*/

Do Not Remove Or Modify The Below String, Needed To Separate Comments From CSS
/*** Textbox CSS ***/
@namespace url(http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul);
#textbox-content.textbox-content {
  -moz-appearance: none !important;
  background: white !important;
  border: none !important;
  white-space: nowrap !important;
  overflow: hidden !important;
  /*text-overflow: ellipsis !important;*/

  /*============= ADDED =================================*/
  border-top: 1px solid #bbb !important;
 padding:0px !important;
 padding-bottom: 2px !important;
 padding-left: 1px !important;
 margin-left: -3px !important; margin-left: 0px !important;
 margin-top:3px !important;
 margin-bottom:3px !important;
 margin-top:5px !important;
 margin-bottom:6px !important;
  /*MOVE WHOLE CONTAINER (BUTTON AND TEXTBOX) RIGHT*/
 margin-right:-18px !important;}
 /*============= ADDED =================================*/
 
#textbox-content.textbox-content:hover {}

/*** Settings Dialog CSS ***/
#clipboard-contents {
  padding: 4px !important;}
 
#clipboard-contents .radio-label-box,
#clipboard-contents .checkbox-label-box {
  border: 1px dotted transparent !important;
  outline: none !important;}
 
#clipboard-contents #captionLabel {
  font-weight: bold !important;}
 
#clipboard-contents .radio {
  width: 100px !important;}
 
#clipboard-contents #textboxWidth {
  margin-right: 16px !important;
  text-align: center !important;
  width: 36px !important;}
 
#clipboard-contents #textboxWidth .textbox-input-box {
  margin: 0px 4px 0px 0px !important;}
 
  /*END*/




EDIT
Okay I was on FF48.0b6 ... somehow was on beta channel.
I reverted back to FF47 release and all is fine on this version... but it won't be on FF48
And also the add CSS in the Help Tab seemed to be not working correctly n FF48.
But I am sticking with FF47 for now.
SORRY
BarbieBarb
 
Posts: 751
Joined: Thu Jun 14, 2012 6:14 am

Re: Clipboard Contents

Postby mcee » Tue Jul 26, 2016 10:38 pm

I tried creating the button by pasting the above code. Did not work well. initially displayed clipboard contents but would not work again after right click. And after deleting the button it left the text box behind and so far can't remove it
mcee
 
Posts: 37
Joined: Wed Oct 29, 2014 5:49 pm

Re: Clipboard Contents

Postby BarbieBarb » Wed Jul 27, 2016 2:14 am

● Button you can LeftClick MiddleCLick or RightClick
● Textbox you can only LeftClick or MiddleClick. YOU CANNOT RightClick on the Textbox.

Button
LeftClick = hide/show textbox
MidClick = Clears the Textbox
RightClick = Opens the Context Menu
Ctrl+LeftClick = for Settings dialog

Textbox
LeftClick = hide/show toolbar button
MidClick = Clears the Textbox
RightClick DO NOT RightClick
Ctrl+LeftClick = for Settings dialog

:?: Maybe if RightClick on Textbox there can be a block where nothing happens instead of causing malfunction. Otherwise... just remember NOT to rightclick on the Textbox.
Firefox restart should re-set and fix any messup

EDIT
I think it is the RightClick and drag as in "Select Text" in the Textbox that can cause a messup.
BarbieBarb
 
Posts: 751
Joined: Thu Jun 14, 2012 6:14 am

Re: Clipboard Contents

Postby mcee » Wed Jul 27, 2016 7:07 am

It works fine as long as I only click on the button. I'm finding any kind of clicks on the textbox can eventually cause it to mess up in different ways. For me, it would be better having that textbox instead just be a label showing the first X characters from the clipboard, where X is however many characters fit in the space. Gave up and deleted it, was causing thousands of errors in browser console about text box.
mcee
 
Posts: 37
Joined: Wed Oct 29, 2014 5:49 pm

Re: Clipboard Contents

Postby LL25255252 » Thu Mar 02, 2017 10:30 pm

mcee wrote:...Gave up and deleted it, was causing thousands of errors in browser console about text box.

Me too....thousands of errors in browser console :!:

error - XUL box for textbox element contained an inline #text child, forcing all its children to be wrapped in a block.

@Sonny, If you don't have time to test/fix it maybe add a "need to be fixed" warning in the first post of this thread.
Thanks in advance.

Tested on Pale Moon 27 and also in Cyberfox 51.0.3
Win 7 x64
LL25255252
 
Posts: 20
Joined: Sat Mar 30, 2013 12:35 am

Re: Clipboard Contents

Postby srazzano » Fri Mar 03, 2017 12:40 am

Checking.
srazzano
 
Posts: 1508
Joined: Sat Mar 31, 2012 6:42 pm
Location: Las Vegas, Nevada

Re: Clipboard Contents

Postby LL25255252 » Thu Apr 13, 2017 10:23 pm

Thank you Sonny for trying to fix it.
Tried the new version.

The new version works fine ( and without "spamming" the error console) in pale Moon 27.2.1 Win 7 x64.
Not working in Waterfox 52 (or Cyberfox 52) - textbox not displayed after copying to clipboard.
LL25255252
 
Posts: 20
Joined: Sat Mar 30, 2013 12:35 am

Re: Clipboard Contents

Postby LL25255252 » Thu Apr 13, 2017 11:01 pm

LL25255252 wrote:Thank you Sonny for trying to fix it.
Tried the new version.

The new version works fine ( and without "spamming" the error console) in pale Moon 27.2.1 Win 7 x64.
Not working in Waterfox 52 (or Cyberfox 52) - textbox not displayed after copying to clipboard.

Is it really a new version or did it start to work in Palemoon because Palemoon got a new version?
LL25255252
 
Posts: 20
Joined: Sat Mar 30, 2013 12:35 am

Next

Return to Buttons made by forum users

cron