Created
October 22, 2014 15:32
-
-
Save xqwzts/707f4e675f3847a8ae3b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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