home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 2010 Software/Programs / PCGuia_programas.iso / Software / Internet / FlashGet / flashget3.3.0.1092en.exe / FlashGet3.xpi / chrome / FlashGet3.jar / content / saveas.js < prev    next >
Encoding:
JavaScript  |  2009-04-09  |  4.7 KB  |  194 lines

  1. /* You may find the license in the LICENSE file */
  2. /* ╨▐╕─╫╘dta╜┼▒╛ */
  3.  
  4. var FlashGet_Cookie;
  5.  
  6. var FG3_SaveAs = {
  7.     init: function fg_init() {
  8.         
  9.         var basicBox = document.getElementById('basicBox');
  10.         var normalBox = document.getElementById('normalBox');
  11.         const doRevert = basicBox && (!basicBox.collapsed || (normalBox && normalBox.collapsed));
  12.         
  13.         if (doRevert) {
  14.             this.revertUI();
  15.         }
  16.         
  17.         this.normal = document.getElementById('FG3saveas');
  18.         this.mode = document.getElementById('mode');
  19.         this.remember = document.getElementById("rememberChoice");
  20.         this.settingsChange = document.getElementById("settingsChange");
  21.         
  22.         document.getElementById('flashget3container').collapsed = false;
  23.         this.normal.disabled = false;
  24.         
  25.         this.dialog = dialog;
  26.         this.url = dialog.mLauncher.source.spec;
  27.         try 
  28.         {
  29.             this.referrer = dialog.mContext.QueryInterface(Components.interfaces.nsIWebNavigation).currentURI.spec;
  30.           }
  31.         catch(ex)
  32.         {
  33.             this.referrer = this.url;
  34.         }
  35.         try
  36.         {
  37.                     var ios = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
  38.                    var uri = ios.newURI(this.url, null, null);
  39.                     var cookieSvc =Components.classes["@mozilla.org/cookieService;1"].getService(Components.interfaces.nsICookieService);
  40.                     FlashGet_Cookie = cookieSvc.getCookieString(uri, null);    
  41.                         
  42.         }
  43.         catch (ex)
  44.         {
  45.             this.cookie = "";
  46.         }
  47.  
  48.  
  49.         var ml = FG_getLinkPrintMetalink(this.url);
  50.         this.url = ml ? ml : this.url;
  51.  
  52.         // this.url = new DTA_URL(ml ? ml : this.url);
  53.         
  54.         this.mode.selectedItem = this.normal;
  55.         
  56.         document.documentElement.setAttribute(
  57.             'ondialogaccept',
  58.             'if(FG3_SaveAs.dialogAccepted()) { '
  59.             + document.documentElement.getAttribute('ondialogaccept')
  60.             + '}'
  61.         );
  62.                 
  63.         this.mode.addEventListener( 'select',
  64.             function(evt) {
  65.                 FG3_SaveAs.select(evt);
  66.             },
  67.             false
  68.         );
  69.     },
  70.     
  71.     revertUI: function fg_revertUI() {
  72.         ['open'].forEach(
  73.             function(e) {
  74.                 e = document.getElementById(e);
  75.                 e.parentNode.collapsed = true;        
  76.                 e.disabled = true;
  77.             }
  78.         );
  79.         document.getElementById('normalBox').collapsed = false;
  80.         var nodes = document.getElementById('normalBox')
  81.             .getElementsByTagName('separator');
  82.         
  83.         for (var i = 0; i < nodes.length; ++i) {
  84.             nodes[i].collapsed = true;
  85.         } 
  86.  
  87.         document.getElementById('basicBox').collapsed = true;
  88.         document.getElementById('normalBox').collapsed = false;
  89.         
  90.         // take care of FlashGot... for now.
  91.         // need to negotiate with the author (and possible other extension authors)
  92.         try {
  93.             gFlashGotDMDialog.init();
  94.             document.getElementById("flashgot-basic").collapsed = true;
  95.         }
  96.         catch (ex) {
  97.             // no op
  98.         }
  99.         this.sizeToContent();
  100.                 
  101.     },
  102.     
  103.     // Workaround for bug 371508
  104.     sizeToContent: function() {
  105.         try {
  106.             window.sizeToContent();    
  107.         }
  108.         catch (ex) {
  109.             FG_debug.dump("sizeToContent Bug: 371508", ex);
  110.             try {
  111.                 var btn = document.documentElement.getButton('accept');
  112.                 window.innerHeight = btn.boxObject.y + 10; 
  113.             }
  114.             catch (ex) {
  115.                 FG_debug.dump("setting height failed");
  116.             }        
  117.         }
  118.     },    
  119.     select: function fg_select(evt) {
  120.         var mode = this.mode.selectedItem;
  121.         this.remember.checked = false;
  122.         if (this.normal == mode ) {
  123.             this.remember.disabled = false;
  124.         }
  125.     },
  126.     
  127.     dialogAccepted: function fg_accept() {
  128.         var mode = this.mode.selectedItem;
  129.         if (mode == this.normal) {
  130.             this.download();            
  131.             return false;
  132.         }        
  133.         return true;
  134.     },
  135.     
  136.     download: function() 
  137.     {
  138.     // ╠φ╝╙╡╜Flashget┐═╗º╢╦╓╨
  139.     //FG_alert( this.url, this.referrer );
  140.         //FG_AddingFunctions.saveSingleLink(this.url, "", this.referrer, "FlashGet3", 0);
  141.         //document.documentElement.cancelDialog();
  142.         
  143.         var obj
  144.         try
  145.         {
  146.             const cid = "@flashget.com/FlashgetXpiEx;1";
  147.             obj = Components.classes[cid].createInstance();
  148.             obj = obj.QueryInterface(Components.interfaces.IFlashgetXpi);
  149.         } 
  150.         catch (err) 
  151.         {
  152.             return;
  153.         }
  154.         
  155.         if (obj == null)
  156.         {
  157.             return;
  158.         }
  159.  
  160.         obj.AddUrl(this.url, this.referrer, this.referrer, "FlashGet3",FlashGet_Cookie,0);
  161.             
  162.         document.documentElement.cancelDialog();
  163.     }
  164. }
  165.  
  166. addEventListener(
  167.     "load",
  168.     function(){ FG3_SaveAs.init(); },
  169.     false
  170. );
  171.  
  172. function FG_getLinkPrintMetalink(url, charset) {
  173.     if (url instanceof Components.interfaces.nsIURL) {
  174.         url = url.ref;
  175.     }
  176.     else if (url instanceof Components.interfaces.nsIURI) {
  177.         url = url.spec;
  178.     }
  179.     else if (typeof(url) != 'string' && !(url instanceof String)) {
  180.         return null;
  181.     }
  182.     
  183.     var lp = url.match(/#!metalink3!((?:https?|ftp):.+)$/);
  184.     if (lp) {
  185.         var rv = lp[1];
  186.         try {
  187.             return DTA_AddingFunctions.ios.newURI(rv, charset, null).spec;
  188.         }
  189.         catch (ex) {
  190.             // not a valid link, ignore it.
  191.         }
  192.     }
  193.     return null;
  194. }