Advertisement
Guest User

kwierso

a guest
Jul 1st, 2010
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.88 KB | None | 0 0
  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Version: Open Software License v. 2.1
  3. *
  4. * The contents of this file are subject to the Open Software License Version
  5. * 2.1 (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. * http://www.opensource.org/licenses/osl-2.1.php
  8. *
  9. * Software distributed under the License is distributed on an "AS IS" basis,
  10. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. * for the specific language governing rights and limitations under the
  12. * License.
  13. *
  14. * The Original Code is the 'Rooster Teeth Site Extender'.
  15. *
  16. * The Initial Developer of the Original Code is
  17. * Shawn Wilsher
  18. *
  19. * Portions created by the Initial Developer are Copyright (C) 2006
  20. * the Initial Developer. All Rights Reserved.
  21. *
  22. * Contributor(s):
  23. * Wes Kocher
  24. *
  25. * ***** END LICENSE BLOCK ***** */
  26.  
  27. Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
  28.  
  29. /* constants */
  30. const Cc = Components.classes;
  31. const Ci = Components.interfaces;
  32. const nsIRTSE = Ci.nsIRTSE;
  33. const nsISupports = Ci.nsISupports;
  34.  
  35. const nsIPrefService = Ci.nsIPrefService;
  36. const nsIPasswordManagerInternal = Ci.nsIPasswordManagerInternal;
  37. const nsIXMLHttpRequest = Ci.nsIXMLHttpRequest;
  38. const nsIStyleSheetService = Ci.nsIStyleSheetService;
  39. const nsIIOService = Ci.nsIIOService;
  40.  
  41. /* class definition */
  42. function RTSE()
  43. // OVERVIEW: This is the constructor function
  44. {
  45. // Style Sheet Loading
  46. var sss = Cc["@mozilla.org/content/style-sheet-service;1"]
  47. .getService(nsIStyleSheetService);
  48. var ios = Cc["@mozilla.org/network/io-service;1"]
  49. .getService(nsIIOService);
  50. var uri = ios.newURI("chrome://rtse/content/styles.css", null, null);
  51. sss.loadAndRegisterSheet(uri, sss.USER_SHEET);
  52. var uri2 = ios.newURI("chrome://rtse/content/styles2.css", null, null);
  53. var uri3 = ios.newURI("chrome://rtse/content/styles3.css", null, null);
  54. var uri4 = ios.newURI("chrome://rtse/content/styles4.css", null, null);
  55. var uri5 = ios.newURI("chrome://rtse/content/styles5.css", null, null);
  56. var uriHome = ios.newURI("chrome://rtse/content/homepage.css", null, null);
  57. var uriWatch = ios.newURI("chrome://rtse/content/watchlist.css", null, null);
  58. if(!this.prefsGetBool("extensions.rtse.sidebar"))
  59. sss.loadAndRegisterSheet(uri2, sss.USER_SHEET);
  60. if(!this.prefsGetBool("extensions.rtse.header"))
  61. sss.loadAndRegisterSheet(uri3, sss.USER_SHEET);
  62. if(!this.prefsGetBool("extensions.rtse.journals"))
  63. sss.loadAndRegisterSheet(uri4, sss.USER_SHEET);
  64. if(!this.prefsGetBool("extensions.rtse.background"))
  65. sss.loadAndRegisterSheet(uri5, sss.USER_SHEET);
  66. if(!this.prefsGetBool("extensions.rtse.homepage"))
  67. sss.loadAndRegisterSheet(uriHome, sss.USER_SHEET);
  68. if(this.prefsGetBool("extensions.rtse.watchlistcolor"))
  69. sss.loadAndRegisterSheet(uriWatch, sss.USER_SHEET);
  70.  
  71. // Version
  72. const UA_STRING = "RTSE/" + this.version;
  73. if (this.prefsGetString("general.useragent.extra.rtse") != UA_STRING)
  74. this.prefsSetString("general.useragent.extra.rtse", UA_STRING);
  75. };
  76. RTSE.prototype =
  77. {
  78. classDescription: "Rooster Teeth Site Extender XPCOM Component",
  79. classID: Components.ID("{0960cf50-d196-11da-a94d-0800200c9a66}"),
  80. contractID: "@shawnwilsher.com/rtse;1",
  81. QueryInterface: XPCOMUtils.generateQI([Ci.nsIRTSE]),
  82.  
  83. // OVERVIEW: This is the class definition. Defines the functions
  84. // that are exposed in the interface.
  85. mVersion: '1.2.0.20100320',
  86. mLoginSent: false,
  87.  
  88. get version()
  89. // EFFECTS: returns the value of 'version' - used as an attribute
  90. {
  91. return this.mVersion;
  92. },
  93.  
  94. /**
  95. * Obtains the username stored in the preferences.
  96. *
  97. * @return The stored username.
  98. */
  99. get username()
  100. {
  101. return this.prefsGetString("extensions.rtse.username");
  102. },
  103.  
  104. /**
  105. * Sets the username in the preferences.
  106. *
  107. * @param aVal The value to set username too.
  108. */
  109. set username(aVal)
  110. {
  111. this.prefsSetString("extensions.rtse.username", aVal);
  112. },
  113.  
  114. prefsSetBool: function(aName,aValue)
  115. // EFFECTS: Sets a boolean preference aName with aValue.
  116. {
  117. var prefs = this.prefsGetBranch(aName);
  118.  
  119. prefs.branch.setBoolPref(prefs.name, aValue);
  120. },
  121. prefsSetString: function(aName,aValue)
  122. // EFFECTS: Sets a string preference aName with aValue.
  123. {
  124. var prefs = this.prefsGetBranch(aName);
  125.  
  126. prefs.branch.setCharPref(prefs.name, aValue);
  127. },
  128. prefsGetBool: function(aName)
  129. // EFFECTS: Returns the value of aName.
  130. {
  131. var prefs = this.prefsGetBranch(aName);
  132.  
  133. return prefs.branch.getBoolPref(prefs.name);
  134. },
  135. prefsGetString: function(aName)
  136. // EFFECTS: Returns the value of aName.
  137. {
  138. var prefs = this.prefsGetBranch(aName);
  139.  
  140. return prefs.branch.getCharPref(prefs.name);
  141. },
  142.  
  143. /**
  144. * Obtains the proper preference branch for the preference.
  145. *
  146. * @param aName The full name of the preference to obtain.
  147. * @return An array of the branch and the name of the preference.
  148. */
  149. prefsGetBranch: function prefsGetBranch(aName)
  150. {
  151. var prefs = {
  152. name: null,
  153. branch: null
  154. };
  155. prefs.branch = Cc["@mozilla.org/preferences-service;1"]
  156. .getService(nsIPrefService);
  157. var temp = aName.split('.');
  158. var root = '';
  159. for (var i = 0; i < (temp.length - 1); ++i ) {
  160. root = root + temp[i] + '.';
  161. }
  162. prefs.branch = prefs.branch.getBranch(root);
  163. prefs.name = temp[temp.length - 1];
  164. return prefs;
  165. }
  166. };
  167.  
  168. var components = [RTSE];
  169.  
  170. /**
  171. * XPCOMUtils.generateNSGetFactory was introduced in Mozilla 2 (Firefox 4).
  172. * XPCOMUtils.generateNSGetModule is for Mozilla 1.9.2 (Firefox 3.6).
  173. */
  174. if (XPCOMUtils.generateNSGetFactory)
  175. var NSGetFactory = XPCOMUtils.generateNSGetFactory(components);
  176. else
  177. var NSGetModule = XPCOMUtils.generateNSGetModule(components);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement