Created
October 23, 2014 16:43
-
-
Save anonymous/f9031a38c756e93ddc6d to your computer and use it in GitHub Desktop.
So the last will be first
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 so the last will be first | |
// @namespace http://www.zedlopez.org/ | |
// @description commentator | |
// @include http://*.metafilter.com/* | |
// @version 1 | |
// @grant none | |
// ==/UserScript== | |
(function so_the_last_will_be_first() { | |
if (document.URL.match(/((www|ask|fanfare|projects|music|podcast|irl|metatalk)\.)?metafilter.com\/[1-9]/)) { | |
var flag, fav, idstring; | |
var comments = document.getElementsByClassName('comments'); | |
for (var i=0, comment; comment = comments[i++];) { | |
var smallcopies = comment.getElementsByClassName('smallcopy'); | |
if (smallcopies.length !== 1) { continue; } | |
var smallcopy = smallcopies[0]; | |
var subspans = smallcopy.getElementsByTagName('span'); | |
for (var j=0,subspan;subspan = subspans[j++];) { | |
var id = subspan.getAttribute('id'); | |
if (id === null) { continue; } | |
if (idstring = id.match(/^fav(\d+)$/)) { | |
fav = smallcopy.removeChild(subspan); | |
break; | |
} | |
} | |
if (comment.classList.contains("best")) { | |
smallcopy.appendChild(document.createTextNode("[marked as best answer]")); | |
} | |
smallcopy.removeChild(smallcopy.firstChild); // posted by | |
flag = document.getElementById("flag"+idstring[1]); | |
if (flag !== null) { smallcopy.removeChild(flag); } | |
comment.insertBefore(document.createElement('br'),comment.firstChild); | |
comment.insertBefore(smallcopy, comment.firstChild); | |
//comment.insertBefore(document.createElement('hr'),comment.firstChild); | |
var trailer = document.createElement('small'); | |
trailer.appendChild(fav); | |
if (flag !== null) { trailer.appendChild(flag); } | |
trailer.appendChild(document.createElement('hr')); | |
comment.appendChild(trailer); | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment