Page 1 of 1

Custom Buttons break

PostPosted: Fri Oct 09, 2015 2:04 am
by trapper john
It looks like the let and const compliancy has affected the Custom Buttons addon. It's now impossible in the latest nightly inbound to edit buttons from the toolbars and some buttons have broken. It's difficult to tell whether in addition to the break if some internal firefox commands have changed as well.

For example, the simple command "this.toggleCookieBehavior();" no longer works so I had to change it using prefBranch.getIntPref('network.cookie.cookieBehavior') instead. I also lost the ability for the button to change icons when cookies were toggled on or off.

This was the code that was used until today:

Code: Select all
var prefService = Components.classes["@mozilla.org/preferences-service;1"]
                    .getService(Components.interfaces.nsIPrefService);

var prefDomain = "network.cookie.cookieBehavior";

function pref() {
  var p = prefService.getIntPref(prefDomain);
  return p;
}

this.toggleCookieBehavior = function() {
  if(pref() == 2) {
    prefService.setIntPref(prefDomain, 1);
    this.image = "icon code";
  } else {
    prefService.setIntPref(prefDomain, 2);
    this.image = "icon code";
  }
}


If someone could help me out and restore this ability I'd appreciate it. Believe it or not, it is almost impossible to find an addon that does this anymore in current versions.

Edit: this code is probably still good. With the latest FF update some buttons that use Initialization Code are broken. Hopefully the developer will give the addon a temporary reprieve before XUL is abandoned altogether.

Re: Custom Buttons break

PostPosted: Fri Oct 09, 2015 8:07 pm
by trapper john
Thanks to the generosity of another button maker I was able to download a custom button that will toggle both cookies and the icons. Unfortunately, can't test it in the nightlies due to the breakage.

Re: Custom Buttons break

PostPosted: Sun Oct 11, 2015 12:38 am
by Odyseus
Hello, trapper john.

Attached to this post you will find two patched custombuttons.jar files that fixes the breakage on Firefox Nightly. At least all the buttons are initialized. There are still a lot of things broken due to changes everywhere! ¬¬

Just download the file corresponding to your version of Custom Buttons, rename it to custombuttons.jar and replace the same file inside ProfileFolder/extensions/custombuttons@xsms.org/chrome.

If you want to patch it yourself, I just changed one single keyword in the overlay.js file inside the custombuttons.jar file.
From...
Code: Select all
const custombuttons = {
// A lot more code

To...
Code: Select all
var custombuttons = {
// A lot more code


To be honest, it was a shot in the dark and it worked. LOL

Image

By the way, you should report Custom Buttons errors in the right section and with as much information as possible. The Browser Console told me everything I needed to know to attempt to find/fix the error.

Re: Custom Buttons break

PostPosted: Sun Oct 11, 2015 4:49 am
by trapper john
Hey Odyseus, nice job, it's working again. I didn't realize it would be that easy and didn't even bother to look in the console. Besides fixing the addon Firefox is starting up fast again; I can't believe how much the broken Custom Buttons was holding it up.

Now we just have to get it signed before the final release but hopefully the developer will be back and straighten it out. If not, anyone can upload it for signing, just the name and id has to be changed first.

While you're here, can I shamelessly ask you for assistance with button code?

This is used to clear cookies:

Code: Select all
var cookieMgr = Cc["@mozilla.org/cookiemanager;1"]
   .getService(Ci.nsICookieManager);
cookieMgr.removeAll(); // Removes ALL cookies

Is it possible to add more to initialization to change icons between when cookies are in the manager and when they're cleared? I've tried every trick but can't find the right formula.

Re: Custom Buttons break

PostPosted: Sun Oct 11, 2015 7:08 am
by Odyseus
trapper john wrote:Besides fixing the addon Firefox is starting up fast again.

That's the first thing I noticed too. And the only "clue" in the Browser Console was the error "custombuttons is not defined". Like I said, a shot in the dark.
trapper john wrote:Is it possible to add more to initialization to change icons between when cookies are in the manager and when they're cleared? I've tried every trick but can't find the right formula.

An easy way would be with the code bellow:
Code: Select all
/*Initialization Code*/
var empty = "chrome://custombuttons/skin/stdicons/gbutton.png"; // Image for when there are NO cookies
var full = "chrome://custombuttons/skin/stdicons/rbutton.png"; // Image for when there ARE cookies

var _UID = "__unique_identifier_" + self.id.slice(20);
var cookieMgr = Cc["@mozilla.org/cookiemanager;1"].getService(Ci.nsICookieManager);

var TabsListener = {
   onStateChange: function(aBrowser) {
      self.setImage();
   },
};

if (!(_UID in window)) {
   window[_UID] = true;
   gBrowser.addTabsProgressListener(TabsListener);
}

this.setImage = function() {
   if (cookieMgr.enumerator.hasMoreElements())
      self.image = full;
   else
      self.image = empty;
};

addDestructor(function(aReason) {
   if (aReason === "update" || aReason === "delete" || aReason === "destructor") {
      gBrowser.removeTabsProgressListener(TabsListener);
      delete window[_UID];
   }
});

this.setImage();


And put this at the end of the Code tab:
Code: Select all
setTimeout(function() {
   self.setImage();
}, 500);


Another way (a very lazy one LOL) would be with a "setInterval" instead of the tab listener, but I don't like very much some code runing all the time in the background, no matter how small it is.

If you need me to explain the code, just let me know.

Re: Custom Buttons break

PostPosted: Sun Oct 11, 2015 12:47 pm
by trapper john
That code works like a champ, thanks again. And it's one less addon needed for such a simple job. Don't know what I'm going to do without Custom Buttons when it's gone.