Skip navigation.

Lee Harvey's Target Range

1 Click Away

Posts tagged with "javascript"

UserJS fix for ASUS Product Comparison page

, , , ...

The ASUS Product Comparison page seems to contain JavaScript code written specifically for MSIE or FF (untested). In any event, the page does not work correctly in Opera, mostly due to their calls to new ActiveXObject.

Below, I've taken the liberty of correcting their processRequest and add JavaScript functions found in this external load_data.js script.

Click here to download/view the asus.js script

if (document.domain.match(/(uk\.)?asus\.com$/)) {

   window.opera.defineMagicFunction("processRequest",
      function(a, b, c) {
         if (http_request.readyState != 4) return;
         if (http_request.status != 200) return;

         var dpl1=document.getElementById("dpl_l1");
         var dpl2=document.getElementById("dpl_l2");
         var dpl3=document.getElementById("dpl_l3");
         var dpl4=document.getElementById("dpl_l4");
         var lbl=document.getElementById("lbl_model");
        
         var parser = new DOMParser();
         var xmldoc = parser.parseFromString(http_request.responseText,"text/xml");
         var dataArray = xmldoc.getElementsByTagName('Table1');
         var dataArrayLen = dataArray.length;
         for (var i=0; i<dataArrayLen; i++)
         {
            var get_id=dataArray[i].getElementsByTagName("id_name")[0].text;
            var get_value=dataArray[i].getElementsByTagName("id_value")[0].text;
            var opt = new Option(get_value, get_id, 0, 0);
            if (l1!=0&&list_model==2) //load level 2
            {
               dpl2.disabled=false;
               dpl2.add(opt);
            }
            else if(l2!=0&&list_model==3) //load level 3
            {
               dpl3.disabled=false;
               dpl3.add(opt);
            }
            else if(l3!=0&&list_model==4) //load level 4
            {
               dpl4.disabled=false;
               dpl4.add(opt);
            }
            else if (list_model==5) 
            {
               dpl3.disabled=(dpl3.length==1);
               lbl.add(opt);
            }
         }
      }, 0);


   window.opera.defineMagicFunction("add", 
      function(a, b, c) {
         var lbl=document.getElementById("lbl_model");
         var lbl_select=document.getElementById("lbl_model_select");
         for(var i=0;i<lbl.options.length;i++)
         {
            if (!lbl.options[i].selected) continue;

            for(var j=0;j<lbl_select.options.length;j++)
               if (lbl.options[i].value==lbl_select.options[j].value)
                  return;

            lbl_select.add(new Option(lbl.options[i].text, lbl.options[i].value));
         }
      }, 0);

}

For those of you who might use this ASUS product comparison page, enjoy.

Proxy Automatic Config (PAC) File Tips

, ,

I was recently involved in our corporate overhaul of our proxy automatic config (.pac) file. Below are some tips if you ever have to do the same. Since some older clients or custom apps may have poor JavaScript support, or may be considered non-standard, thus:

* Always check url and host parameters prior to using them.
* Validate all built-in JS functions exist prior to calling them.
* Keep the .pac file size as small as possible, to improve download speed.
* Keep comments to a minimum, per above.
* Since "return" is immediate, avoid using "else" for "if" statements, per above.
* Single-line if() statements do not require begin { and end } brackets, per above.
* Avoid calling isResolvable(), dnsResolve(), and isInNet() functions, due to DNS performance issues.
* Check simple rule exceptions first.
* Place high-probability checks early-on and nearest top.
* Avoid using any external or global vars/functions.
* Since .pac files are text and can be downloaded/viewed by anyone, avoid revealing secrets.
* For security reasons, avoid referencing clients by IP addresses.
* Use efficient regular expressions, and avoid capturing matches if you don't reference them later on.
* To avoid typos, only declare unique return strings once (near top for easy maintenance).
* When possible, sort lists of IP addresses and/or domains to ease future maintenance efforts.
* Try to group common return values into single conditional if() checks.
* For single proxy server environments, return the proxy's static IP address to bypass DNS lookup overhead.
* Ensure your text file encoding is proper for your hosting server environment.
* If checking IPs or domains, avoid protocol-specific string comparisons against the url parameter.
* Randomized proxy load-balancing via pac files is not recommended.
* Keep in mind that server access is either proxied or not. Thus, checking ports and protocols is typically not required.
* Be sure to check all conditions and exceptions listed in your .pac file prior to deployment.
* Obviously, ensure your JavaScript is error-free prior to deployment.

Hope this helps. Enjoy.

Remove high CPU caused by Omniture tracking

, , , ...

