-
-
Save SleepProgger/9faa2d04a182f6e97b9e 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 imgur_enrich_comments.user.js | |
// @namespace foo | |
// @include http://imgur.com/* | |
// @version 1 | |
// @grant none | |
// ==/UserScript== | |
function patch_comment(node, data){ | |
var jnodes = $(node).find(".author span"); | |
var points = jnodes.get(1); | |
var date = jnodes.get(3); | |
points.title = "+ " + data.ups + " / - " + data.downs; | |
date.title = data.datetime; | |
$(points).tipsy(); | |
$(date).tipsy(); | |
} | |
// patch all existing comments ... | |
$(".caption").each(function(){ patch_comment(this, Imgur.InsideNav._instance._.captionInstance._.captions[imgur._.hash].set[this.getAttribute('data-id')]); }); | |
// and register for dom changes to patch the new ones. | |
observer = new MutationObserver(function(mutations) { | |
var captions = Imgur.InsideNav._instance._.captionInstance._.captions[imgur._.hash].set; | |
for(var i=0; i < mutations.length; ++i){ | |
for(var j=0; j < mutations[i].addedNodes.length; ++j){ | |
var node = mutations[i].addedNodes[j]; | |
if( node.className === undefined )continue; | |
if( node.className.indexOf("comment") == 0 || node.className.indexOf("children") == 0){ | |
$(node).find('.caption').each(function(){ | |
patch_comment(this, captions[this.getAttribute('data-id')]); | |
}); | |
} | |
} | |
} | |
}); | |
var target = document.querySelector('body'); | |
observer.observe(target, { subtree: true, childList: true }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment