home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2005 October / DPPCPRO1005.ISO / Download / Web Developer / webdeveloper.xpi / chrome / webdeveloper.jar / content / webdeveloper / miscellaneous.js < prev    next >
Encoding:
JavaScript  |  2005-03-21  |  9.2 KB  |  266 lines

  1. // Clears the cache
  2. function webdeveloper_clearCache()
  3. {
  4.     const cacheService = Components.classes["@mozilla.org/network/cache-service;1"].getService(Components.interfaces.nsICacheService);
  5.     const stringBundle = document.getElementById("webdeveloper-string-bundle");
  6.  
  7.     cacheService.evictEntries(Components.interfaces.nsICache.STORE_ON_DISK);
  8.     cacheService.evictEntries(Components.interfaces.nsICache.STORE_IN_MEMORY);
  9.  
  10.     alert(stringBundle.getString("webdeveloper_clearCacheResult"));
  11. }
  12.  
  13. // Clears the history
  14. function webdeveloper_clearHistory()
  15. {
  16.     const stringBundle = document.getElementById("webdeveloper-string-bundle");
  17.  
  18.     Components.classes["@mozilla.org/browser/global-history;2"].getService(Components.interfaces.nsIBrowserHistory).removeAllPages();
  19.  
  20.     alert(stringBundle.getString("webdeveloper_clearHistoryResult"));
  21. }
  22.  
  23. // Clears the HTTP authentication
  24. function webdeveloper_clearHTTPAuthentication()
  25. {
  26.     const authenticationManager = Components.classes["@mozilla.org/network/http-auth-manager;1"].getService(Components.interfaces.nsIHttpAuthManager);
  27.     const stringBundle          = document.getElementById("webdeveloper-string-bundle");
  28.  
  29.     authenticationManager.clearAll();
  30.  
  31.     alert(stringBundle.getString("webdeveloper_clearHTTPAuthenticationResult"));
  32. }
  33.  
  34. // Clears all session cookies
  35. function webdeveloper_clearSessionCookies()
  36. {
  37.     const cookieManager = Components.classes["@mozilla.org/cookiemanager;1"].getService(Components.interfaces.nsICookieManager);
  38.     const cookies       = cookieManager.enumerator;
  39.     const stringBundle  = document.getElementById("webdeveloper-string-bundle");
  40.  
  41.     var removed = 0;
  42.  
  43.     // Loop through the cookies
  44.     while(cookies.hasMoreElements())
  45.     {
  46.         var cookie = cookies.getNext();
  47.  
  48.         // If this is a cookie with no expiration
  49.         if(cookie instanceof Components.interfaces.nsICookie && cookie.expires == "0")
  50.         {
  51.             cookieManager.remove(cookie.host, cookie.name, cookie.path, false);
  52.             removed++;
  53.         }
  54.     }
  55.  
  56.     // If one session cookie was removed
  57.     if(removed == 1)
  58.     {
  59.         alert(stringBundle.getString("webdeveloper_clearSessionCookiesSingleResult"));
  60.     }
  61.     else
  62.     {
  63.         alert(stringBundle.getFormattedString("webdeveloper_clearSessionCookiesMultipleResult", [removed]));
  64.     }
  65. }
  66.  
  67. // Deletes all the cookies for the current domain
  68. function webdeveloper_deleteDomainCookies()
  69. {
  70.     const cookieManager = Components.classes["@mozilla.org/cookiemanager;1"].getService(Components.interfaces.nsICookieManager);
  71.     const mainTabBox    = getBrowser().mTabBox;
  72.     const documentList  = webdeveloper_getDocuments(getBrowser().browsers[mainTabBox.selectedIndex].contentWindow, new Array());
  73.     const stringBundle  = document.getElementById("webdeveloper-string-bundle");
  74.  
  75.     var cookie        = null;
  76.     var cookies       = new Array();
  77.     var cookiesLength = null;
  78.     var pageDocument  = null;
  79.  
  80.     // Loop through the documents
  81.     for(var i = 0; i < documentList.length; i++)
  82.     {
  83.         pageDocument = documentList[i];
  84.         cookies      = cookies.concat(webdeveloper_getCookies(pageDocument.location.hostname, false));
  85.     }
  86.  
  87.     cookiesLength = cookies.length;
  88.  
  89.     // Loop through all the cookies
  90.     for(i = 0 ; i < cookiesLength; i++)
  91.     {
  92.         cookie = cookies[i];
  93.  
  94.         cookieManager.remove(cookie.host, cookie.name, cookie.path, false);
  95.     }
  96.  
  97.     // If one cookie was found
  98.     if(cookiesLength == 1)
  99.     {
  100.         alert(stringBundle.getString("webdeveloper_deleteDomainCookiesSingleResult"));
  101.     }
  102.     else
  103.     {
  104.         alert(stringBundle.getFormattedString("webdeveloper_deleteDomainCookiesMultipleResult", [cookiesLength]));
  105.     }
  106. }
  107.  
  108. // Linearizes all elements
  109. function webdeveloper_linearizePage(element, applyStyle)
  110. {
  111.     webdeveloper_toggleStyleSheet(element, "chrome://webdeveloper/content/stylesheets/linearize_page.css", "webdeveloper-linearize-page", applyStyle);
  112. }
  113.  
  114. // Opens the Java Console
  115. function webdeveloper_openJavaConsole()
  116. {
  117.     Components.classes["@mozilla.org/oji/jvm-mgr;1"].getService(Components.interfaces.nsIJVMManager).showJavaConsole();
  118. }
  119.  
  120. // Toggles comments
  121. function webdeveloper_toggleComments(element, applyStyle)
  122. {
  123.     const mainTabBox   = getBrowser().mTabBox;
  124.     const documentList = webdeveloper_getDocuments(getBrowser().browsers[mainTabBox.selectedIndex].contentWindow, new Array());
  125.     const show         = element.getAttribute("checked");
  126.  
  127.     var pageDocument = null;
  128.  
  129.     // Loop through the documents
  130.     for(var i = 0; i < documentList.length; i++)
  131.     {
  132.         pageDocument = documentList[i];
  133.         webdeveloper_toggleCommentsForDocument(pageDocument, show);
  134.     }
  135.  
  136.     webdeveloper_toggleStyleSheet(element, "chrome://webdeveloper/content/stylesheets/show_comments.css", "webdeveloper-show-comments", applyStyle);
  137.     webdeveloper_toggleFeatureTooltipStyles(element, "webdeveloper-show-comments-tooltips", "div.webdeveloper-comment-icon, div.webdeveloper-comment-text, div.webdeveloper-comment-text *");
  138. }
  139.  
  140. // Toggles all links on the page between visited and unvisited
  141. function webdeveloper_toggleVisitedLinks(visited)
  142. {
  143.     const globalHistory  = Components.classes["@mozilla.org/browser/global-history;1"].getService(Components.interfaces.nsIGlobalHistory);
  144.     const mainTabBox     = getBrowser().mTabBox;
  145.     const documentList   = webdeveloper_getDocuments(getBrowser().browsers[mainTabBox.selectedIndex].contentWindow, new Array());
  146.  
  147.     var browserHistory = null;
  148.     var href           = null;
  149.     var link           = null;
  150.     var linkList       = null;
  151.     var pageDocument   = null;
  152.  
  153.     // Try to get the new history component
  154.     try
  155.     {
  156.         browserHistory = Components.classes["@mozilla.org/browser/global-history;2"].getService(Components.interfaces.nsIBrowserHistory);
  157.     }
  158.     catch(exception)
  159.     {
  160.         browserHistory = Components.classes["@mozilla.org/browser/global-history;1"].getService(Components.interfaces.nsIBrowserHistory);
  161.     }
  162.  
  163.     // Loop through the documents
  164.     for(var i = 0; i < documentList.length; i++)
  165.     {
  166.         pageDocument = documentList[i];
  167.         linkList     = pageDocument.getElementsByTagName("a");
  168.  
  169.         // Loop through all the links
  170.         for(var j = 0; j < linkList.length; j++)
  171.         {
  172.             link = linkList[j];
  173.             href = link.href;
  174.  
  175.             // If this link has an href
  176.             if(href)
  177.             {
  178.                 // If marking links as visited
  179.                 if(visited && !globalHistory.isVisited(href))
  180.                 {
  181.                     globalHistory.addPage(href);
  182.                 }
  183.                 else if(globalHistory.isVisited(href))
  184.                 {
  185.                     const uri = Components.classes["@mozilla.org/network/standard-url;1"].createInstance(Components.interfaces.nsIURI);
  186.  
  187.                     uri.spec = href;
  188.  
  189.                     // Try to remove the page as a URI
  190.                     try
  191.                     {
  192.                         browserHistory.removePage(uri);
  193.                     }
  194.                     catch(exception)
  195.                     {
  196.                         browserHistory.removePage(href);
  197.                     }
  198.                 }
  199.  
  200.                 // Force the browser to recheck the history by changing the href
  201.                 link.href = "";
  202.                 link.href = href;
  203.             }
  204.         }
  205.     }
  206. }
  207.  
  208. // Zooms the content
  209. function webdeveloper_zoom(factor)
  210. {
  211.     const mainTabBox   = getBrowser().mTabBox;
  212.     const documentList = webdeveloper_getDocuments(getBrowser().browsers[mainTabBox.selectedIndex].contentWindow, new Array());
  213.  
  214.     var image        = null;
  215.     var imageList    = null;
  216.     var pageDocument = null;
  217.  
  218.     // Loop through the documents
  219.     for(var i = 0; i < documentList.length; i++)
  220.     {
  221.         pageDocument = documentList[i];
  222.         imageList    = pageDocument.getElementsByTagName("img");
  223.  
  224.         webdeveloper_zoomText(pageDocument.documentElement, factor);
  225.  
  226.         // Loop through the images
  227.         for(var j = 0; j < imageList.length; j++)
  228.         {
  229.             image = imageList[j];
  230.  
  231.             image.setAttribute("width", parseInt(image.getAttribute("width") * factor));
  232.             image.setAttribute("height", parseInt(image.getAttribute("height") * factor));
  233.         }
  234.     }
  235. }
  236.  
  237. // Zooms the text
  238. function webdeveloper_zoomText(node, factor)
  239. {
  240.     const childNodeList = node.childNodes;
  241.     const lineHeight    = window.getComputedStyle(node, "").getPropertyValue("line-height");
  242.     const textSize      = window.getComputedStyle(node, "").getPropertyValue("font-size");
  243.  
  244.     var childNode = null;
  245.  
  246.     // Loop through the child nodes
  247.     for(var i = 0; i < childNodeList.length; i++)
  248.     {
  249.         childNode = childNodeList[i];
  250.  
  251.         // If this is an element
  252.         if(childNode.nodeType == 1)
  253.         {
  254.             webdeveloper_zoomText(childNode, factor);
  255.         }
  256.     }
  257.  
  258.     node.style.fontSize = parseInt(textSize.substr(0, textSize.length - 2) * factor) + "px";
  259.  
  260.     // If the line height is not normal
  261.     if(lineHeight != "normal")
  262.     {
  263.         node.style.lineHeight = parseInt(lineHeight.substr(0, lineHeight.length - 2) * factor) + "px";
  264.     }
  265. }
  266.