summaryrefslogtreecommitdiff
path: root/xpi/content/aboutprefs.js
blob: 368b985744c80b6e67ead246f5f75595cf3058f7 (plain)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
"use strict";

(function(global) {
var Cu = Components.utils;

var {Services} = Cu.import("resource://gre/modules/Services.jsm", {});

if (typeof ctrAboutPrefs  == "undefined") {
    var ctrAboutPrefs  = {};
};
if (!ctrAboutPrefs ) {
    ctrAboutPrefs  = {};
};
 
ctrAboutPrefs = {
  init: function(){
	
	if(Services.prefs.getBranch('extensions.classicthemerestorer.').getBoolPref('optionsrem')) {
	
	  /* main pref categories */	  
	  setTimeout(function(){
		  
		var prefslocation = 'paneGeneral';
	  
		switch (Services.prefs.getBranch('extensions.classicthemerestorer.').getCharPref('aboutprefs')) {

		  case "category-general": prefslocation = 'paneGeneral'; break;
		  case "category-search": prefslocation = 'paneSearch'; break;
		  case "category-content": prefslocation = 'paneContent'; break;
		  case "category-application": prefslocation = 'paneApplications'; break;
		  case "category-privacy": prefslocation = 'panePrivacy'; break;
		  case "category-security": prefslocation = 'paneSecurity'; break;
		  case "category-sync": prefslocation = 'paneSync'; break;
		  case "category-advanced": prefslocation = 'paneAdvanced'; break;

		}
	  
		var windowsService = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService(Components.interfaces.nsIWindowMediator);
		var currentWindow = windowsService.getMostRecentWindow('navigator:browser');
		var browser = currentWindow.getBrowser();
		
		if(browser.contentDocument.location.href=='about:preferences') {
		  gotoPref(prefslocation);
		}
		
	  },80);
  
	  var observer = new MutationObserver(function(mutations) {
		mutations.forEach(function(mutation) {

		   try{ 
		     Services.prefs.getBranch('extensions.classicthemerestorer.').setCharPref('aboutprefs',document.getElementById("categories").getAttribute("last-selected"));
		   } catch(e) {}
			
		});    
	  });

	  observer.observe(document.querySelector('#categories'), { attributes: true, attributeFilter: ['last-selected'] });
	  
	  /* advanced prefs area */
	  window.addEventListener("DOMContentLoaded", function aboutprefsIndex(event){
		window.removeEventListener("DOMContentLoaded", aboutprefsIndex, false);
		  try{
			document.getElementById("advancedPrefs").selectedIndex = Services.prefs.getBranch('extensions.classicthemerestorer.').getIntPref('aboutprefsInd');
		  } catch(e) {}
		  
		  var observer2 = new MutationObserver(function(mutations) {
			mutations.forEach(function(mutation) {

			   try{ 
				 Services.prefs.getBranch('extensions.classicthemerestorer.').setIntPref('aboutprefsInd',document.getElementById("advancedPrefs").getAttribute("selectedIndex"));
			   } catch(e) {}
				
			});    
		  });

		  observer2.observe(document.querySelector('#advancedPrefs'), { attributes: true, attributeFilter: ['selectedIndex'] });
	  },false);
	  
	}

	window.addEventListener("DOMContentLoaded", function addPrefAttributes(event){
	  window.removeEventListener("DOMContentLoaded", addPrefAttributes, false);
	
	  /* add attributes to nodes for better css parting */
	  try{
		var thirdpartytheme = Services.prefs.getBranch("general.skins.").getCharPref("selectedSkin");
		document.querySelector('#categories').setAttribute('currenttheme',thirdpartytheme);
	  } catch(e){}
		
	  try{
		if(parseInt(Services.appinfo.version) >=46 && parseInt(Services.appinfo.version) < 49)
		  document.querySelector('#mainPrefPane').setAttribute('fx46plus',true);
		else if(parseInt(Services.appinfo.version) >=49)
		  document.querySelector('#mainPrefPane').setAttribute('fx49plus',true);
	  } catch(e){}

	  /* restore favicon wheel for all categories */
	  var windowsService = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService(Components.interfaces.nsIWindowMediator);
	  var currentWindow = windowsService.getMostRecentWindow('navigator:browser');
	  var browser = currentWindow.getBrowser();
	
	  if(browser.contentDocument.location.href.indexOf('about:preferences')!=-1) {
		
		var ss =  Cc["@mozilla.org/content/style-sheet-service;1"].getService(Ci.nsIStyleSheetService);
		var uri = Services.io.newURI("data:text/css;charset=utf-8," + encodeURIComponent('\
		\
		#TabsToolbar .tabbrowser-tab[label="'+browser.selectedTab.label+'"] .tab-icon-image:not([src]),\
		#main-window[fx44plus="true"] #TabsToolbar .tabbrowser-tab[label="'+browser.selectedTab.label+'"] .tab-icon-image:not([src]),\
		#TabsToolbar .tabbrowser-tab[label="'+browser.selectedTab.label+'"]:not([pinned]) .tab-icon-image:not([src]),\
		#main-window[fx44plus="true"] #TabsToolbar .tabbrowser-tab[label="'+browser.selectedTab.label+'"]:not([pinned]) .tab-icon-image:not([src]) {\
		  list-style-image: url("chrome://browser/skin/preferences/in-content/favicon.ico") !important;\
		  display:block !important;\
		}\
		\
		'), null, null);

		ss.loadAndRegisterSheet(uri, ss.AGENT_SHEET);
	  }
	},false);
	
  }
}
  // Make ctrAboutPrefs a global variable
  try{
	global.ctrAboutPrefs = ctrAboutPrefs.init();
  } catch(e){}
}(this));