Instantly share code, notes, and snippets.

Embed
What would you like to do?
Restore deleted (and filterred) livefyre comments
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
// (this would restore the liker images but must then restore the
// comment footer too)
// mutation.removedNodes.forEach(function(entry) {
// if ($(entry).hasClass('fyre-comment-like-imgs')) {
// $(mutation.target).append(entry);
// }
//});
// show the comment
if (mutation.type == "attributes") {
if ($(mutation.target).hasClass('fyre-comment-wrapper')) {
$(mutation.target).show();
}
}
// remove .fyre-comment-hidden
if (mutation.type == "attributes") {
if ($(mutation.target).hasClass('fyre-comment-hidden')) {
$(mutation.target).removeClass('fyre-comment-hidden');
}
}
// 5 - remove various nodes
mutation.removedNodes.forEach(function(entry) {
if ($(entry).hasClass('fyre-comment-user')) {
$(mutation.target).append(entry);
}
if ($(entry).hasClass('fyre-comment-head')) {
$(mutation.target).append(entry);
}
if ($(entry).hasClass('fyre-comment-body')) {
var target = $(mutation.target);
target.append(entry);
target.find('section.fyre-comment-deleted').remove();
target.css('background-color', '#ffcccc');
}
// do not restore footer as cannot like a deleted comment
//if ($(entry).hasClass('fyre-comment-footer')) {
// $(mutation.target).append(entry);
//}
});
});
});
// don't need character data notifications
var options = {
attributes: true,
childList: true,
characterData: false,
subtree: true,
attributeOldValue: true,
characterDataOldValue: false
};
// start the observer on the comment stream
var root = $('.fyre-comment-stream');
observer.observe(root[0], options);
console.log('start observer');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment