What.CD : Mark The OP

Marks the thread's [OP]

  1. // ==UserScript==
  2. // @id whatcd-mark-op
  3. // @name What.CD : Mark The OP
  4. // @namespace hateradio)))
  5. // @description Marks the thread's [OP]
  6. // @include http*://*what.cd/forums.php*viewthread*
  7. // @version 1.1.1
  8. // @created 17 June 2012
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function(){
  13. var mark = {
  14. id : 0,
  15. doc : document,
  16. findOP: function(){
  17. var a = document.querySelector('.breadcrumbs ~ .linkbox a:first-child'), xhr = new XMLHttpRequest();
  18. if(a && a.textContent === '<< First'){
  19. xhr.open('get', a.href, true);
  20. xhr.onload = this.xhr;
  21. xhr.send(null);
  22. }else{
  23. this.proc();
  24. }
  25. },
  26. xhr: function(){
  27. var d = document.implementation.createHTMLDocument('');
  28. d.documentElement.innerHTML = this.responseText;
  29. mark.doc = d;
  30. mark.proc();
  31. },
  32. proc : function(){
  33. this.grabID();
  34. if(this.id > 0){
  35. this.grabPosts();
  36. this.modPosts();
  37. }
  38. },
  39. grabID : function(){
  40. var u = this.doc.querySelector('table.forum_post a[href*="user.php"]');
  41. if(/(?:id=(\d+))/.test(u)){
  42. this.id = RegExp.lastParen;
  43. }
  44. },
  45. grabPosts : function(){
  46. this.posts = document.querySelectorAll('.forum_post a[href="user.php?id='+this.id+'"]');
  47. },
  48. modPosts : function(){
  49. var i = this.posts.length, a;
  50. while(i--){
  51. a = this.posts[i];
  52. a.parentNode.insertBefore(document.createTextNode('[OP] '), a);
  53. }
  54. }
  55. };
  56. mark.findOP();
  57. }());