findhash

By myfonj Last update Feb 11, 2008 — Installed 157 times.
// ==UserScript==
// @name           findhash
// @namespace      http://eldar.cz/myf/pub/firefox/
// @description    tries to find(url#hash) if no matching ID or anchor is present
// @include        *
// ==/UserScript==

(function(){
 if ( !window.find
   || !window.location.hash
   || window.location.hash.length < 2
  ) {
  return false // unable to search or nothing to look for
 }
 var h = window.location.hash.substring(1);
 if ( document.getElementById(h) ) {
  return false // ID present
 }
 if ( document.anchors && document.anchors.length ) {
  var l, i = -1;
  while ( l = document.anchors[++i] ) {
   if ( l.name == h ) {
    return false // anchor present
   }
  }
 }
 if ( !window.addEventListener ) {
  window.find( decodeURI(h) );
 } else {
  window.addEventListener(
   // type:
    'load'
   ,
   // listener:
    function(){
     window.find(
      // aString:
       decodeURI(h)
      ,
      // aCaseSensitive:
       false
      ,
      // aBackwards:
       false
      ,
      // aWrapAround:
       false
      ,
      // aWholeWord:
       false
      ,
      // aSearchInFrames:
       false
      ,
      // aShowDialog:
      //  must be also true while aSearchInFrames is enabled
      //  otherwise it will cause 'Error: Access to restricted URI denied'
       false
     );
    }
   ,
   // useCapture:
    false
   )
  ;
 }
})();