Last active
November 20, 2016 17:54
-
-
Save holly4/46095e28fb5042fbdb279ae509010606 to your computer and use it in GitHub Desktop.
Restore deleted (and filterred) livefyre comments
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
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