Metafilter Comment Box Logout

Adds a "logout" link to the right of your username above the comment box.

  1. // ==UserScript==
  2. // @name Metafilter Comment Box Logout
  3. // @namespace http://example.com/metafilter_comment_box_logout
  4. // @description Adds a "logout" link to the right of your username above the comment box.
  5. // @include http://metafilter.com/*
  6. // @include http://*.metafilter.com/*
  7. // @version 1
  8. // ==/UserScript==
  9.  
  10. var commentBoxSnap = document.evaluate(
  11. "//textarea[@name='comment']", document, null,
  12. XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  13. var table = null;
  14. if (commentBoxSnap.snapshotLength > 0) {
  15. var commentBox =
  16. commentBoxSnap.snapshotItem(commentBoxSnap.snapshotLength - 1);
  17. table = commentBox.parentNode.parentNode.parentNode;
  18. }
  19.  
  20. var tr = null;
  21. if (table != null) {
  22. var trSnap = document.evaluate("tr", table, null,
  23. XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  24.  
  25. if (trSnap.snapshotLength > 0) {
  26. tr = trSnap.snapshotItem(0);
  27. }
  28. }
  29.  
  30. var link = null;
  31. if (tr != null) {
  32. var linkSnap = document.evaluate(
  33. "td/span/a[starts-with(@href, 'http://www.metafilter.com/user/')]",
  34. tr, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  35. if (linkSnap.snapshotLength > 0) {
  36. link = linkSnap.snapshotItem(0);
  37. }
  38. }
  39.  
  40. if (link != null) {
  41. var span = link.parentNode;
  42. span.innerHTML += " (<a href=\"http://www.metafilter.com/index.cfm?delcookie=yes\">logout</a>)";
  43. }