Metafilter Comment Box Logout

Adds a "logout" link to the right of your username above the comment box.

当前为 2014-05-24 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        Metafilter Comment Box Logout
// @namespace   http://example.com/metafilter_comment_box_logout
// @description Adds a "logout" link to the right of your username above the comment box.
// @include        http://metafilter.com/*
// @include        http://*.metafilter.com/*
// @version     1
// ==/UserScript==

var commentBoxSnap = document.evaluate(
    "//textarea[@name='comment']", document, null,
    XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
var table = null;
if (commentBoxSnap.snapshotLength > 0) {
    var commentBox =
        commentBoxSnap.snapshotItem(commentBoxSnap.snapshotLength - 1);
    table = commentBox.parentNode.parentNode.parentNode;
}

var tr = null;
if (table != null) {
    var trSnap = document.evaluate("tr", table, null, 
        XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);

    if (trSnap.snapshotLength > 0) {
        tr = trSnap.snapshotItem(0);
    }
}

var link = null;
if (tr != null) {
    var linkSnap = document.evaluate(
        "td/span/a[starts-with(@href, 'http://www.metafilter.com/user/')]",
        tr, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
    
    if (linkSnap.snapshotLength > 0) {
        link = linkSnap.snapshotItem(0);
    }
}

if (link != null) {
    var span = link.parentNode;
    span.innerHTML += " (<a href=\"http://www.metafilter.com/index.cfm?delcookie=yes\">logout</a>)";
}