Skip to content

Instantly share code, notes, and snippets.

@xqwzts
Created October 22, 2014 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xqwzts/707f4e675f3847a8ae3b to your computer and use it in GitHub Desktop.
Save xqwzts/707f4e675f3847a8ae3b to your computer and use it in GitHub Desktop.
// ==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