home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 2004 September / APC0409D1.iso / f_looks / files / adblock-0.5-dev.xpi / chrome / adblock.jar / content / global.js < prev    next >
Encoding:
Text File  |  2004-05-31  |  1.5 KB  |  46 lines

  1. var __abCancelled;
  2. var __abWarn;
  3. var console = Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService);
  4.  
  5. // Checks if a filter is already a regular expression. if warn is true,
  6. // the user is warned.
  7. function adblockIsRegExp(filter, warn) {    
  8.     if (filter.charAt(0) == "/" &&
  9.         filter.charAt( filter.length - 1) == "/") {
  10.         return true;    
  11.     } else {
  12.         return false;
  13.     }
  14. }
  15.  
  16. // Warns the user that he has entered a regular expression. 
  17. // Returns true if the user is ok with this. false if he wants to change the filter.
  18. function adblockWarnRegExp() {
  19.     var prefObj;
  20.     var Branch;
  21.     
  22.     try {
  23.         prefObj = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
  24.         Branch = prefObj.getBranch("adblock.");
  25.         var warn = Branch.getBoolPref("warnregexp");
  26.     } catch(exception) { }    
  27.     
  28.     if (warn == undefined || warn == true) {
  29.         window.openDialog("chrome://adblock/content/warnregexpdialog.xul","Warn regular expression",
  30.                           "chrome,modal,centerscreen", adblockWarnResult);        
  31.         if (__abWarn) {
  32.             prefObj = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
  33.             Branch = prefObj.getBranch("adblock.");
  34.             Branch.setBoolPref("warnregexp", false);
  35.         }
  36.         ;
  37.         if (__abCancelled) 
  38.             return false; // The filter is not ok.
  39.     }
  40.     return true; // The filter is ok.
  41. }
  42.  
  43. function adblockWarnResult(cancelled, warnagain) {
  44.     __abCancelled = cancelled;
  45.     __abWarn = warnagain;
  46. }