Opera users that frequent Symantec.com may notice certain pages triggering an extremely high CPU usage for a short burst of time. For example:

http://www.symantec.com/avcenter/threatcon/

A quick analysis of this CPU issue indicates that one JavaScript file is causing this mess:

http://www.symantec.com/content/en/us/omniture/20070301b/OmniScript.js

...most likely due to its inefficient use of deeply nested loops.

As a temporary work-around, you can simply block this script in Opera using the following pattern in the Block content dialog:

http://*.symantec.com/content/*/omniture/*/OmniScript.js

Reloading the example page above shows the high CPU is now gone -- and virtually no page functionality has been lost by blocking this external JavaScript.

Enjoy.

Enhance Opera's mouse cursor over text

, , , ...

Ever wish Opera's mouse cursor behaved like Firefox's or MSIE's in web pages? You know, when you hover over text in a web page, the cursor actually changes to a meaningful text caret, rather than remaining a stupid old default NW mouse cursor.

Usability experts say that text carets (vertical mouse cursor) should be used as a visual feedback mechanism when underlying text can be selected. Plus, text carets do not obscure underlying text, like the default NW mouse cursor does. Personally, this is just one Opera pet peeve solved with User JavaScript.

So, with my latest UserJS script (shown below), now you too can have this 'smart' mouse cursor feature in Opera!

Keep in mind, this script is currently non-optimized for extremely large pages, or pages with poorly written HTML markup and/or scripts. Regardless, it does seem to work pretty well on most sites.

