youtube: update scraper for youtube.com change
[conkeror.git] / modules / pref.js
blob17926b7ace972d1527aeac379a2fa3d3b13c1f58
1 /**
2  * (C) Copyright 2004-2007 Shawn Betts
3  * (C) Copyright 2007-2009 John J. Foerch
4  * (C) Copyright 2007-2008 Jeremy Maitin-Shepard
5  *
6  * Use, modification, and distribution are subject to the terms specified in the
7  * COPYING file.
8 **/
10 in_module(null);
12 function set_branch_pref (branch, name, value) {
13     if (typeof(value) == "string") {
14         branch.setCharPref(name, value);
15     } else if (typeof(value) == "number") {
16         branch.setIntPref(name, value);
17     } else if (typeof(value) == "boolean") {
18         branch.setBoolPref(name, value);
19     }
22 function default_pref (name, value) {
23     var branch = preferences.getDefaultBranch(null);
24     set_branch_pref(branch, name, value);
27 function user_pref (name, value) {
28     var branch = preferences.getBranch(null);
29     set_branch_pref(branch, name, value);
32 function get_branch_pref (branch, name) {
33     switch (branch.getPrefType(name)) {
34     case branch.PREF_STRING:
35         return branch.getCharPref(name);
36     case branch.PREF_INT:
37         return branch.getIntPref(name);
38     case branch.PREF_BOOL:
39         return branch.getBoolPref(name);
40     default:
41         return null;
42     }
45 function get_localized_pref (name) {
46     try {
47         return preferences.getBranch(null).getComplexValue(name, Ci.nsIPrefLocalizedString).data;
48     } catch (e) {
49         return null;
50     }
53 function get_pref (name) {
54     var branch = preferences.getBranch(null);
55     return get_branch_pref(branch, name);
58 function get_default_pref (name) {
59     var branch = preferences.getDefaultBranch(null);
60     return get_branch_pref(branch, name);
63 function clear_pref (name) {
64     var branch = preferences.getBranch(null);
65     return branch.clearUserPref(name);
68 function pref_has_user_value (name) {
69     var branch = preferences.getBranch(null);
70     return branch.prefHasUserValue(name);
73 function pref_has_default_value (name) {
74     var branch = preferences.getDefaultBranch(null);
75     return branch.prefHasUserValue(name);
78 function session_pref (name, value) {
79     try {
80         clear_pref (name);
81     } catch (e) {}
82     return default_pref(name, value);
85 function watch_pref (pref, hook) {
86     /* Extract pref into branch.pref */
87     let match = pref.match(/^(.*[.])?([^.]*)$/);
88     let br = match[1];
89     let key = match[2];
90     let branch = preferences.getBranch(br).QueryInterface(Ci.nsIPrefBranch2);
91     let observer = {
92         observe: function (subject, topic, data) {
93             if (topic == "nsPref:changed" && data == key) {
94                 hook();
95             }
96         }
97     };
98     branch.addObserver("", observer, false);
101 provide("pref");