Advertisement
Guest User

8kun Baker tools v0.3.0

a guest
Dec 26th, 2019
1,145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.   8Kun Baker Tools
  3.   Version 0.3.0
  4.  
  5.   Features:
  6.   ========
  7.   Notables
  8.     * Highlight posts that are marked notable (I.E. someone has replied and said notable) in Yellow
  9.     * Highlight nominating posts in Pink
  10.     * Higlight nominating posts in posts mentions in Green
  11.     * Filter to only nominating and notable posts
  12.     * Generate notables post
  13.  
  14.   Q Posts :: New In 0.3.0
  15.     * Highlights Q Posts with white BG -> DARK TO LIGHT!
  16.     * Highlights Q posts in mentions (I.E. posts that get (YOU)'ed)
  17.     * Highlights links to Q Posts
  18.  
  19.   Comfyness
  20.     * Highlight PB links
  21.     * Thread stats overlay with
  22.       * color coded reply count that goes from green to red as bread ages
  23.       * UID Count
  24.       * Jump To Bottom Link
  25.       * Jump To Bottom Top link
  26.  
  27.   Version History:
  28.   0.3.0
  29.   https://pastebin.com/4aEFsPwK 0.2.0
  30.   https://pastebin.com/eNmTtzdi 0.1.0
  31.   */
  32. (function ($) {
  33.   'use strict';
  34.  
  35.  
  36.   /**
  37.    * Wrapper for 8kun active_page variable to determine the type of page the user is on.
  38.    */
  39.   class ActivePage {
  40.     static Index = "index"
  41.     static Catalog = "catalog"
  42.     static Thread = "thread"
  43.  
  44.     static isIndex() {
  45.       return window.active_page == ActivePage.Index;
  46.     }
  47.  
  48.     static isCatalog() {
  49.       return window.active_page == ActivePage.Catalog;
  50.     }
  51.    
  52.     static isThread() {
  53.       console.log(window.active_page == ActivePage.Thread);
  54.       return window.active_page == ActivePage.Thread;
  55.     }
  56.   }
  57.  
  58.   //TODO: Create Dough?
  59.   //TODO: Highlight/filter yous - when they actually work for me again
  60.   //TODO: Nominate notable template
  61.   //
  62.     //TODO: Bread list
  63.  
  64.  
  65.   /*****************************
  66.    * Research Bread Class
  67.    ****************************/
  68.   class ResearchBread {
  69.     static OP_SUBJECT_SELECTOR = ".post.op > p > label > span.subject";
  70.     static POST_BODY_SELECTOR = ".post > .body";
  71.     static POST_SELECTOR = ".post";
  72.     static REPLY_REGEX = /highlightReply\('(.+?)'/;
  73.     static DOUGH_POSTS_REGEX = /^(Welcome To Q Research General|Global Announcements|War Room|QPosts Archives).*/;
  74.  
  75.     /**
  76.      * Get an array of post bodies with dough posts filtered out
  77.      * @returns NodeList of .post elements
  78.      */
  79.     static getPostsWithoutDough() {
  80.       var posts = Array.from(document.querySelectorAll(ResearchBread.POST_SELECTOR));
  81.       var filteredPosts = posts.filter(function(post){
  82.         return !post.querySelector('.body').innerText.match(ResearchBread.DOUGH_POSTS_REGEX);
  83.       })
  84.       return filteredPosts;
  85.     }
  86.  
  87.     /**
  88.      * Determine what the bread number is
  89.      */
  90.     static getBreadNumber() {
  91.       var breadNumberRegex = /#(.+?) /;
  92.       return document.querySelector(ResearchBread.OP_SUBJECT_SELECTOR)
  93.                       .innerText
  94.                           .match(breadNumberRegex)[1] || "COULD NOT FIND BREAD NUMBER";
  95.     }
  96.  
  97.     /**
  98.      * @arg post .post
  99.      * @return RegexMatch Capture 1 is the number
  100.      */
  101.     static getFirstReplyLink(post) {
  102.         var match = post.querySelector('.body').innerHTML.match(ResearchBread.REPLY_REGEX);
  103.         return match && match[1] || null;
  104.     }
  105.  
  106.   }
  107.  
  108.  
  109.   /*****************************
  110.   * UI
  111.   * ***************************/
  112.   class BakerWindow {
  113.     static ID = "baker-tools-window";
  114.     showOnlyNotablesCheckboxId = "bakertools-show-only-notable"
  115.     createNotablePostButtonId = "bakertools-create-notable-post"
  116.     notableEditorId = "bakertools-notable-editor"
  117.     bakerWindowBodyId = "bakertools-window-body"
  118.     bakerWindowHeaderId = "bakertools-window-header"
  119.     element = null;
  120.  
  121.     constructor() {
  122.       this._createStyles();
  123.       this._createElement();
  124.       this._setupListeners();
  125.       this._setupBakerWindowLink()
  126.     }
  127.  
  128.     _createStyles() {
  129.       var sheet = window.document.styleSheets[0];
  130.       sheet.insertRule(`#${BakerWindow.ID} { width: 300px; background-color: rgb(214, 218, 240);
  131.       position: fixed; z-index: 100; float: right; right:28.25px}`, sheet.cssRules.length);
  132.       sheet.insertRule(`#${BakerWindow.ID} #${this.bakerWindowBodyId} {  padding: 5px; }`, sheet.cssRules.length);
  133.       sheet.insertRule(`#${BakerWindow.ID} #${this.bakerWindowHeaderId} { background: #98E; border: solid 1px; text-align: center; margin: 0px}`, sheet.cssRules.length);
  134.       sheet.insertRule(`#${BakerWindow.ID} #${this.bakerWindowHeaderId} h3 { margin: 0; }`, sheet.cssRules.length);
  135.     }
  136.  
  137.     _createElement() {
  138.       this.element = document.createElement("div");
  139.       this.element.id = BakerWindow.ID;
  140.  
  141.       this.element.innerHTML = `
  142.       <header id="${this.bakerWindowHeaderId}">
  143.         <h3>Baker Tools</h3>
  144.       </header>
  145.       <div id="${this.bakerWindowBodyId}">
  146.         <label for="${this.showOnlyNotablesCheckboxId}">Only Show Notable/Nomination Posts</label>
  147.         <input type="checkbox" id="${this.showOnlyNotablesCheckboxId}" />
  148.         <button id="${this.createNotablePostButtonId}">Create Notable Post</button>
  149.         <textarea id="${this.notableEditorId}"></textarea>
  150.       </div>
  151.       `
  152.       document.body.appendChild(this.element);
  153.  
  154.       $(this.element).draggable();
  155.       $(this.element).hide();
  156.     }
  157.  
  158.     _setupListeners() {
  159.       $('#'+this.showOnlyNotablesCheckboxId).change(function(e) {
  160.         bakerTools.notableHighlighter.setOnlyShowNotables(e.target.checked)
  161.       }.bind(this));
  162.  
  163.       $('#'+this.createNotablePostButtonId).click(function() {
  164.         if($('#'+this.notableEditorId).val()) {
  165.           if (!confirm("If you continue, any changes you made will be overwritten!")) {
  166.             return;
  167.           }
  168.         }
  169.         $('#'+this.notableEditorId).val(this.createNotablesPost());
  170.       }.bind(this));
  171.     }
  172.  
  173.     _setupBakerWindowLink() {
  174.       this.bakerToolsLink = document.createElement("a");
  175.       this.bakerToolsLink.textContent = "[Baker Tools]"
  176.       this.bakerToolsLink.style.cssText = "float: right;"
  177.       this.bakerToolsLink.title = "Baker Tools"
  178.       this.bakerToolsLink.href = "javascript:void(0)"
  179.       document.querySelector('.boardlist').appendChild(this.bakerToolsLink)
  180.  
  181.       this.bakerToolsLink.onclick =  this.toggle.bind(this);
  182.     }
  183.  
  184.     show() {
  185.         $(this.element).css({"top": 15});
  186.         $(this.element).show();
  187.     }
  188.  
  189.     hide() {
  190.         $(this.element).hide();
  191.     }
  192.  
  193.     isVisible() {
  194.       return $(this.element).is(':visible')
  195.     }
  196.  
  197.     toggle() {
  198.       if (this.isVisible()) {
  199.         this.hide();
  200.       } else {
  201.         this.show();
  202.       }
  203.     }
  204.  
  205.     /**
  206.      * Create the notables post for review
  207.      */
  208.     createNotablesPost() {
  209.       var notables = NotablePost.GetNotables();
  210.       var breadNumber = ResearchBread.getBreadNumber();
  211.       var post = `'''#${breadNumber}'''\n\n`;
  212.  
  213.       notables.forEach(function(notable) {
  214.         post += `${notable.shortLink()} ${notable.description}\n\n`;
  215.       });
  216.  
  217.       return post;
  218.     }
  219.   } // end class BakerWindow
  220.      
  221.   class StatsOverlay {
  222.     //TODO: number of notables
  223.     //TODO: number of q posts in bread
  224.     static ID = 'bakertools-stats-overlay'
  225.     static MAX_POSTS = 750
  226.  
  227.     postCountId = "bakertools-stats-post-count"
  228.     userCountId = "bakertools-stats-uid-count"
  229.     qCountId = "bakertools-stats-q-count"
  230.     notableCountId = "bakertools-stats-notable-count"
  231.  
  232.     constructor() {
  233.       this._createStyles();
  234.       this._createElement()
  235.       this._UpdateStats();
  236.       $(document).on("new_post", function(e, post) { this._UpdateStats() }.bind(this));
  237.     }
  238.  
  239.     _createStyles() {
  240.       var sheet = window.document.styleSheets[0];
  241.       sheet.insertRule(`#${StatsOverlay.ID} { padding: 5px; position: fixed; z-index: 100; float: right; right:28.25px; bottom: 28.25px}`, sheet.cssRules.length);
  242.     }
  243.  
  244.     _createElement() {
  245.       this.element = document.createElement("div");
  246.       this.element.id = StatsOverlay.ID;
  247.  
  248.       this.element.innerHTML = `
  249.       Posts: <span id="${this.postCountId}" ></span> UIDS: <span id="${this.userCountId}"></span>
  250.       <a href="#bottom" alt="to-bottom"></a> <a href="#top" alt="to-top"></a><br/>
  251.       Q's: <span id="${this.qPostCountId}" ></span> Notables: <span id="${this.notableCountId}"></span>
  252.      `
  253.      document.body.appendChild(this.element);
  254.    }
  255.  
  256.    _UpdateStats() {
  257.        var postCount = $("#thread_stats_posts").text()
  258.        var progress = postCount/StatsOverlay.MAX_POSTS;
  259.  
  260.        var postColor = "green";
  261.        if (progress >= .87) {  // ~ 650 posts (100 posts left)
  262.          postColor = "red";
  263.        } else if (progress >= .5) {
  264.          postColor = "goldenrod";
  265.        }
  266.        $("#"+this.postCountId).text(postCount).css({'color': postColor})
  267.        $("#"+this.userCountId).text($("#thread_stats_uids").text())
  268.        $("#"+this.qPostCountId).text(QPostHighlighter.qPosts.length)
  269.        $("#"+this.notableCountId).text(NotablePost.GetNotables().length)
  270.    }
  271.  } // End StatsOverlay class
  272.  
  273.  class NotableHighlighter {
  274.    static NOMINATOR_CLASS = "notable-nominator";
  275.    static NOTABLE_CLASS = "notable";
  276.    static NOMINATING_REGEX = /notable/i;
  277.  
  278.    constructor() {
  279.      this._createStyles();
  280.      this.findNominatedNotables();
  281.      $(document).on("new_post", function(e, post) { this.checkNewPostsForNotables(post) }.bind(this));
  282.    }
  283.  
  284.    _createStyles() {
  285.      var sheet = window.document.styleSheets[0];
  286.      sheet.insertRule(`div.post.${NotableHighlighter.NOTABLE_CLASS} { background-color: #FFFFCC; }`, sheet.cssRules.length);
  287.      sheet.insertRule(`div.post.${NotableHighlighter.NOMINATOR_CLASS} { background-color: #FFCCE5;  }`, sheet.cssRules.length);
  288.      sheet.insertRule(`div.post.reply .mentioned .${NotableHighlighter.NOMINATOR_CLASS} { color: #00CC00; font-weight: bold; font-size: 1.5em}`, sheet.cssRules.length);
  289.    }
  290.  
  291.    checkNewPostsForNotables(post) {
  292.      var postBody = post.querySelector('.body')
  293.      $(post).removeAttr("style") //TODO: try removing
  294.        
  295.      if (this.isNominatingPost(post)) {
  296.        NotablePost.FromNominatingPost(post)
  297.      }
  298.    }
  299.  
  300.    /**
  301.     * Finds posts that are being tagged as notable.    
  302.     *
  303.     * I.E. Finding any post that has been replied to by a post with the string "notable" in it.
  304.     * Maybe at somepoint this can be smarter.  Q give me some dwave snow white tech!
  305.     *
  306.     * Highlights notable posts in yellow
  307.     * Highlights nominating posts in pink <3
  308.     * Highlights nominating posts in mentions
  309.     * Add nominee count to post
  310.     */
  311.    findNominatedNotables() {
  312.      var postsWithoutDough = ResearchBread.getPostsWithoutDough();
  313.  
  314.      //^s to ignore notables review posts
  315.      var nominatingPosts = postsWithoutDough.filter(post => this.isNominatingPost(post));
  316.  
  317.      nominatingPosts.forEach(function(nominatingPost) {
  318.        var notable = NotablePost.FromNominatingPost(nominatingPost)
  319.      }.bind(this));
  320.      console.log(NotablePost.GetNotables());
  321.      return NotablePost.GetNotables();
  322.    }
  323.  
  324.    /**
  325.     * Is the post nominating a notable
  326.     * @arg Element .post
  327.     */
  328.    isNominatingPost(post) {
  329.      return post.textContent.search(NotableHighlighter.NOMINATING_REGEX) != -1 && //User declared something notable
  330.             post.querySelector('.body').innerHTML.match(NotableHighlighter.REPLY_REGEX); // Link to the notable
  331.    }
  332.  
  333.      
  334.    /**
  335.     * Toggle whether only the notable/nominee posts are shown or not
  336.     * @arg onlyShowNotables boolean If true, only show notables/nominators, else show all
  337.     */
  338.    setOnlyShowNotables(onlyShowNotables) {
  339.      var notableOrNominationPostsSelector = `div.post.${NotableHighlighter.NOTABLE_CLASS}, div.post.${NotableHighlighter.NOMINATOR_CLASS}`
  340.      var notableOrNominationPostBreaksSelector = `div.post.${NotableHighlighter.NOTABLE_CLASS}+br,div.post.${NotableHighlighter.NOMINATOR_CLASS}+br`;
  341.      var onlyShowNotablesStyleId = 'bakertools-only-show-notables';
  342.  
  343.      if (onlyShowNotables){
  344.        $(`<style id='${onlyShowNotablesStyleId}' type='text/css'>
  345.          div.reply:not(.post-hover), div.post+br {display: none !important; visibility: hidden !important;}
  346.          ${notableOrNominationPostsSelector}, ${notableOrNominationPostBreaksSelector}
  347.          { display: inline-block !important; visibility: visible !important; }
  348.          </style>`).appendTo("head")
  349.      } else {
  350.         $(`#${onlyShowNotablesStyleId}`).remove();
  351.        // For whatever reason, when the non notable posts are filtered and new posts come through the auto_update,
  352.        // the posts are created with style="display:block" which messes up display.  Remove style attr
  353.        $(ResearchBread.POST_SELECTOR).removeAttr("style") //TODO: can we remove this now that we have !important?
  354.      }
  355.    }
  356.  }
  357.  
  358.  class NotablePost {
  359.    static _notables = [];
  360.  
  361.    element = null;
  362.    postNumber = null;
  363.    description = "[DESCRIPTION]";
  364.    nominatingPosts = [];
  365.  
  366.    static NULL = null; //NullNotablePost
  367.    
  368.    constructor() { }
  369.  
  370.    static FromNominatingPost(nominatingPost) {
  371.      var [postNumber, element] = NotablePost._getNotableFromNominator(nominatingPost);
  372.  
  373.      if (!postNumber) {
  374.         console.info("Could not find a reply link in nominator post") ;
  375.         console.debug(nominatingPost.querySelector('.body').innerText);
  376.         if (!NotablePost.NULL) {
  377.           NotablePost.NULL = new NullNotablePost();
  378.         }
  379.         return NotablePost.NULL;
  380.      }
  381.  
  382.      var notable = NotablePost.FindNotableByPostNumber(postNumber)
  383.      if (!notable) {
  384.        var notable = new NotablePost()
  385.  
  386.        var isPreviousBread = element == null;
  387.        if (!isPreviousBread) {
  388.          notable.setElement(element);
  389.        } else {
  390.          //TODO: set pb description
  391.          notable.postNumber = postNumber;
  392.        }
  393.        NotablePost._notables.push(notable);
  394.      }
  395.      notable.addNominatingPost(nominatingPost);
  396.  
  397.      return notable;
  398.    }
  399.  
  400.    isNull() {return false;}
  401.  
  402.    static GetNotables() {
  403.      return NotablePost._notables;
  404.    }
  405.  
  406.    static FindNotableByPostNumber(postNumber) {
  407.      return NotablePost._notables.find(notable => notable.postNumber == postNumber);
  408.    }
  409.  
  410.    setElement(element) {
  411.      this.element = element;
  412.      this._markAsNotable(this.element);
  413.      this.description = element.querySelector('.body').innerText.replace(/\n/g,' ');
  414.      this.postNumber = $(this.element).find('.intro .post_no').text();
  415.      console.debug(this.postNumber);
  416.    }
  417.  
  418.    shortLink() {
  419.      return ">>" + this.postNumber;
  420.    }
  421.  
  422.    addNominatingPost(nominatingPost) {
  423.      this.nominatingPosts.push(nominatingPost)
  424.      this._markAsNominator(nominatingPost);
  425.      this._markNominatorInMentions(nominatingPost);
  426.    }
  427.  
  428.    /**
  429.     * @arg nominatorPost .post
  430.     */
  431.    _markAsNominator(nominatorPost) {
  432.      console.info(`Mark as nominator: ${nominatorPost}`)
  433.      nominatorPost.classList.add(NotableHighlighter.NOMINATOR_CLASS);
  434.    }
  435.      
  436.    /**
  437.     * @arg post .post
  438.     */
  439.    _markAsNotable(post) {
  440.      console.info(`Mark as notable: ${post}`)
  441.      post.classList.add(NotableHighlighter.NOTABLE_CLASS);
  442.    }
  443.  
  444.    static _getNotableFromNominator(nominatingPost) {
  445.      var postNumber = ResearchBread.getFirstReplyLink(nominatingPost);
  446.      var nominatedPost = document.querySelector("#reply_" + postNumber);
  447.      return [postNumber, nominatedPost]
  448.    }
  449.  
  450.    _markNominatorInMentions(nominatingPost) {
  451.      var notableString = this.element && this.element.id || this.postNumber + " (pb)";
  452.      console.info(`Mark as nominator in mentions.  Notable: ${notableString}, Nominating Post: ${nominatingPost.id}`)
  453.      if (!this.element) {
  454.        console.info(`Notable post is null - possible pb/lb`)
  455.        return;
  456.      }
  457.      var nominatingPostId = nominatingPost.id.replace("reply_","");
  458.      $(this.element).find('.mentioned-'+nominatingPostId).addClass(NotableHighlighter.NOMINATOR_CLASS);
  459.    }
  460.  }
  461.  
  462.  class NullNotablePost extends NotablePost {
  463.    isNull() { return true; }
  464.  }
  465.  
  466.  class PreviousBreadHighlighter {
  467.    static previousBreadClass = "bakertools-PreviousBread"
  468.    _linkSelector = "div.body > p.body-line.ltr > a"
  469.  
  470.    /**
  471.     * Loop through post links and mark those that link to breads other than this one.
  472.     * Setup event listener for new post
  473.     */
  474.  
  475.    constructor() {
  476.      this._setupStyles();
  477.  
  478.      var links = $(this._linkSelector).filter("[onClick]");
  479.      links.each(function (index,link){ this.markLinkIfPreviousBread(link)}.bind(this) );
  480.  
  481.      this._setupListeners();
  482.    }
  483.  
  484.    _setupStyles() {
  485.      var sheet = window.document.styleSheets[0];
  486.      sheet.insertRule(`div.post.reply div.body a.${PreviousBreadHighlighter.previousBreadClass} { color: #8B0000; }`, sheet.cssRules.length);
  487.      sheet.insertRule(`a.${PreviousBreadHighlighter.previousBreadClass}::after { content: " (pb)"; }`, sheet.cssRules.length);
  488.    }
  489.  
  490.    _setupListeners() {
  491.      $(document).on("new_post", function(e, post) {
  492.        $(post).find(this._linkSelector).each((index,link) => this.markLinkIfPreviousBread(link));
  493.      });
  494.    }
  495.  
  496.    markLinkIfPreviousBread(link) {
  497.      var breadFileName = document.location.pathname.split('/').slice(-1)[0];  
  498.       var linkFileName = link.href.split('/').slice(-1)[0].split("#")[0];
  499.       if ($(link).attr('onclick').search(ResearchBread.REPLY_REGEX) !=1 &&
  500.             breadFileName != linkFileName) {
  501.           $(link).addClass(PreviousBreadHighlighter.previousBreadClass);
  502.       }
  503.    }
  504.  }
  505.  
  506.  class QPostHighlighter {
  507.    qPostClass = "bakertools-q-post"
  508.    qReplyClass = "bakertools-q-reply"
  509.    qMentionClass = "bakertools-q-mention"
  510.    qLinkClass = "bakertools-q-link"
  511.    _linkSelector = "div.body > p.body-line.ltr > a"
  512.    currentQTripCode = null;
  513.  
  514.    static qPosts = [];
  515.  
  516.    constructor() {
  517.      this._setupStyles();
  518.      this._getCurrentQTripFromBread();
  519.      this._findQPosts();
  520.      this._setupListeners();
  521.    }
  522.  
  523.    _setupStyles() {
  524.      var sheet = window.document.styleSheets[0];
  525.      // Dark to light
  526.      sheet.insertRule(`div.post.reply.${this.qPostClass}
  527.      { background: #FFFFFF; display: inline-block !important; visibility: visible !important;}`, sheet.cssRules.length);
  528.  
  529.      // Enlightened by the Q but still not all the way
  530.      sheet.insertRule(`div.post.reply.${this.qReplyClass}
  531.      { background: #DDDDDD; display: inline-block !important; visibility: visible !important;}`, sheet.cssRules.length);
  532.  
  533.      //Trippy mentions
  534.      sheet.insertRule(`div.post.reply .intro .${this.qMentionClass}, .${this.qLinkClass}
  535.      {
  536.        padding:1px 3px 1px 3px;
  537.        background-color:black;
  538.        border-radius:8px;
  539.        border:1px solid #bbbbee;
  540.        color:gold;
  541.        background: linear-gradient(300deg, #ff0000, #ff0000, #ff0000, #bbbbbb, #4444ff);
  542.        background-size: 800% 800%;
  543.  
  544.        -webkit-animation: Patriot 5s ease infinite;
  545.        -moz-animation: Patriot 5s ease infinite;
  546.        -o-animation: Patriot 5s ease infinite;
  547.        animation: Patriot 5s ease infinite;
  548.        -webkit-text-fill-color: transparent;
  549.        
  550.        background: -o-linear-gradient(transparent, transparent);
  551.        -webkit-background-clip: text;
  552.      }`, sheet.cssRules.length);
  553.  
  554.    }
  555.  
  556.    _getCurrentQTripFromBread() {
  557.      var tripCodeMatch = $('div.post.op').text().match(/Q's Trip-code: Q (.+?\s)/)
  558.  
  559.       if (!tripCodeMatch) {
  560.         console.error("Could not find Q's tripcode");
  561.         return;
  562.       }
  563.       this.currentQTripCode = tripCodeMatch[1].split(' ')[0];
  564.     }
  565.  
  566.     _findQPosts() {
  567.       var posts = ResearchBread.getPostsWithoutDough();
  568.       $(posts).each(function(i,post){
  569.         this._doItQ(post);  
  570.       }.bind(this))
  571.     }
  572.  
  573.     //WWG1WGA
  574.     _doItQ(post) {
  575.       if (this._markIfQPost(post)) { //Q Post, lets check for q replies
  576.         var qPostNumber = $(post).find('.intro .post_no').text().replace("No.","")
  577.  
  578.         var links = $(post).find(this._linkSelector).filter('[onClick]')
  579.         $(links).each(function(i,link) {
  580.           var postNumber = link.href.split('#')[1]
  581.           $(`#reply_${postNumber}`).addClass(this.qReplyClass); //Enlightened post
  582.  
  583.           $(`#reply_${postNumber} .intro .mentioned a`).each(function(i,mentionAnchor) {
  584.             var mentionPostNumber = $(mentionAnchor).text().replace(">>","");
  585.             if (mentionPostNumber == qPostNumber) {
  586.               $(mentionAnchor).addClass(this.qMentionClass);
  587.             }
  588.           }.bind(this));
  589.            
  590.         }.bind(this));
  591.       } else { // Not Q, but lets check if this post replies to Q
  592.         var links = $(post).find(this._linkSelector).filter('[onClick]')
  593.  
  594.         $(links).each(function(i,link) {
  595.           var postNumber = link.href.split('#')[1]
  596.           var replyPost = document.querySelector(`#reply_${postNumber}`);
  597.           if (this._isQ(replyPost)) {
  598.             $(link).addClass(this.qLinkClass)
  599.            
  600.           }
  601.         }.bind(this));
  602.  
  603.       }
  604.     }
  605.  
  606.     /**
  607.      * @arg post div.post.reply
  608.      */
  609.     _markIfQPost(post) {
  610.       var isQ = false;
  611.       if (this._isQ(post)) {
  612.         $(post).addClass(this.qPostClass);
  613.         QPostHighlighter.qPosts.push(post)
  614.         isQ = true;
  615.       }
  616.       return isQ;
  617.     }
  618.  
  619.     _isQ(post) {
  620.       return this._getTripCodeOfPost(post) == this.currentQTripCode;
  621.     }
  622.  
  623.     _getTripCodeOfPost(post) {
  624.       return $(post).find('.intro span.trip').text()
  625.     }
  626.  
  627.     _setupListeners() {
  628.       $(document).on("new_post", function(e, post) {
  629.         this._doItQ(post);
  630.       }.bind(this))
  631.     }
  632.   }
  633. /**************
  634.  * MAIN  
  635.  **************/
  636.  
  637.   //Only setup the tools if we are on a thread
  638.   if (ActivePage.isThread()) {
  639.     $(document).ready(function() {
  640.       window.bakerTools = {};
  641.       bakerTools.mainWindow = new BakerWindow();
  642.       bakerTools.notableHighlighter = new NotableHighlighter();
  643.       bakerTools.PreviousBreadHighlighter = new PreviousBreadHighlighter();
  644.       bakerTools.qPostHighlighter = new QPostHighlighter();
  645.       bakerTools.statsOverlay = new StatsOverlay();
  646.     }.bind(this));
  647.   }
  648.  
  649.  
  650. })(window.jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement