Skip to content

Instantly share code, notes, and snippets.

@rschrieken
Last active April 8, 2021 04:29
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 rschrieken/8a3b04390b7fb3600c8056b039a21d24 to your computer and use it in GitHub Desktop.
Save rschrieken/8a3b04390b7fb3600c8056b039a21d24 to your computer and use it in GitHub Desktop.
// ==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