home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 February / Chip_2004-02_cd1.bin / software / del / regetdx.exe / RCDATA / CABINET / reget.jar / content / reget / rgt-ovr.xul < prev   
Extensible Markup Language  |  2003-06-17  |  8KB  |  213 lines

  1. <?xml version="1.0"?>
  2. <!-- ***** BEGIN LICENSE BLOCK *****
  3.    - Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4.    -
  5.    - The contents of this file are subject to the Mozilla Public License Version
  6.    - 1.1 (the "License"); you may not use this file except in compliance with
  7.    - the License. You may obtain a copy of the License at
  8.    - http://www.mozilla.org/MPL/
  9.    -
  10.    - Software distributed under the License is distributed on an "AS IS" basis,
  11.    - WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12.    - for the specific language governing rights and limitations under the
  13.    - License.
  14.    -
  15.    - The Original Code is ReGet Mozilla Plugin.
  16.    -
  17.    - The Initial Developer of the Original Code is Marek Wawoczny.
  18.    - Portions created by the Initial Developer are Copyright (C) 2002
  19.    - the Initial Developer. All Rights Reserved.
  20.    -
  21.    - Contributor(s):
  22.    - Marek Wawoczny (GmbH@MozillaPL.org)
  23.    -
  24.    - Alternatively, the contents of this file may be used under the terms of
  25.    - either the GNU General Public License Version 2 or later (the "GPL"), or
  26.    - the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27.    - in which case the provisions of the GPL or the LGPL are applicable instead
  28.    - of those above. If you wish to allow use of your version of this file only
  29.    - under the terms of either the GPL or the LGPL, and not to allow others to
  30.    - use your version of this file under the terms of the MPL, indicate your
  31.    - decision by deleting the provisions above and replace them with the notice
  32.    - and other provisions required by the LGPL or the GPL. If you do not delete
  33.    - the provisions above, a recipient may use your version of this file under
  34.    - the terms of any one of the MPL, the GPL or the LGPL.
  35.    -
  36.    - ***** END LICENSE BLOCK ***** -->
  37.  
  38. <overlay id="regetOverlay" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  39.  
  40.  <script type="application/x-javascript" src="chrome://navigator/content/contentAreaUtils.js"/>
  41.  <script type="application/x-javascript" src="chrome://navigator/content/utilityOverlay.js"/>
  42.  
  43.  <script type="application/x-javascript">
  44.  <![CDATA[
  45.  
  46.   /**
  47.    * Converts Cyrillic letters in JavaScript string to cp1251.
  48.    * @author Peter B. Shalimoff (vshalim@home.ru).
  49.    * @param str - JavaScript string to be converted.
  50.    * @return converted string.
  51.    */
  52.   function JS2CP1251(str) {
  53.     var rc = "";
  54.     const len = str.length;
  55.     var c, cc;
  56.     for (var i=0; i<len; i++) {
  57.       cc = (c = str[i]).charCodeAt(0);
  58.       if ( cc >> 8 == 4 ) { // a cyrillic letter
  59.         if ( cc == 0x0401 ) { // capital letter Io
  60.           rc += String.fromCharCode(168)
  61.         } else if ( cc == 0x0451 ) { // small letter Io
  62.           rc += String.fromCharCode(184);
  63.         } else { // other cyrillic letters
  64.           rc += String.fromCharCode(cc - 848);
  65.         }
  66.       } else { // not a cyrillic letter, leave it as is.
  67.         rc += c;
  68.       }
  69.     }
  70.     return rc;
  71.   }
  72.  
  73.   cmn = Components.classes["RgCommon"].createInstance(Components.interfaces.nsIRgCommon);
  74.  
  75.   function DownloadBy() {
  76.     var url = Components.classes["RgUrl"].createInstance(Components.interfaces.nsIRgUrl);
  77.     url.url = gContextMenu.linkURL();
  78.     url.info = JS2CP1251(gContextMenu.linkText());
  79.     url.referer = window._content.location.href;
  80.     url.add();
  81.   }
  82.  
  83.   function DownloadAll() {
  84.     var list = Components.classes["RgUrlList"].createInstance(Components.interfaces.nsIRgUrlList);
  85.     var doc = gContextMenu.target.ownerDocument;
  86.     var links = doc.links
  87.     for (i = 0; i < links.length; i++)
  88.     {
  89.       var url = Components.classes["RgUrl"].createInstance(Components.interfaces.nsIRgUrl);
  90.       url.url = links[i].href;
  91.       url.info = JS2CP1251(links[i].text); 
  92.       url.referer = window._content.location.href;
  93.       list.add(url);
  94.     }
  95.     list.list();
  96.   }
  97.  
  98.   function initReGetContextMenuItems(aEvent)
  99.   {
  100.     if (cmn.menu1 != null)
  101.     {
  102.         var s=cmn.menu1;
  103.         r=s.search("&");
  104.         if (r!=-1)
  105.         {
  106.             document.getElementById("download-by-catcher").setAttribute("accesskey", s.charAt(r+1).toLowerCase( )); 
  107.         } else
  108.         {
  109.             document.getElementById("download-by-catcher").setAttribute("accesskey", ""); 
  110.         }
  111.         s=s.replace("&","");
  112.         document.getElementById("download-by-catcher").setAttribute("label", s); 
  113.     }
  114.  
  115.     if (cmn.menu2 != null)
  116.     {
  117.         var s=cmn.menu2;
  118.         r=s.search("&");
  119.         if (r!=-1)
  120.         {
  121.             document.getElementById("download-all-by-catcher").setAttribute("accesskey", s.charAt(r+1).toLowerCase( )); 
  122.         } else
  123.         {
  124.             document.getElementById("download-all-by-catcher").setAttribute("accesskey", ""); 
  125.         }
  126.         s=s.replace("&","");
  127.         document.getElementById("download-all-by-catcher").setAttribute("label", s);
  128.     }
  129.  
  130.     gContextMenu.showItem("download-by-catcher", gContextMenu.onSaveableLink);
  131.     gContextMenu.showItem("context-sep-reget-start", gContextMenu.onSaveableLink);
  132.   }
  133.  
  134.   function initReGetContextMenuListener(aEvent)
  135.   {
  136. //    document.getElementById("contentAreaContextMenu").addEventListener("popupshowing", initReGetContextMenuItems, false);
  137.     var contentAreaContextMenu = window.document.getElementById("contentAreaContextMenu");
  138.  
  139.     if (contentAreaContextMenu)
  140.       contentAreaContextMenu.addEventListener("popupshowing", initReGetContextMenuItems, false);
  141.  
  142.     window.removeEventListener("load", initReGetContextMenuListener, true);
  143.   }
  144.  
  145.   function altKeyDownloadBy(aEvent)
  146.   {
  147.     if (cmn.catchLinks) {
  148.       if (aEvent.button == 0 && (aEvent.altKey || !cmn.useAlt)) {
  149.         var linkNode;
  150.         var localName = aEvent.target.localName;
  151.  
  152.  
  153.  
  154.         if (localName) {
  155.           localName = localName.toLowerCase();
  156.         }
  157.  
  158.         switch (localName) {
  159.           case "a":
  160.           case "area":
  161.           case "link":
  162.             if (aEvent.target.hasAttribute("href")) 
  163.               linkNode = aEvent.target;
  164.             break;
  165.           default:
  166.             linkNode = findParentNode(aEvent.originalTarget, "a");
  167.             if (linkNode && !linkNode.hasAttribute("href"))
  168.               linkNode = null;
  169.             break;
  170.         }
  171.  
  172.  
  173.         if (linkNode) {
  174.           var text = gatherTextUnder(linkNode);
  175.    
  176.  
  177.  
  178.           if (!text || !text.match(/\S/)) {
  179.             text = linkNode.getAttribute("title");
  180.             if (!text || !text.match(/\S/)) {
  181.               text = linkNode.getAttribute("alt");
  182.               if (!text || !text.match(/\S/)) {
  183.                 text = linkNode.href;
  184.               }
  185.             }
  186.           }
  187.  
  188.           var url = Components.classes["RgUrl"].createInstance(Components.interfaces.nsIRgUrl);
  189.           url.url = linkNode.href;
  190.           url.info = JS2CP1251(text);
  191.           url.referer = window._content.location.href;
  192.           url.add();
  193.         }
  194.       }
  195.     }
  196.   }
  197.  
  198.   window.addEventListener("load", initReGetContextMenuListener, true);
  199.   getBrowser().addEventListener("click", altKeyDownloadBy, true);
  200.  
  201.  
  202.  ]]>
  203.  </script>
  204.  
  205.  <popup id="contentAreaContextMenu">
  206.   <menuseparator id="context-sep-reget-end" insertafter="context-savelink"/>
  207.   <menuitem id="download-all-by-catcher" label="Download all with ReGet" oncommand="DownloadAll();" insertafter="context-savelink"/>
  208.   <menuitem id="download-by-catcher" label="Download with ReGet" oncommand="DownloadBy();" insertafter="context-savelink"/>
  209.   <menuseparator id="context-sep-reget-start" insertafter="context-savelink"/>
  210.  </popup>
  211.  
  212. </overlay>
  213.