Skip to content

Instantly share code, notes, and snippets.

@SleepProgger
Created July 18, 2015 01:23
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 SleepProgger/9faa2d04a182f6e97b9e to your computer and use it in GitHub Desktop.
Save SleepProgger/9faa2d04a182f6e97b9e to your computer and use it in GitHub Desktop.
// ==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