Advertisement
Guest User

Qresearch User JavaScript With Image Blocking/New Trip 8/10

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