showAllIdAndClassName

    @@ -48,10 +48,10 @@ } if(window.addEventListener) { - window.addEventListener('scroll', scrollTop, false); + //window.addEventListener('scroll', scrollTop, false); a.addEventListener('click', close, false); } else { - window.attachEvent('onscroll', scrollTop); + //window.attachEvent('onscroll', scrollTop); a.attachEvent('onclick', close); }
  • /*
     * @title showAllIdAndClassName
     * @description ページ内で使われているクラス名を全部表示idも
     * @include http://*
     * @license MIT License
     * @require 
     */
    
    var all = document.all || document.getElementsByTagName('*');
    var div = document.createElement('DIV');
    var a = document.createElement('A');
    var ul = document.createElement('UL');
    a.textContent = a.innerText = "close";
    var y = document.documentElement.scrollTop || document.body.scrollTop ;
    div.style.position = 'absolute';
    div.style.top = y+'px';
    div.style.right = '8px';
    div.style.zIndex = '9999';
    div.style.backgroundColor = "#ccc";
    div.maxHeight = '100%';
    
    
    // class名の取得
    var l = 0;
    var loop = all.length;
    var li = new Array();
    for(var i=0; i<loop; i++){
      if(all[i].className){
        li[l] = document.createElement('LI');
        li[l].textContent = li[l].innerText = '.' + all[i].className;
        ul.appendChild(li[l]);
        l++;
      }
      if(all[i].id){
        li[l] = document.createElement('LI');
        li[l].textContent = li[l].innerText = '#' + all[i].id;
        ul.appendChild(li[l]);
        l++;
      }
    }
    
    function close(){
        div.parentNode.removeChild(div);
    }
    function scrollTop(){
        var y = document.documentElement.scrollTop || document.body.scrollTop ;
        div.style.top = y+'px';
    }
    
    if(window.addEventListener) {
        //window.addEventListener('scroll', scrollTop, false);
        a.addEventListener('click', close, false);
    } else {
        //window.attachEvent('onscroll', scrollTop);
        a.attachEvent('onclick', close);
    }
    
    document.body.appendChild(div);
    div.appendChild(ul);
    div.appendChild(a);
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。

History

  1. 2014/01/17 19:36:02 - 2014-01-17
  2. 2014/01/17 19:33:30 - 2014-01-17
  3. 2014/01/17 19:28:53 - 2014-01-17
  4. 2014/01/17 19:16:56 - 2014-01-17