Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This hides all Unfogged comments from read, inserting a button in their place to redisplay the comment.
- // It also inserts one at the top of the page to show all hidden comments.
- // ==UserScript==
- // @name Put a sock in it, read.
- // @namespace http://pasiir.unfogged.com/
- // @include http://www.unfogged.com/archives/comments_*
- // ==/UserScript==
- var allComments;
- var readcoms = 0;
- allComments = document.evaluate("//span[@class='comments-post']", document, null,
- XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
- for (var i = 0; i < allComments.snapshotLength; i++) {
- thisSpan = allComments.snapshotItem(i);
- // if (thisSpan.innerText.substring(15,0) == 'Posted by: read') {
- if (thisSpan.childNodes[0].nodeValue.match(/read/)) {
- readcoms += 1;
- postDiv = thisSpan.parentNode;
- button = document.createElement('a');
- button.style.color = 'blue';
- button.style.display = 'block';
- button.className = 'read-comment-button';
- button.appendChild(document.createTextNode("Removed comment by read. Click to show."));
- postDiv.parentNode.insertBefore(button, postDiv);
- button.addEventListener('click', function() {this.nextSibling.style.display = 'block'; this.style.display = 'none';}, false);
- postDiv.style.display = 'none';
- }
- }
- if (readcoms) {
- button = document.createElement('a');
- button.style.color = 'blue';
- button.style.display = 'block';
- button.className = 'read-comment-button';
- button.appendChild(document.createTextNode("This post contains comments by read. Click to show all."));
- document.body.insertBefore(button, document.body.childNodes[0]);
- button.addEventListener('click', function() {
- buts = document.evaluate("//a[@class='read-comment-button']",
- document, null,
- XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
- null);
- for (var i = 0; i < buts.snapshotLength; i++) {
- thisBut = buts.snapshotItem(i);
- com = thisBut.nextSibling;
- while (com.nodeType == 3) com = com.nextSibling;
- com.style.display = 'block';
- thisBut.style.display = 'none';
- }
- }, false);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement