Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// ==UserScript==
// @name Metafilter comment signature reordering
// @namespace mefireordersignature
// @description
// @include http://*.metafilter.com/*
// @include https://*.metafilter.com/*
// @version 0.0.1
// @grant none
// ==/UserScript==
// get all the signatures denoted by the smallcopy class
$(".comments > .smallcopy").each(function() {
var contents = $(this).contents(); // the contents of this smallcopy span
var topSpan = $("<span>"); // the new span we'll be placing at the top of the comment
for (var i = 0; i < contents.length; i++) {
var node = contents[i];
// discard the "posted by" node
if (node.nodeType == 3 && node.textContent.trim() == "posted by") {
$(node).detach();
continue;
}
// check if we've reached the "at" node
if (node.nodeType == 3 && node.textContent.trim() == "at") {
// get rid of it
$(node).detach();
// then stop: everything after it stays in place
break;
}
// this is before the "at" node so add it to our new span
topSpan.append(node);
}
// add " posted:" at the end of the new span
topSpan.append(" posted:");
// assign the same smallcopy class for styling
topSpan.addClass("smallcopy");
// place it at the beginning of the comment div
$(this).parent().prepend(topSpan);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment