Advertisement
Guest User

Untitled

a guest
Mar 12th, 2009
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // This hides all Unfogged comments from read, inserting a button in their place to redisplay the comment.
  2. // It also inserts one at the top of the page to show all hidden comments.
  3. // ==UserScript==
  4. // @name           Put a sock in it, read.
  5. // @namespace      http://pasiir.unfogged.com/
  6. // @include        http://www.unfogged.com/archives/comments_*
  7. // ==/UserScript==
  8.  
  9. var allComments;
  10. var readcoms = 0;
  11. allComments = document.evaluate("//span[@class='comments-post']", document, null,
  12.                                 XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
  13. for (var i = 0; i < allComments.snapshotLength; i++) {
  14.     thisSpan = allComments.snapshotItem(i);
  15. //    if (thisSpan.innerText.substring(15,0) == 'Posted by: read') {
  16.     if (thisSpan.childNodes[0].nodeValue.match(/read/)) {
  17.         readcoms += 1;
  18.         postDiv = thisSpan.parentNode;
  19.     button = document.createElement('a');
  20.     button.style.color = 'blue';
  21.     button.style.display = 'block';
  22.     button.className = 'read-comment-button';
  23.     button.appendChild(document.createTextNode("Removed comment by read. Click to show."));
  24.     postDiv.parentNode.insertBefore(button, postDiv);
  25.     button.addEventListener('click', function() {this.nextSibling.style.display = 'block'; this.style.display = 'none';}, false);
  26.     postDiv.style.display = 'none';
  27.     }
  28. }
  29. if (readcoms) {
  30.     button = document.createElement('a');
  31.     button.style.color = 'blue';
  32.     button.style.display = 'block';
  33.     button.className = 'read-comment-button';
  34.     button.appendChild(document.createTextNode("This post contains comments by read. Click to show all."));
  35.     document.body.insertBefore(button, document.body.childNodes[0]);
  36.     button.addEventListener('click', function() {
  37.       buts = document.evaluate("//a[@class='read-comment-button']",
  38.                     document, null,
  39.                     XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
  40.                     null);
  41.       for (var i = 0; i < buts.snapshotLength; i++) {
  42.         thisBut = buts.snapshotItem(i);
  43.         com = thisBut.nextSibling;
  44.         while (com.nodeType == 3) com = com.nextSibling;
  45.         com.style.display = 'block';
  46.         thisBut.style.display = 'none';
  47.       }
  48.     }, false);
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement