IP.Board - Isolate Posts by User

Adds links to 'Who posted in' lists and posts that generate all posts by that user in the thread.

  1. // ==UserScript==
  2. // @name IP.Board - Isolate Posts by User
  3. // @namespace Makaze
  4. // @include *
  5. // @grant none
  6. // @version 1.0.9
  7. // @description Adds links to 'Who posted in' lists and posts that generate all posts by that user in the thread.
  8. // ==/UserScript==
  9.  
  10. var thisViews,
  11. thisLink,
  12. thisThreadInList,
  13. threadNameInList,
  14.  
  15. thisThreadInThread,
  16. threadNameInThread,
  17. authorInThread,
  18.  
  19. listOnPage,
  20. thisThreadOnPage,
  21. threadNameOnPage,
  22. usersOnPage,
  23. authorOnPage,
  24.  
  25. thisUser,
  26. usersPosts,
  27. posts,
  28. threads,
  29. newLink,
  30. i = 0;
  31.  
  32. // Classes constructor
  33.  
  34. function ClassHandler() {
  35. var self = this;
  36.  
  37. this.classList = function(elem) {
  38. return elem.className.trim().split(/[\b\s]/);
  39. };
  40.  
  41. this.hasClass = function(elem, className) {
  42. var classes = self.classList(elem),
  43. has = false,
  44. i = 0;
  45.  
  46. for (i = 0; i < classes.length; i++) {
  47. if (classes[i] === className) {
  48. has = true;
  49. break;
  50. }
  51. }
  52.  
  53. return (has);
  54. };
  55.  
  56. this.addClass = function(elem, className) {
  57. var classes;
  58.  
  59. if (!self.hasClass(elem, className)) {
  60. classes = self.classList(elem);
  61. classes.push(className);
  62. elem.className = classes.join(' ').trim();
  63. }
  64.  
  65. return self;
  66. };
  67.  
  68. this.removeClass = function(elem, className) {
  69. var classes = self.classList(elem),
  70. i = 0;
  71.  
  72. for (i = 0; i < classes.length; i++) {
  73. if (classes[i] === className) {
  74. classes.splice(i, 1);
  75. }
  76. }
  77.  
  78. elem.className = classes.join(' ').trim();
  79.  
  80. return self;
  81. };
  82.  
  83. this.toggleClass = function(elem, className) {
  84. var classes;
  85.  
  86. if (self.hasClass(elem, className)) {
  87. self.removeClass(elem, className);
  88. } else {
  89. classes = self.classList(elem);
  90. classes.push(className);
  91. elem.className = classes.join(' ').trim();
  92. }
  93.  
  94. return self;
  95. };
  96. }
  97.  
  98. // Initialize
  99.  
  100. var Classes = new ClassHandler();
  101.  
  102. // End Classes constructor
  103.  
  104. function empty(listOnPage) {
  105. while (listOnPage.hasChildNodes()) {
  106. listOnPage.removeChild(listOnPage.lastChild);
  107. }
  108. }
  109.  
  110. function createElement(type, callback) {
  111. var element = document.createElement(type);
  112.  
  113. callback(element);
  114.  
  115. return element;
  116. }
  117.  
  118. function createIsoOnPost(author, threadName, thread) {
  119. return createElement('span', function(span) {
  120. span.className = 'right ipsType_small desc blend_links';
  121. span.style.marginRight = '7px';
  122. span.appendChild(createElement('a', function(link) {
  123. link.title = 'View all posts by ' + author + ' in ' + threadName;
  124. link.href =
  125. window.location.protocol
  126. + '//'
  127. + window.location.hostname
  128. + window.location.pathname
  129. + '?app=core&module=search&do=search&cType=topic&cId='
  130. + thread
  131. + '&search_author='
  132. + author;
  133. link.appendChild(document.createTextNode('All'));
  134. }));
  135. });
  136. }
  137.  
  138. function createIsoOnWho(author, threadName, thread, postsElem) {
  139. return createElement('a', function(link) {
  140. link.title = 'View all posts by ' + author + ' in ' + threadName;
  141. link.href =
  142. window.location.protocol
  143. + '//'
  144. + window.location.hostname
  145. + window.location.pathname
  146. + '?app=core&module=search&do=search&cType=topic&cId='
  147. + thread
  148. + '&search_author='
  149. + author;
  150. link.appendChild(document.createTextNode(postsElem.textContent + ' (View)'));
  151. });
  152. }
  153.  
  154. var generateLinks = function(event) {
  155. var listOnPage = event.target,
  156. users,
  157. author,
  158. thisUser,
  159. usersPosts,
  160. i = 0;
  161.  
  162. if (!listOnPage.className || !Classes.hasClass(listOnPage, 'fixed_inner')) {
  163. return false;
  164. }
  165.  
  166. threadNameInList = listOnPage.parentNode.getElementsByTagName('h3')[0].textContent.split('Who posted in: ')[1];
  167.  
  168. users = listOnPage.getElementsByTagName('tr');
  169.  
  170. for (i = 0; i < users.length; i++) {
  171. thisUser = users[i];
  172. if (!Classes.hasClass(users[i], 'header')) {
  173. author = thisUser.getElementsByTagName('td')[0].textContent.trim();
  174. usersPosts = thisUser.getElementsByTagName('td')[1];
  175. usersPosts.className = 'blend_links';
  176. newLink = createIsoOnWho(author, threadNameInList, thisThreadInList, usersPosts);
  177. empty(usersPosts);
  178. usersPosts.appendChild(newLink);
  179. }
  180. }
  181.  
  182. document.removeEventListener('DOMNodeInserted', generateLinks, false);
  183. };
  184.  
  185. var generateLinksInit = function(event) {
  186. thisThreadInList = event.target.href.match(/t=(\d+)/)[1];
  187.  
  188. document.addEventListener('DOMNodeInserted', generateLinks, false);
  189. };
  190.  
  191. if (document.body.id === 'ipboard_body') {
  192. if (document.getElementsByClassName('__topic')[0] != null) {
  193. for (i = 0, threads = document.getElementsByClassName('__topic'); i < threads.length; i++) {
  194. thisViews = threads[i].getElementsByClassName('col_f_views')[0];
  195. thisLink = thisViews.getElementsByTagName('a')[0];
  196.  
  197. if (thisLink != null) {
  198. thisLink.addEventListener('click', generateLinksInit, false);
  199. }
  200. }
  201. }
  202.  
  203. if (document.getElementsByClassName('post_id')[0] != null) {
  204. for (i = 0, posts = document.getElementsByClassName('post_id'); i < posts.length; i++) {
  205. if (posts[i].getElementsByTagName('a')[0].href.match(/\/topic\//)) {
  206. thisThreadInThread = posts[i].getElementsByTagName('a')[0].href.match(/\/topic\/(\d+)/)[1];
  207. } else {
  208. thisThreadInThread = posts[i].getElementsByTagName('a')[0].href.match(/showtopic=(\d+)/)[1];
  209. }
  210.  
  211. threadNameInThread = posts[i].getElementsByTagName('a')[0].title.split(': post #')[0];
  212. authorInThread = posts[i].parentNode.parentNode.getElementsByClassName('author')[0].textContent.trim();
  213.  
  214. posts[i].parentNode.appendChild(createIsoOnPost(authorInThread, threadNameInThread, thisThreadInThread));
  215. }
  216. }
  217.  
  218. if (window.location.href.match('do=who')) {
  219. listOnPage = document.getElementsByClassName('fixed_inner')[0];
  220.  
  221. thisThreadOnPage = window.location.href.match(/t=(\d+)/)[1];
  222. threadNameOnPage = listOnPage.parentNode.getElementsByTagName('h3')[0].textContent.split('Who posted in: ')[1];
  223.  
  224. usersOnPage = listOnPage.getElementsByTagName('tr');
  225.  
  226. for (i = 0; i < usersOnPage.length; i++) {
  227. thisUser = usersOnPage[i];
  228. if (!Classes.hasClass(thisUser, 'header')) {
  229. authorOnPage = thisUser.getElementsByTagName('td')[0].textContent.trim();
  230. usersPosts = thisUser.getElementsByTagName('td')[1];
  231. usersPosts.className = 'blend_links';
  232.  
  233. newLink = createIsoOnWho(authorOnPage, threadNameOnPage, thisThreadOnPage, usersPosts);
  234. empty(usersPosts);
  235. usersPosts.appendChild(newLink);
  236. }
  237. }
  238. }
  239. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址