-
-
Save rschrieken/8a3b04390b7fb3600c8056b039a21d24 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 comment timer | |
// @namespace http://your.homepage/ | |
// @version 0.1 | |
// @description comment rtimer | |
// @author rene | |
// @match http://meta.stackexchange.com/questions/* | |
// @match http://stackoverflow.com/questions/* | |
// @match http://meta.stackoverflow.com/questions/* | |
// @grant none | |
// ==/UserScript== | |
(function () { | |
var observer = new MutationObserver(function(mutations) { | |
mutations.forEach(function(mutation) { | |
if (mutation.addedNodes.length === 0) { | |
return; | |
} | |
console.log(mutation); | |
var time = new Date().getTime(), | |
interval, | |
ce = $(mutation.target).find('a.comment-edit'); | |
//console.log(ce); | |
if (ce.length>0) { | |
observer.disconnect(); | |
var mtr = $('<meter max="300000"></meter>'); | |
ce.append(mtr); | |
interval = window.setInterval(function() { | |
var diff = Date.now() - time; | |
mtr.prop('value', diff); | |
if (diff > 300000) { | |
mtr.remove(); | |
window.clearInterval(interval); | |
} | |
}, 5000); | |
} | |
}); | |
}); | |
// configuration of the observer: | |
var config = {childList: true, subtree: true}; | |
$('#mainbar').on('click','.js-add-link.comments-link', function() { | |
// pass in the target node, as well as the observer options | |
console.log($(this).parent().prop('id').replace('-link','')); | |
observer.observe(document.querySelector('#'+$(this).parent().prop('id').replace('-link','')), config); | |
}); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment