2009-01-16

面倒くさくなった

// ==UserScript==
// @name           anond
// @namespace      http://anond.hatelabo.jp/
// @include        http://anond.hatelabo.jp/?page=*
// ==/UserScript==
function anond(doc) {
    $X(".//div[@class='section'][.//h3/a[2][starts-with(@href, 'http://anond.hatelabo.jp')]]", doc, Array).forEach(function(node){
        node.style.display = "none";
    });
    $X(".//h3/a[1]", doc, Array).forEach(function(node){
        var a = document.createElement("a");
        a.name = node.pathname;
        a.href = "#" + node.pathname + "/footer";
        a.innerHTML = "V";
        node.parentNode.insertBefore(a, node);
    });
    $X(".//p[@class = 'sectionfooter']/a[1]", doc, Array).forEach(function(node){
        var a = document.createElement("a");
        a.name = node.pathname + "/footer";
        a.href = "#" + node.pathname;
        a.innerHTML = "^";
        node.parentNode.insertBefore(a, node);
        node.parentNode.insertBefore(document.createTextNode(" | "), node);
    });
}

anond(document);
if (AutoPagerize.addDocumentFilter)
    AutoPagerize.addDocumentFilter(anond);


// by http://lowreal.net/blog/2007/11/17/1
// $X(exp);
// $X(exp, context);
// $X(exp, type);
// $X(exp, context, type);
function $X (exp, context, type /* want type */) {
    if (typeof context == "function") {
        type    = context;
        context = null;
    }
    if (!context) context = document;
    var exp = (context.ownerDocument || context).createExpression(exp, function (prefix) {
        var o = document.createNSResolver(context).lookupNamespaceURI(prefix);
        if (o) return o;
        return (document.contentType == "application/xhtml+xml") ? "http://www.w3.org/1999/xhtml" : "";
    });

    switch (type) {
        case String:
            return exp.evaluate(
                context,
                XPathResult.STRING_TYPE,
                null
            ).stringValue;
        case Number:
            return exp.evaluate(
                context,
                XPathResult.NUMBER_TYPE,
                null
            ).numberValue;
        case Boolean:
            return exp.evaluate(
                context,
                XPathResult.BOOLEAN_TYPE,
                null
            ).booleanValue;
        case Array:
            var result = exp.evaluate(
                context,
                XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
                null
            );
            var ret = [];
            for (var i = 0, len = result.snapshotLength; i < len; i++) {
                ret.push(result.snapshotItem(i));
            }
            return ret;
        case undefined:
            var result = exp.evaluate(context, XPathResult.ANY_TYPE, null);
            switch (result.resultType) {
                case XPathResult.STRING_TYPE : return result.stringValue;
                case XPathResult.NUMBER_TYPE : return result.numberValue;
                case XPathResult.BOOLEAN_TYPE: return result.booleanValue;
                case XPathResult.UNORDERED_NODE_ITERATOR_TYPE: {
                    // not ensure the order.
                    var ret = [];
                    var i = null;
                    while (i = result.iterateNext()) {
                        ret.push(i);
                    }
                    return ret;
                }
            }
            return null;
        default:
            throw(TypeError("$X: specified type is not valid type."));
    }
}

記事への反応(ブックマークコメント)

ログイン ユーザー登録
ようこそ ゲスト さん