Source for "Mefi deleted posts"

By Plutor
Has 13 other scripts.


// ==UserScript==
// @name           Mefi deleted posts
// @namespace      http://plutor.org/
// @description    Shows deleted posts on the Metafilter front page
// @include        http://www.metafilter.com/
// @include        http://www.metafilter.com/daily.mefi/*
// @include        http://www.metafilter.com/index.cfm?*
// @include        http://www.metafilter.com/home/recentposts
// @include        http://*.metafilter.com/
// @include        http://*.metafilter.com/daily.mefi/*
// @include        http://*.metafilter.com/index.cfm?*
// @include        http://*.metafilter.com/home/recentposts
// ==/UserScript==
//
// DONE 2008-03-25
// * Make it work on all subsites
// * Turn off that dumb debug logging!
// * Fix some of the out-of-order false positives on AskMe
// * Sensible variable names
// TODO
// * AJAX to inline FPP text?
// * Fix the rest of the out-of-order false positives on AskMe with AJAX

(function () {
    var xpath = "//div[@class='copy']/span[@class='smallcopy'][a[contains(@href,'/user/')]]/a[contains(text(),' comment') or contains(text(),' answer')]";

    /* Thanks to Jerry Kindall (http://www.jerrykindall.com/) */
    for (n in document.forms[0].elements)
        if (document.forms[0].elements[n] && document.forms[0].elements[n].name == "sortby" &&
            document.forms[0].elements[n].value != "date") 
            return;

    var candidates = document.evaluate(xpath, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
    var i = 0;
    var threadlist = new Array();
    var threadinfo = new Object();

    // First pass, collect all the thread objects and ids
    for (var cand = null, i = 0; (cand = candidates.snapshotItem(i)); i++) {
        var url = cand.href;
        var pathstart = url.indexOf('metafilter.com/') + 15;
        var threadidend = url.substring(pathstart).indexOf('/') + pathstart;

        if (pathstart >= 15 && threadidend > pathstart) {
            var threadid = parseInt(url.substring(pathstart,threadidend));
            var anon = cand.parentNode.innerHTML.indexOf("/user/17564");

            threadlist.push(threadid);
            threadinfo[threadid] = { obj: cand,
                                     anon: (anon != -1) };
        }
    }

    // Second pass, find the deleted threads
    var lastthread = 0;
    for (var i=0; i<threadlist.length; ++i) {
        var threadid = threadlist[i];

	if (!threadinfo[threadid] || threadinfo[threadid].anon) continue;
        var thread = threadinfo[threadid].obj;

        if ((lastthread > 0) && (threadid < lastthread - 1)) {
            var post = thread.parentNode.parentNode;
            for (var j = lastthread - 1; j > threadid; --j) {
                if (threadinfo[j]) continue;
                var nt = document.createElement('div');
                nt.className = "copy";
                var ntd = document.createElement('span');
                ntd.className = "smallcopy"
                ntd.style.color = "#f99";
                ntd.style.marginLeft = "1em";
                var nta = document.createElement('a');
                nta.href = "/" + j + "/";

                nta.appendChild( document.createTextNode(j) );
                ntd.appendChild( document.createTextNode("Deleted thread: ") );
                ntd.appendChild( nta );
                nt.appendChild( ntd );
                post.parentNode.insertBefore(nt, post);
                post.parentNode.insertBefore(document.createElement('br'), post);
            }
        }

        lastthread = threadid;
    }
})();