Custom Buttons break

General discussion about Custom Buttons, including feature requests.

Custom Buttons break

Postby trapper john » Fri Oct 09, 2015 2:04 am

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.
trapper john
 
Posts: 108
Joined: Wed Mar 14, 2012 6:58 pm

Re: Custom Buttons break

Postby trapper john » Fri Oct 09, 2015 8:07 pm

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.
trapper john
 
Posts: 108
Joined: Wed Mar 14, 2012 6:58 pm

Re: Custom Buttons break

Postby Odyseus » Sun Oct 11, 2015 12:38 am

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.
Attachments
custombuttons.zip.0.0.5.9pre1.zip
Rename file to custombuttons.jar. For Custom Buttons Beta ONLY!!!!
(125.86 KiB) Downloaded 36 times
custombuttons.jar.0.0.5.8.1-signed.zip
Rename file to custombuttons.jar. For Custom Buttons Stable ONLY!!!!
(123.04 KiB) Downloaded 38 times
Odyseus
 
Posts: 434
Joined: Sun Mar 10, 2013 12:51 pm

Re: Custom Buttons break

Postby trapper john » Sun Oct 11, 2015 4:49 am

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.
trapper john
 
Posts: 108
Joined: Wed Mar 14, 2012 6:58 pm

Re: Custom Buttons break

Postby Odyseus » Sun Oct 11, 2015 7:08 am

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.
Odyseus
 
Posts: 434
Joined: Sun Mar 10, 2013 12:51 pm

Re: Custom Buttons break

Postby trapper john » Sun Oct 11, 2015 12:47 pm

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.
trapper john
 
Posts: 108
Joined: Wed Mar 14, 2012 6:58 pm


Return to General Discussion

cron