File: browser.js

package info (click to toggle)
custom-tab-width 1.0.1-2
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 100 kB
  • ctags: 3
  • sloc: makefile: 9
file content (33 lines) | stat: -rw-r--r-- 1,163 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
window.addEventListener("load", function () {
  customTabWidth.init();
}, false);
window.addEventListener("unload", function () {
  customTabWidth.uninit();
}, false);

var customTabWidth = {
  init: function() {
    var ss = document.styleSheets;
    for (let i = ss.length - 1; i >= 0; i--) {
      if (ss[i].href == "chrome://tab-width/content/browser.css") {
         this.styleSheet = ss[i];
         break;
      }
    }
    Services.prefs.addObserver("browser.tabs.tabMinWidth", this, false);
    Services.prefs.addObserver("browser.tabs.tabMaxWidth", this, false);
    this.observe();
  },
  uninit: function () {
    Services.prefs.removeObserver("browser.tabs.tabMinWidth", this);
    Services.prefs.removeObserver("browser.tabs.tabMaxWidth", this);
    delete this.styleSheet;
  },
  observe: function () {
    var min = Math.max(20, Services.prefs.getIntPref("browser.tabs.tabMinWidth"));
    var max = Math.max(20, Services.prefs.getIntPref("browser.tabs.tabMaxWidth"));
    var style = this.styleSheet.cssRules[1].style;
    style.setProperty("min-width", min + "px", "important");
    style.setProperty("max-width", max + "px", "important");
  }
};