SHARE
TWEET

LJ Unfolder (Tapermonkey/Firefox)

a guest Jun 7th, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // LJ Thread Unfolder
  2. // version 0.2
  3. // 2005-08-23
  4. // Copyright (c) 2005, Tim Babych
  5. // Homepage: http://clear.com.ua/projects/firefox/unfolder
  6. // Released under the GPL license
  7. // http://www.gnu.org/copyleft/gpl.html
  8.  
  9. // Branched 2006-09-09 by Henrik Nyh <http://henrik.nyh.se>
  10. // Added "Unfold all".
  11.  
  12. // ==UserScript==
  13. // @name        LJ Thread Unfolder with "Unfold all"
  14. // @namespace   http://clear.com.ua/projects/firefox/unfolder+http://henrik.nyh.se
  15. // @description Expands nested discussion threads in place.
  16. // @include     http://*.insanejournal.com/*
  17. // @version     1
  18. // @grant       none
  19. // @require     https://gist.githubusercontent.com/arantius/3123124/raw/grant-none-shim.js
  20. // ==/UserScript==
  21.  
  22.  
  23. var unfoldNodes = [];
  24.  
  25. function unfold_all() {
  26. unfoldNodes.forEach(unfold_thread);
  27. }
  28.  
  29. var threadIdRE = /thread=(\d+)/;
  30. var allReplies = $x("//td/a[contains(@href, '?thread')]");
  31.  
  32. allReplies.forEach(function(thisReplyLink) {
  33. t = document.createTextNode(' - ');
  34. thisReplyLink.parentNode.insertBefore(t, thisReplyLink.nextSibling);
  35.  
  36. var threadId = thisReplyLink.href.match(threadIdRE)[1];
  37.  
  38. a = document.createElement('A');
  39. with (a) {
  40. innerHTML = "Unfold";
  41. href = 'javascript:void(0)';
  42. addEventListener("click", unfold_click, false)
  43. setAttribute('thread_id', threadId);
  44. setAttribute('thread_href', thisReplyLink.href);
  45. }
  46. t.parentNode.insertBefore(a, t.nextSibling);
  47. unfoldNodes.push(a);
  48.  
  49. d = document.createElement('div');
  50. d.style.display = 'none';
  51. d.id = 'thread_unfolder_temp_div_' + threadId;
  52. document.body.appendChild(d);
  53. });
  54.  
  55. GM_addStyle(
  56. "a.unfold_thread {color:black; text-decoration:none; cursor:default; } " +
  57. "a.unfold_thread:hover {color:black; text-decoration:none; }" +
  58. "a.unfold_thread img { border:none; }"
  59. );
  60.  
  61. // Inject "Unfold all" links
  62.  
  63. if (!unfoldNodes.length)
  64. return;
  65. $x("//a[contains(@href, '?mode=reply')]/ancestor::b").forEach(function(b) {
  66. var comma = document.createTextNode(', ');
  67. b.appendChild(comma);
  68. var newA = document.createElement("A");
  69. with (newA) {
  70. innerHTML = "Unfold all";
  71. href = "javascript:void(0)";
  72. addEventListener("click", unfold_all, false);
  73. }
  74. b.appendChild(newA);
  75. b.insertBefore(newA, newA.previousSibling.previousSibling);
  76. b.insertBefore(comma, comma.previousSibling.previousSibling);
  77. });
  78.  
  79.  
  80. //  Workhorses
  81.  
  82. function unfold_click() {
  83. unfold_thread(this);
  84. }
  85.  
  86. function unfold_thread(link) {
  87. with (link) {
  88. className = 'unfold_thread';
  89. innerHTML = loader;
  90. blur();
  91. }
  92. elem = link;
  93. // Closure yo!
  94. (function(elem) {
  95.  
  96. GM_xmlhttpRequest({
  97.    method: 'GET',
  98.    url: link.getAttribute('thread_href'),
  99.    onload: function(responseDetails) {
  100. dummy = document.getElementById('thread_unfolder_temp_div_'+elem.getAttribute('thread_id'));
  101. dummy.innerHTML = responseDetails.responseText;
  102. reply = document.getElementById('ljcmt'+elem.getAttribute('thread_id'));
  103. try {  // If we fail, fail silently
  104. // get cell
  105. td = elem;
  106. while (td.nodeName != 'TD')
  107. td = td.parentNode;
  108.  
  109. //cleanse cell
  110. while(td.firstChild)
  111. td.removeChild(td.firstChild);
  112. // remove nesting comments
  113. tbody = td.parentNode.parentNode;
  114. my_padding = tbody.firstChild.firstChild.firstChild.width;
  115.  
  116. next_comment = tbody.parentNode.nextSibling.nextSibling.nextSibling;
  117. while(next_comment &&
  118. next_comment.firstChild &&
  119. next_comment.firstChild.firstChild &&
  120. next_comment.firstChild.firstChild.firstChild &&
  121. next_comment.firstChild.firstChild.firstChild.firstChild &&
  122. (next_comment.firstChild.firstChild.firstChild.firstChild.width > my_padding)) {
  123. to_del = next_comment;
  124. next_comment = next_comment.nextSibling.nextSibling.nextSibling;
  125. to_del.parentNode.removeChild(to_del);
  126. }
  127.  
  128. // add comments there
  129. while(reply && reply.nodeName != 'HR') {
  130. next_one = reply.nextSibling;
  131. td.appendChild(reply);
  132. reply = next_one;
  133. }
  134. } catch(e) {}
  135. dummy.innerHTML = '';
  136. }
  137. });
  138. })(elem);
  139. }
  140.  
  141. //========================================
  142. //  ROUTINES
  143. //========================================
  144.  
  145. loader = '<img src="data:image/gif;base64,R0lGODlhEAAQAMQAAP///+7u7t3d3bu7u6qqqpmZmYi'+
  146. 'IiHd3d2ZmZlVVVURERDMzMyIiIhEREQAR'+
  147. 'AAAAAP///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH/C05F'+
  148. 'VFNDQVBFMi4wAwEAAAAh+QQFBwAQACwAAAAAEAAQAAAFdyAkQgGJJOWoQgIjBM8jkKsoPEzgyMGs'+
  149. 'CjPDw7ADpkQBxRDmSCRetpRA6Rj4kFBkgLC4IlUGhbNQIwXOYYWCXDufzYPDMaoKGBoKb886OjAK'+
  150. 'dgZAAgQkfCwzAgsDBAUCgl8jAQkHEAVkAoA1AgczlyIDczUDA2UhACH5BAUHABAALAAAAAAPABAA'+
  151. 'AAVjICSO0IGIATkqIiMKDaGKC8Q49jPMYsE0hQdrlABCGgvT45FKiRKQhWA0mPKGPAgBcTjsspBC'+
  152. 'AoH4gl+FmXNEUEBVAYHToJAVZK/XWoQQDAgBZioHaX8igigFKYYQVlkCjiMhACH5BAUHABAALAAA'+
  153. 'AAAQAA8AAAVgICSOUGGQqIiIChMESyo6CdQGdRqUENESI8FAdFgAFwqDISYwPB4CVSMnEhSej+Fo'+
  154. 'gNhtHyfRQFmIol5owmEta/fcKITB6y4choMBmk7yGgSAEAJ8JAVDgQFmKUCCZnwhACH5BAUHABAA'+
  155. 'LAAAAAAQABAAAAViICSOYkGe4hFAiSImAwotB+si6Co2QxvjAYHIgBAqDoWCK2Bq6A40iA4yYMgg'+
  156. 'NZKwGFgVCAQZotFwwJIF4QnxaC9IsZNgLtAJDKbraJCGzPVSIgEDXVNXA0JdgH6ChoCKKCEAIfkE'+
  157. 'BQcAEAAsAAAAABAADgAABUkgJI7QcZComIjPw6bs2kINLB5uW9Bo0gyQx8LkKgVHiccKVdyRlqjF'+
  158. 'SAApOKOtR810StVeU9RAmLqOxi0qRG3LptikAVQEh4UAACH5BAUHABAALAAAAAAQABAAAAVxICSO'+
  159. '0DCQKBQQonGIh5AGB2sYkMHIqYAIN0EDRxoQZIaC6bAoMRSiwMAwCIwCggRkwRMJWKSAomBVCc5l'+
  160. 'UiGRUBjO6FSBwWggwijBooDCdiFfIlBRAlYBZQ0PWRANaSkED1oQYHgjDA8nM3kPfCmejiEAIfkE'+
  161. 'BQcAEAAsAAAAABAAEAAABWAgJI6QIJCoOIhFwabsSbiFAotGMEMKgZoB3cBUQIgURpFgmEI0EqjA'+
  162. 'CYXwiYJBGAGBgGIDWsVicbiNEgSsGbKCIMCwA4IBCRgXt8bDACkvYQF6U1OADg8mDlaACQtwJCEA'+
  163. 'IfkEBQcAEAAsAAABABAADwAABV4gJEKCOAwiMa4Q2qIDwq4wiriBmItCCREHUsIwCgh2q8MiyEKO'+
  164. 'DK7ZbHCoqqSjWGKI1d2kRp+RAWGyHg+DQUEmKliGx4HBKECIMwG61AgssAQPKA19EAxRKz4QCVIh'+
  165. 'ACH5BAUHABAALAAAAAAQABAAAAVjICSOUBCQqHhCgiAOKyqcLVvEZOC2geGiK5NpQBAZCilgAYFM'+
  166. 'ogo/J0lgqEpHgoO2+GIMUL6p4vFojhQNg8rxWLgYBQJCASkwEKLC17hYFJtRIwwBfRAJDk4Obwsi'+
  167. 'dEkrWkkhACH5BAUHABAALAAAAQAQAA8AAAVcICSOUGAGAqmKpjis6vmuqSrUxQyPhDEEtpUOgmgY'+
  168. 'ETCCcrB4OBWwQsGHEhQatVFhB/mNAojFVsQgBhgKpSHRTRxEhGwhoRg0CCXYAkKHHPZCZRAKUERZ'+
  169. 'MAYGMCEAIfkEBQcAEAAsAAABABAADwAABV0gJI4kFJToGAilwKLCST6PUcrB8A70844CXenwILRk'+
  170. 'IoYyBRk4BQlHo3FIOQmvAEGBMpYSop/IgPBCFpCqIuEsIESHgkgoJxwQAjSzwb1DClwwgQhgAVVM'+
  171. 'IgVyKCEAIfkECQcAEAAsAAAAABAAEAAABWQgJI5kSQ6NYK7Dw6xr8hCw+ELC85hCIAq3Am0U6JUK'+
  172. 'jkHJNzIsFAqDqShQHRhY6bKqgvgGCZOSFDhAUiWCYQwJSxGHKqGAE/5EqIHBjOgyRQELCBB7EAQH'+
  173. 'fySDhGYQdDWGQyUhADs="> Loading...'
  174.  
  175.  
  176. /* Staple functions */
  177.  
  178. function $(id) { return document.getElementById(id); }
  179. function $x(path, root) {
  180. if (!root) root = document;
  181. var i, arr = [], xpr = document.evaluate(path, root, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
  182. for (i = 0; item = xpr.snapshotItem(i); i++) arr.push(item);
  183. return arr;
  184. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top