Guest User

Qresearch User JavaScript With Image Blocking

a guest
Jul 27th, 2018
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.00 KB | None | 0 0
  1.  
  2. /*
  3. * q.js v2018.3-6.1
  4. * http://anonsw.github.io/8chjs/
  5. */
  6. var imageBlacklist = [] ;
  7. function loadImageBlacklist() { JSON.parse(localStorage.imageBlacklist || "[]").forEach(addToImageBlaclist); }
  8. function saveImageBlacklist() { localStorage.imageBlacklist = JSON.stringify(imageBlacklist); }
  9. function addToImageBlaclist(md5) { if (md5 && -1 === imageBlacklist.indexOf(md5)) imageBlacklist.push(md5); }
  10. function blacklistPostImages(post) { $(post).find('img.post-image').each(function (i, el) { var md5 = el.getAttribute('data-md5'); addToImageBlaclist(md5); el.remove(); }); }
  11. function removeBlacklistedImages() { var removed = 0; $('img.post-image').each(function (i, el) { if (-1 !== imageBlacklist.indexOf(el.getAttribute('data-md5'))) { el.remove(); removed += 1; } }); return removed; }
  12. function onNopeClicked(event) { event.preventDefault(); event.stopPropagation(); loadImageBlacklist(); var post = $(event.target).closest('.post'); blacklistPostImages(post); removeBlacklistedImages(); saveImageBlacklist(); }
  13. function addNopeButtons() { $('.post').each(function(i, post) { if ($(post).find('.nope').length === 0) { $(post).prepend("<input type='button' class='nope' onClick='onNopeClicked(event)' value='Nope'></input>"); } }) }
  14.  
  15. setInterval(function () { loadImageBlacklist(); removeBlacklistedImages(); addNopeButtons(); }, 500);
  16. // User Settings
  17. var anonsw = {
  18. qflair: '', // Examples: REAL, &rarr;
  19. qcolor: '#17dd4c',
  20. youcolor: '#ffff00',
  21. scrollcolor: 'rgba(153, 153, 153, 0.6)',
  22. scrollbackcolor: '#333',
  23. scrolltime: 400, // ms
  24. updateDelay: 200, // ms
  25. sidenavWidth: 30, // px
  26.  
  27. floodEnabled: false,
  28. floodThreshold: 15, // min # posts before beginning fade
  29. floodVanish: 25, // max # posts before completed fade/hide
  30. floodBehavior: 'fade', // hide, fade
  31. fadenametripregex: /^(Anon(ymous)?-.*|.*-!CbboFOtcZs)$/i,
  32. fadenametripfloodvalue: -1, // Effective post count for fading, or -1 for auto of floodThreshold+post count
  33. strikeThroughNameFags: true,
  34.  
  35. rateHistoryLen: 50, // Data points on chart
  36. rateAvgLen: 10 // Number of data points to average for instantaneous rate
  37.  
  38. // Suggestions from 589388.html#590283
  39. // ...shill detection features, such as
  40. // easily knowing the proportion of posts from a user that don't link.
  41. // I'd want to know any ID that was posting > 1/3 posts targetting noone.
  42.  
  43. // TODO: Behavior for post hover should be to show original post visual before all q.js mods
  44. // TODO: Add flags to turn on/off features
  45. // TODO: Custom-regex -> post color/fade (auto-filter by selecting text and choosing new menu item?)
  46. // Examples: daily reminder, guys, check this out, shill, get out, filtered, tell us more, archive everything
  47. // TODO: Manual shade
  48. // TODO: remove Q trip codes from post content?
  49. // TODO: remove Q from end of post content if not a Q post?
  50. // TODO: recognize all of known Q trip codes? (make to sure to exclude known comps)
  51. // TODO: Links to reset on current Q/(you) post
  52. // TODO: Link to go to latest post (end key doesn't always work, but try capturing that as well?)
  53. // TODO: Keyboard shortcuts for navigation
  54. // TODO: Current/Total overall post navigation
  55. // TODO: Remap end key to always go to end of page
  56. // TODO: Check box for each post to mark as "read", "spam", ?
  57. // TODO: Autocorrect all-caps posts (50% threshold)?
  58. // TODO: Correct broken links but remove referral when clicked?
  59. // TODO: Make flood post fading non-linear to give leniency to posters just passing flood threshold
  60. // TODO: Penalize reposts in flood detection (if id's different, merge?) ?
  61. // TODO: Scorecard of posters ordered by post count (post rate, reply count, ...)?
  62. // TODO: Color/shade posts where there are no references and no question marks
  63. // TODO: If Q or trip used in name field, strike them out or replace with Anonymous?
  64. // TODO: embedded posts in Q posts don't have background-color and inherit Q color, fix?
  65. };
  66.  
  67. (function( anonsw_main, $, undefined ) {
  68. // House keeping variables
  69. var qposts = [];
  70. var allqposts = [];
  71. var currq = -1;
  72. var youposts = [];
  73. var curryou = -1;
  74. var qnavposts = [];
  75. var younavposts = [];
  76. var ctx;
  77. var borderSz;
  78. var scrollWd;
  79. var minheight;
  80. var ratehistory = [];
  81.  
  82. // On scroll stop. SO #9144560
  83. (function ($) {
  84. var on = $.fn.on, timer;
  85. $.fn.on = function () {
  86. var args = Array.apply(null, arguments);
  87. var last = args[args.length - 1];
  88.  
  89. if (isNaN(last) || (last === 1 && args.pop())) return on.apply(this, args);
  90.  
  91. var delay = args.pop();
  92. var fn = args.pop();
  93.  
  94. args.push(function () {
  95. var self = this, params = arguments;
  96. clearTimeout(timer);
  97. timer = setTimeout(function () {
  98. fn.apply(self, params);
  99. }, delay);
  100. });
  101.  
  102. return on.apply(this, args);
  103. };
  104. }(this.jQuery || this.Zepto));
  105.  
  106. // Case insensitive contains selector for finding yous. SO #8746882
  107. $.expr[":"].icontains = jQuery.expr.createPseudo(function (arg) {
  108. return function (elem) {
  109. return jQuery(elem).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0;
  110. };
  111. });
  112.  
  113. // Get non-child text. SO #3442394
  114. function immediateText(el) {
  115. return el.contents().not(el.children()).text();
  116. }
  117.  
  118. // Scroll to element
  119. function myScrollTo(el) {
  120. $('html, body').animate({
  121. scrollTop: $(el).offset().top - $('div.boardlist').height()
  122. }, anonsw.scrolltime);
  123. }
  124.  
  125. // Highlight (you) posts/references
  126. function highlightYous() {
  127. $(youposts).each(function() {
  128. $(this).css('background-color', anonsw.youcolor);
  129. });
  130. return $.Deferred().resolve();
  131. }
  132.  
  133. // Remove invalid (you)'s
  134. function removeInvalidYous() {
  135. $('div.body:icontains("(You)")').each(function() {
  136. $(this).find(':not(small)').contents().filter(function() { return this.nodeType == 3 }).each(function() {
  137. this.textContent = this.textContent.replace(/\(+ *You *\)+/ig, "you");
  138. });
  139. });
  140. return $.Deferred().resolve();
  141. }
  142.  
  143. // Highlight Q posts
  144. function highlightQ() {
  145. $(allqposts).each(function(idx,val) {
  146. if($(val).css('background-color') !== anonsw.qcolor) {
  147. if(anonsw.qflair !== "") {
  148. $(val).find('p.intro > label > span.trip').first().prepend(anonsw.qflair + " ");
  149. }
  150. $(val).css('background-color', anonsw.qcolor);
  151. }
  152. });
  153. return $.Deferred().resolve();
  154. }
  155.  
  156. // Scroll to next Q
  157. anonsw_main.nextq = function() {
  158. if(qposts.length > 0) {
  159. if(currq < qposts.length-1) {
  160. currq++;
  161. }
  162. myScrollTo($(qposts).get(currq));
  163. }
  164. };
  165.  
  166. // Scroll to last Q
  167. anonsw_main.lastq = function() {
  168. if(qposts.length > 0) {
  169. currq = qposts.length - 1;
  170. myScrollTo($(qposts).get(currq));
  171. }
  172. };
  173.  
  174. // Scroll to previous Q
  175. anonsw_main.prevq = function() {
  176. if(qposts.length > 0) {
  177. if(currq > 0) {
  178. currq--;
  179. }
  180. myScrollTo($(qposts).get(currq));
  181. }
  182. };
  183.  
  184. // Scroll to first Q
  185. anonsw_main.firstq = function() {
  186. if(qposts.length > 0) {
  187. currq = 0;
  188. myScrollTo($(qposts).get(currq));
  189. }
  190. };
  191.  
  192. // Scroll to next (You)
  193. anonsw_main.nextyou = function() {
  194. if(youposts.length > 0) {
  195. if(curryou < youposts.length-1) {
  196. curryou++;
  197. }
  198. myScrollTo($(youposts).get(curryou));
  199. }
  200. };
  201.  
  202. // Scroll to last (You)
  203. anonsw_main.lastyou = function() {
  204. if(youposts.length > 0) {
  205. curryou = youposts.length - 1;
  206. myScrollTo($(youposts).get(curryou));
  207. }
  208. };
  209.  
  210. // Scroll to previous (You)
  211. anonsw_main.prevyou = function() {
  212. if(youposts.length > 0) {
  213. if(curryou > 0) {
  214. curryou--;
  215. }
  216. myScrollTo($(youposts).get(curryou));
  217. }
  218. };
  219.  
  220. // Scroll to first (You)
  221. anonsw_main.firstyou = function() {
  222. if(youposts.length > 0) {
  223. curryou = 0;
  224. myScrollTo($(youposts).get(curryou));
  225. }
  226. };
  227.  
  228. // Inserts Q navigation links
  229. function qnav() {
  230. $('div.boardlist').append('<span>[ <a href="javascript:anonsw_main.firstq();"><i class="fa fa-step-backward"></i></a> <a href="javascript:anonsw_main.prevq();"><i class="fa fa-backward"></i></a> <span style="filter:brightness(70%);">Q</span> <span class="qcount">(?:?)</span> <a href="javascript:anonsw_main.nextq();"><i class="fa fa-forward"></i></a> <a href="javascript:anonsw_main.lastq();"><i class="fa fa-step-forward"></i></a> ]</span>');
  231. }
  232.  
  233. // Inserts (You) navigation links
  234. function younav() {
  235. $('div.boardlist').append('<span>[ <a href="javascript:anonsw_main.firstyou();"><i class="fa fa-step-backward"></i></a> <a href="javascript:anonsw_main.prevyou();"><i class="fa fa-backward"></i></a> <span style="filter:brightness(70%);">(You)</span> <span class="youcount">(?:?)</span> </span><a href="javascript:anonsw_main.nextyou();"><i class="fa fa-forward"></i></a> <a href="javascript:anonsw_main.lastyou();"><i class="fa fa-step-forward"></i></a> ]</span>');
  236. }
  237.  
  238. // Inserts feature toggle links
  239. function togglenav() {
  240. $('div.boardlist').append('<span>[ <a href="javascript:anonsw_main.toggleFlood();">Turn Post Fading <span class="toggleFloodState">Off</span></a> ]</span>')
  241. }
  242.  
  243. // Inserts post rate count/chart
  244. function postratenav() {
  245. var height = $('div.boardlist').height() - 1;
  246. $('div.boardlist').append('<span>[ Post Rate: <span class="postRate">0</span> posts/min <canvas class="postRateChart"></canvas>]</span>')
  247. $('.postRate').css('color', $('div.boardlist a').css('color'));
  248. var charts = $('.postRateChart');
  249. $(charts).each(function() {
  250. $(this).css('width', '100px');
  251. $(this).css('height', height);
  252. $(this).css('vertical-align', 'middle');
  253. //$(this).css('border', '1px solid');
  254. //$(this).css('border-color', $('div.boardlist').css('color'));
  255. var gctx = $(this).get(0).getContext('2d');
  256. gctx.canvas.height = 20;
  257. gctx.canvas.width = 100;
  258. });
  259. }
  260.  
  261. // Inserts side navigation (bird's eye)
  262. function sidenav() {
  263. $('body').append('<canvas id="sidenav"></canvas>');
  264. var nav = $('#sidenav');
  265. $(nav).css('position', 'fixed');
  266. $(nav).css('top', $('div.boardlist').height());
  267. $(nav).css('right', 0);
  268. $(nav).css('width', anonsw.sidenavWidth);
  269. $(nav).css('height', $(window).height() - $('div.boardlist').height());
  270. $(nav).css('background-color', anonsw.scrollbackcolor);
  271. $('body').css('margin-right', anonsw.sidenavWidth);
  272. ctx = $('#sidenav').get(0).getContext('2d');
  273. //ctx.canvas.height = $(document).height() - $('div.boardlist').height();
  274. ctx.canvas.height = 2048;
  275. ctx.canvas.width = anonsw.sidenavWidth;
  276. borderSz = 1;
  277. scrollWd = ctx.canvas.width / 2;
  278. }
  279.  
  280. // Update navigation counts
  281. function updateNavCounts() {
  282. var fontSize = -1;
  283. var lineHeight;
  284.  
  285. if(currq > qposts.length) { currq = qposts.length; }
  286. if(curryou > youposts.length) { curryou = youposts.length; }
  287.  
  288. for(i=0; i<qposts.length; i++) {
  289. var el = $(qposts).get(i);
  290. if(fontSize == -1) {
  291. fontSize = $(el).css('font-size');
  292. lineHeight = Math.floor(parseInt(fontSize.replace('px', '')) * 1.5);
  293. }
  294. if(($(el).offset().top + $(el).height() - 2.25*lineHeight) > $(window).scrollTop()) {
  295. currq = i;
  296. break;
  297. }
  298. }
  299.  
  300. for(i=0; i<youposts.length; i++) {
  301. var el = $(youposts).get(i);
  302. if(fontSize == -1) {
  303. fontSize = $(el).css('font-size');
  304. lineHeight = Math.floor(parseInt(fontSize.replace('px', '')) * 1.5);
  305. }
  306. if(($(el).offset().top + $(el).height() - 2.25*lineHeight) > $(window).scrollTop()) {
  307. curryou = i;
  308. break;
  309. }
  310. }
  311.  
  312. // TODO: check for duplicates and remove from counts
  313. $('.qcount').text("(" + (currq+1) + ":" + qposts.length + ")");
  314. $('.youcount').text("(" + (curryou+1) + ":" + youposts.length + ")");
  315. }
  316.  
  317. // Update navigation graphics
  318. function updateNavGraphics() {
  319. var sidenav = $('#sidenav');
  320. if(sidenav.length) {
  321. $(sidenav).css('height', $(window).height() - $('div.boardlist').height());
  322. minheight = ctx.canvas.height / ($(window).height() - $('div.boardlist').height()); // 1px
  323. ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
  324.  
  325. // Draw nav q posts
  326. qnavposts = [];
  327. ctx.fillStyle = anonsw.qcolor;
  328. for (i = 0; i < qposts.length; i++) {
  329. // TODO: check if we have already added post, don't draw it again
  330. var el = $(qposts).get(i);
  331. var height = $(el).height() / $(document).height() * ctx.canvas.height;
  332. if(height < minheight) height = minheight;
  333. qnavposts[i] = {
  334. x : borderSz,
  335. y : $(el).offset().top / $(document).height() * ctx.canvas.height,
  336. width : ctx.canvas.width - borderSz*2,
  337. height : height
  338. };
  339. ctx.fillRect(qnavposts[i].x, qnavposts[i].y, qnavposts[i].width, qnavposts[i].height);
  340. }
  341.  
  342. // Draw nav you posts
  343. younavposts = [];
  344. ctx.fillStyle = anonsw.youcolor;
  345. for (i = 0; i < youposts.length; i++) {
  346. // TODO: check if we have already added post, don't add it again
  347. var el = $(youposts).get(i);
  348. var height = $(el).height() / $(document).height() * ctx.canvas.height;
  349. if(height < minheight) height = minheight;
  350. younavposts[i] = {
  351. x : borderSz,
  352. y : $(el).offset().top / $(document).height() * ctx.canvas.height,
  353. width : ctx.canvas.width - borderSz*2,
  354. height : height
  355. };
  356. ctx.fillRect(younavposts[i].x, younavposts[i].y, younavposts[i].width, younavposts[i].height);
  357. }
  358.  
  359. // Update nav window
  360. ctx.fillStyle = anonsw.scrollcolor;
  361. ctx.fillRect(
  362. scrollWd / 2,
  363. $(window).scrollTop() / $(document).height() * ctx.canvas.height,
  364. scrollWd,
  365. $(window).height() / $(document).height() * ctx.canvas.height
  366. );
  367.  
  368. // Add red marker at bottom of >750 posts
  369. if($('#thread_stats_posts').text() > 750) {
  370. var barHeight = (4 * 2048) / ($(window).height() - $('div.boardlist').height());
  371. ctx.fillStyle = '#f66';
  372. ctx.fillRect(
  373. 0,
  374. ctx.canvas.height - barHeight,
  375. ctx.canvas.width,
  376. barHeight
  377. );
  378. }
  379. }
  380. }
  381.  
  382. // Updates post rate count/chart
  383. function updateNavPostRate() {
  384. var posts = $('div.post').not('.post-hover');
  385. var startPost = posts.length - (anonsw.rateHistoryLen + anonsw.rateAvgLen) + 1;
  386. if(startPost < 1) startPost = 1;
  387. var start = $($($(posts).get(0)).find('.intro time').get(0)).attr('unixtime'); //$('div.post:first .intro time').attr('unixtime');
  388. ratehistory = [];
  389. timehistory = [];
  390. for(var i=startPost; i<posts.length; i++) {
  391. // TODO: check if we have already added post, don't add it again
  392. var step = $($($(posts).get(i)).find('.intro time').get(0)).attr('unixtime'); //$($('div.post .intro time').get(i)).attr('unixtime');
  393. timehistory[timehistory.length] = step;
  394. if(timehistory.length - anonsw.rateAvgLen - 1 >= 0) {
  395. var avgend = timehistory[timehistory.length - 1];
  396. var avgstart = timehistory[timehistory.length - anonsw.rateAvgLen - 1];
  397. ratehistory[ratehistory.length] = anonsw.rateAvgLen / ((avgend - avgstart) / 60);
  398. } else {
  399. ratehistory[ratehistory.length] = 0;
  400. }
  401. }
  402. //console.log(ratehistory);
  403.  
  404. $('.postRate').text(ratehistory[ratehistory.length-1].toFixed(1));
  405.  
  406. if(ratehistory.length > anonsw.rateAvgLen) {
  407. var maxRate = Math.max.apply(null, ratehistory);
  408. var minRate = Math.min.apply(null, ratehistory);
  409. //console.log("Max: " + maxRate);
  410. //console.log("Min: " + minRate);
  411. if(minRate > (maxRate - 0.5)) {
  412. minRate = maxRate - 0.5;
  413. maxRate = maxRate + 0.5;
  414. }
  415. if(minRate < 0) {
  416. minRate = 0;
  417. }
  418. var maxTime = timehistory[timehistory.length-1];
  419. var minTime = timehistory[anonsw.rateAvgLen];
  420. $('.postRateChart').each(function() {
  421. var gctx = $(this).get(0).getContext('2d');
  422. gctx.clearRect(0, 0, gctx.canvas.width, gctx.canvas.height);
  423. gctx.strokeStyle = $('div.boardlist a').css('color');
  424. gctx.beginPath();
  425. var x = 0;
  426. var y = gctx.canvas.height - (ratehistory[anonsw.rateAvgLen] - minRate)/(maxRate - minRate) * gctx.canvas.height;
  427. gctx.moveTo(x, y);
  428. for(var i=anonsw.rateAvgLen+1; i<ratehistory.length; i++) {
  429. x = (timehistory[i] - minTime)/(maxTime - minTime) * gctx.canvas.width;
  430. y = gctx.canvas.height - (ratehistory[i] - minRate)/(maxRate - minRate) * gctx.canvas.height;
  431. gctx.lineTo(x, y);
  432. }
  433. gctx.stroke();
  434. gctx.closePath();
  435. });
  436. }
  437. }
  438.  
  439. // Update navigation
  440. function updateNav() {
  441. updateNavCounts();
  442. updateNavGraphics();
  443. updateNavPostRate();
  444. }
  445.  
  446. // Update nav when scrolling stops
  447. $(window).on('scroll', function(e) {
  448. updateNavCounts();
  449. updateNavGraphics();
  450. }, anonsw.updateDelay);
  451.  
  452. // Update nav when resize stops
  453. $(window).on('resize', function(e) {
  454. updateNav();
  455. }, anonsw.updateDelay);
  456.  
  457. // Set which posts are Q posts
  458. function setQPosts() {
  459. qposts = $.map($('div.post:not(.post-hover) > p.intro > label > span.trip:contains("!CbboFOtcZs")'), function(el) {
  460. return $(el).closest('div.post');
  461. });
  462. allqposts = $.map($('div.post:not(.post-hover) > p.intro > label > span.trip:contains("!CbboFOtcZs")'), function(el) {
  463. return $(el).closest('div.post');
  464. });
  465. return $.Deferred().resolve();
  466. }
  467.  
  468. // Set which posts are (you) posts
  469. function setYouPosts() {
  470. youposts = $.map($('div.post:not(.post-hover) > p.intro > label span.name > span.own_post, div.post:not(.post-hover) > div.body > p.body-line > small:icontains("(You)")'), function(el) {
  471. return $(el).closest('div.post');
  472. });
  473. return $.Deferred().resolve();
  474. }
  475.  
  476. // Set flood posts
  477. function setFloodPosts() {
  478. if(anonsw.floodEnabled) {
  479. var stats = {};
  480. var firstId = null;
  481. //console.log("==[ Name Fags ]=================================================");
  482. var posts = $('div.post:not(.post-hover)').not('.you');
  483. $(posts).each(function () {
  484. var id = $(this).find('p > span.poster_id').first().text();
  485. if(firstId != null) {
  486. if (!(id in stats)) {
  487. stats[id] = {count: 0, namefag: false, floodcount: 0};
  488. }
  489. stats[id].count++;
  490. if(!stats[id].namefag) {
  491. var name = immediateText($(this).find('p > label span.name').first());
  492. var trip = $(this).find('p > label > span.trip').first().text();
  493. stats[id].namefag = !anonsw.fadenametripregex.test(name+'-'+trip);
  494. //if(stats[id].namefag) {
  495. // console.log(id + '=' + stats[id].namefag + ', ' + name + ', ' + trip);
  496. //}
  497. }
  498. if(stats[id].namefag) {
  499. if(anonsw.fadenametripfloodvalue < 0) {
  500. stats[id].floodcount = anonsw.floodThreshold + stats[id].count;
  501. } else {
  502. stats[id].floodcount = anonsw.fadenametripfloodvalue;
  503. }
  504. } else {
  505. stats[id].floodcount = stats[id].count;
  506. }
  507. }
  508. if (firstId == null) {
  509. firstId = id;
  510. }
  511. });
  512. $.each(stats, function (key, value) {
  513. if (key !== firstId) {
  514. var ids = $('span.poster_id:contains("' + key + '")');
  515. if (value.floodcount > anonsw.floodThreshold || value.namefag) {
  516. if(anonsw.strikeThroughNameFags && value.namefag) {
  517. $(ids).each(function() {
  518. $(this).closest('div.post').find('p > label span.name').first().css('text-decoration','line-through');
  519. });
  520. }
  521. if (anonsw.floodBehavior === 'fade') {
  522. var intensity = value.floodcount;
  523. if (intensity > anonsw.floodVanish) {
  524. intensity = anonsw.floodVanish;
  525. }
  526. intensity = ((anonsw.floodVanish - anonsw.floodThreshold) - (intensity - anonsw.floodThreshold)) / (anonsw.floodVanish - anonsw.floodThreshold);
  527. if (intensity < 0.1) {
  528. intensity = 0.1;
  529. }
  530. $(ids).each(function () {
  531. $(this).closest('div.post').css('opacity', intensity);
  532. $(this).closest('div.post').hover(function () {
  533. $(this).animate({opacity: 1.0}, anonsw.updateDelay);
  534. }, function () {
  535. $(this).animate({opacity: intensity}, anonsw.updateDelay);
  536. });
  537. });
  538. } else if (anonsw.floodBehavior === 'hide') {
  539. if (value.count >= anonsw.floodVanish) {
  540. $(ids).each(function () {
  541. $(this).closest('div.post').hide();
  542. });
  543. }
  544. }
  545. } else {
  546. $(ids).each(function () {
  547. $(this).closest('div.post').css('opacity', 1.0);
  548. });
  549. }
  550. }
  551. });
  552. }
  553. return $.Deferred().resolve();
  554. }
  555.  
  556. // Toggle post flooding
  557. anonsw_main.toggleFlood = function() {
  558. if(anonsw.floodEnabled) {
  559. anonsw.floodEnabled = false;
  560. $('.toggleFloodState').text('On');
  561. if(anonsw.floodBehavior === 'fade') {
  562. $('span.poster_id').each(function () {
  563. $(this).closest('div.post').css('opacity', 1);
  564. $(this).closest('div.post').off('mouseenter mouseleave');
  565. });
  566. } else if(anonsw.floodBehavior === 'hide') {
  567. $(this).closest('div.post').show();
  568. }
  569. } else {
  570. anonsw.floodEnabled = true;
  571. $('.toggleFloodState').text('Off');
  572. runq()
  573. }
  574. };
  575.  
  576. // Helper to run snippets in the right order
  577. function runq() {
  578. setQPosts()
  579. .done(highlightQ)
  580. .done(removeInvalidYous)
  581. .done(setYouPosts)
  582. .done(highlightYous)
  583. .done(setFloodPosts)
  584. .done(updateNav);
  585. }
  586.  
  587. anonsw_main.Q = function() {
  588. qnav();
  589. younav();
  590. togglenav();
  591. postratenav();
  592. sidenav();
  593. runq();
  594.  
  595. // Select the node that will be observed for mutations
  596. var targetNode = $('div.thread')[0];
  597.  
  598. // Options for the observer (which mutations to observe)
  599. var config = { childList: true };
  600.  
  601. // Callback function to execute when mutations are observed
  602. var callback = function(mutationsList) {
  603. for(var mutation in mutationsList) {
  604. if (mutationsList[mutation].type == 'childList') {
  605. runq();
  606. break;
  607. }
  608. }
  609. };
  610.  
  611. // Create an observer instance linked to the callback function
  612. var observer = new MutationObserver(callback);
  613.  
  614. // Start observing the target node for configured mutations
  615. observer.observe(targetNode, config);
  616. };
  617. }( window.anonsw_main = window.anonsw_main || {}, jQuery ));
  618.  
  619. // Attach snippets to ready/change events
  620. $(document).ready(anonsw_main.Q);
Advertisement
Add Comment
Please, Sign In to add comment