deadspace の 単機能 bookmarklet 群

http://mayokara.info/deadspace/#d20090429

単機能ブックマークレット群。面白い。この bookmarklet がどういうふうになっているかを調べるだけでも意味がある。オレには。たぶん。丸々コピペ。deadspace アーカイブされると url が変わっちゃうからな。

  1. up

    ハッシュの除去 or クエリの除去 or 一つ上の階層に移動 or ドメインの一番左をwwwに or ドメインの一番左を除去。

    javascript:'up';(function(L){
    L.hash ? L.hash = '' :
    L.search ? L.search = '' :
    L.pathname !== '/' ? L.href = /\/$/.test(L.pathname) ? '../' : './' :
    L.hostname = L.hostname.replace(/^[^.]+\./, function($0){return $0 !== 'www.' ? 'www.' : '';});
    })(location);
  2. guess

    href群をソートして次のURLを推測し、移動(ITmediaの分割記事などで使う)。

    javascript:'guess';(function(d,L){
    var xp = d.evaluate('/h:html/h:head/h:link|/h:html/h:body/descendant::h:a', d, function(){return d.contentType !== "text/html" ? "http://www.w3.org/1999/xhtml" : "";}, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null), ary = [];
    for (var i=0,l=xp.snapshotLength,n; i L.href && !~n.href.indexOf("#")) ary.push(n.href);
    }
    ary.sort();
    if (ary[0]) L.href = ary[0];
    })(document,location);
  3. next

    rel-nextが指定されているURLに移動。
    javascript:'next';(function(d){
    var n = d.evaluate('(/h:html/h:head/h:link|/h:html/h:body/descendant::h:a)[contains(concat(" ",translate(@rel,"ENTX","entx")," ")," next ")]', d, function(){return d.contentType !== "text/html" ? "http://www.w3.org/1999/xhtml" : "";}, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
    if (n) location.href = n.href;
    })(document);
  4. prev

    rel-prevが指定されているURLに移動。
    javascript:'prev';(function(d){
    var n = d.evaluate('(/h:html/h:head/h:link|/h:html/h:body/descendant::h:a)[contains(concat(" ",translate(@rel,"EPRV","eprv")," ")," prev ")]', d, function(){return d.contentType !== "text/html" ? "http://www.w3.org/1999/xhtml" : "";}, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
    if (n) location.href = n.href;
    })(document);
  5. forward

    次の見出しまでスクロールする。
    javascript:'forward';(function(d,w){
    var xp = d.evaluate('descendant::*[self::h:h1 or self::h:h2 or self::h:h3 or self::h:h4 or self::h:h5 or self::h:h6]', d.body, function(){return d.contentType !== "text/html" ? "http://www.w3.org/1999/xhtml" : "";}, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
    for (var i=0,l=xp.snapshotLength,dy; i 0) {
    w.scrollBy(0, dy);
    return;
    }
    }
    w.scrollTo(w.scrollX, w.scrollMaxY);
    })(document,window);
  6. backward

    前の見出しまでスクロールする。
    javascript:'backward';(function(d,w){
    var xp = d.evaluate('descendant::*[self::h:h1 or self::h:h2 or self::h:h3 or self::h:h4 or self::h:h5 or self::h:h6]', d.body, function(){return d.contentType !== "text/html" ? "http://www.w3.org/1999/xhtml" : "";}, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
    for (var i=xp.snapshotLength-1,dy; i>=0; i--) {
    dy = Math.floor(xp.snapshotItem(i).getBoundingClientRect().top);
    if (dy < 0) {
    w.scrollBy(0, dy);
    return;
    }
    }
    w.scrollTo(w.scrollX, 0);
    })(document,window);
  7. incl

    URL中の最後の数字を1増やす。
    javascript:'incl';(function(L){
    var r = L.href.replace(/^([^:]+:\/\/[^/]*\/.*?)(\d+)(\D*)$/, function($0,$1,$2,$3){
    var n = String(parseInt($2,10)+1);
    return $1 + new Array($2.length-n.length+1).join("0") + n + $3;
    });
    if (r !== L.href) L.href = r;
    })(location);
  8. decl

    URL中の最後の数字を1減らす。
    javascript:'decl';(function(L){
    var r = L.href.replace(/^([^:]+:\/\/[^/]*\/.*?)(\d+)(\D*)$/, function($0,$1,$2,$3){
    var n = String(parseInt($2,10)-1);
    return n < 0 ? $0 : $1 + (/^0/.test($2) ? new Array($2.length-n.length+1).join("0") + n : n) + $3;
    });
    if (r !== L.href) L.href = r;
    })(location);