Download/view the textNodes.js script
document.addEventListener("load",
   function() {

      var body = document.getElementsByTagName("BODY");
      if (!body) return;

      var isIgnored = function(node) {
         var bad = /^(SCRIPT)|(STYLE)|(OPTION)|(TEXTAREA)|(INPUT)|(\#cdata\-section)|(\#comment)$/i;
         var result = false;
         while (node && !result) {
            result = (node.nodeName.match(bad) || 
                     ((node.nodeName == "A") && node.href));
            node = node.parentNode;
         }
         return result;
      }

      var nodeIterator = document.createNodeIterator( 
         body[0], 
         NodeFilter.SHOW_TEXT, 
         { acceptNode : function (node) {
            return (/\S+/.test(node.data) && !isIgnored(node)) ?
               NodeFilter.FILTER_ACCEPT:
               NodeFilter.FILTER_REJECT;
           }
         }, 
         true
      );

      var a = new Array();
      var textNode;
      while ((textNode = nodeIterator.nextNode())) { 
         if (!textNode.parentNode.style) continue;
         if (textNode.parentNode.style.cursor != "") continue;
         if (textNode.parentNode.currentStyle.cursor != "default") continue;
         a.push(textNode);
      }

      if (!a.length) return;
      var ss = false;
      var sheet = null;
      for (var i = 0; i < document.styleSheets.length; i++) {
         sheet = document.styleSheets[i];
         ss = (!sheet.media || !sheet.media.length);
         if (ss) break;
         for (var j = 0, m; m = sheet.media[j]; j++) {
            ss = (m.match(/^(\*)|(all)|(screen)$/i));
            if (ss) break;
         }
      }

      if (ss) sheet.insertRule(
         "SPAN.crsrTxt { \
         font: inherit !important; \
         color: inherit !important; \
         background: none !important; \
         padding: 0 0 0 0 !important; \
         margin: 0 0 0 0 !important; \
         clear: none !important; \
         z-index: inherit !important; \
         float: none !important; \
         display: inline !important; \
         cursor: text !important; }", 0);

      while ((textNode = a.pop())) {
         var span = document.createElement("span");
         if (ss)   span.className = "crsrTxt";
         else {
            span.style.color = "inherit";
            span.style.background = "none";
            span.style.padding = "0 0 0 0";
            span.style.margin = "0 0 0 0";
            span.style.clear = "none";
            span.style.zIndex = "inherit";
            span.style.float = "none";
            span.style.display = "inline";
            span.style.cursor = "text";
         }
         textNode.parentNode.insertBefore(span, textNode);
         span.appendChild(textNode);
      }
   }, 0);

I'll keep this blog entry updated to reflect the most recent version of the script, so stay tuned.

Known issue:
  • Script may not work on poorly coded HTML and JavaScript websites (foxnews.com)
  • There's a known crash bug in Opera 9.20 when using this script on newegg.com

BTW, feedback is always appreciated.

Enjoy.

UserJS fix for Yahoo!'s global search box stealing keystrokes

, , , ...

If you're a regular reader of this blog, then you realize how much I despise Yahoo! web developers. Their latest trick is to steal ALL keyboard input using a setTimeout event poller, then place the keystrokes into their stupid global search edit box at the top of the page. Nice going losers.

Anyhow, if you use Yahoo! Sports, and use ANY keyboard commands in Opera, then I highly recommend downloading this script.

Download/view the yahooSport.js script:
if (document.domain.match(/sports\.yahoo\.com$/)) {
  document.addEventListener("load",
    function() {
      document.sf1 = null;
    }, 0);
}

Enjoy.

UserJS to fix printing TitanTV.com schedules

, , , ...

Mason C reported in the opera.general newsgroup on Jan 30, 2007 that TitanTV.com schedules could not be printed in Opera. After reviewing his claim, I confirmed it and wrote this UserJS script to work-around the problem:

Download/view the titantv.js script
if (document.domain.match(/^(www\.)?titantv\.com$/)) {
   document.addEventListener("load",
      function(e) {
         var inps = document.getElementsByTagName("input");
         for (var i = 0, o; o = inps[i]; i++) {
            if (o.type != "image") continue;
            if (o.getAttribute("alternate") != "Print") continue;
            o.onclick = "window.open(document.forms.Form1.__PrintUrl.value,'','');";
            break;
         }
      }, 0);
}

NOTE: Once the script is installed, reload the page, then click the blue [Print] button that appears on the upper-right corner of their TV schedule pages. Clicking [Print] will open a new pop-up window with a printer-friendly version of the page -- so be sure your Opera pop-up blocker is not set to "Block All". And as always with UserJS scripts, be sure JavaScript is enabled, and that you place the .js file in the correct UserJS folder.

For those of you who use TitanTV.com (very nice, btw, compared to TVGuide.com), and prefer to print-out hard-copies of their TV schedules...enjoy.

UserJS to fix NFL.com RealPlayer video

, , , ...

For whatever reason, Opera disallows calling the DoStop(), DoPlay(), etc methods of the RealPlayer plug-in on nfl.com -- perhaps for security reasons, since the script which injects the tag is located on images.nfl.com, but the homepage is on www.nfl.com.

Anyhow, this latest script provides a work-around by rewriting the HTML inside the tag hosting the RealPlayer plug-in. In essence, it simply sets the autoplay attribute to true, which allows the video to play when users click a video link.

Download/view the nfl.js script
if (document.domain.match(/^(www\.|images\.)?nfl\.com$/)) {
  window.opera.defineMagicFunction("goMovie",
    function (a,b,selection) {
      var videoplayer = document.getElementById("videoplayer");
      if (!videoplayer) return;
      videoplayer.innerHTML = '<PARAM name="autostart" value="true"/> \
        <PARAM name="controls" value="imagewindow"/> \
        <PARAM name="src" value="' + selection + '"/> \
        <PARAM name="console" value="cons"/> \
        <PARAM name="nologo" value="true"/> \
        <EMBED name="videoplayer" type="audio/x-pn-realaudio-plugin" width="240" height="180" nologo="true" src="' + selection + '" controls="imagewindow" autostart="true" console="cons"/>';
    });
}

To learn how to install this User JavaScript, visit UserJS.org

Enjoy.

UserJS to fix Yahoo! Football Play by Play

, , , ...

Yes, Yahoo! stinks when it comes to web coding. Simply right-click any of their pages in Opera, select "Validate", and then watch the markup errors pile-up.

Anyhow, this latest script fixes their NFL and NCAA football play by play display in Opera.

For example:

yahooNFL.js
if (document.domain.match(/^sports\.yahoo\.com$/) && 
  window.location.href.match(/&page=plays/)) {
  document.addEventListener("load",
    function() {
      var yspMainContent = document.getElementById("yspMainContent");
      if (!yspMainContent) return;
      yspMainContent.innerHTML = yspMainContent.innerHTML.replace(/\<thead\>/gi, '<table width="560" border="0" cellpadding="0" cellspacing="0"><thead>');
      yspMainContent.innerHTML = yspMainContent.innerHTML.replace(/\<\/tbody\>/gi, '</tbody></table>');
      }, 0);
}

To learn how to install this User JavaScript, visit UserJS.org

Enjoy.

UserJS to fix Disney Channel

, , , ...

The kids discovered this one: Disney Channel blocks Opera when older versions (7.0) of Flash are installed.

Here's a really simple User JavaScript to allow Disney Channel to use Flash 7.0, etc...

disneychannel.js:
if (document.domain.match(/\.disney\.go\.com$/)) {
   window.opera.defineMagicFunction("DetectFlash",
      function(RealFunc, oThis, nversion, redirect, override) {
         return 1;
      });
}

Enjoy kiddies.