diff --git a/src/General/BuildTest.coffee b/src/General/BuildTest.coffee index cc350b511..bdba5235a 100644 --- a/src/General/BuildTest.coffee +++ b/src/General/BuildTest.coffee @@ -4,22 +4,46 @@ BuildTest = a = $.el 'a', textContent: 'Test HTML building' - - $.on a, 'click', @runTest - + $.on a, 'click', @testOne $.event 'AddMenuEntry', type: 'post' el: a open: (post) -> a.dataset.fullID = post.fullID + true - runTest: -> - post = g.posts[@dataset.fullID] - c.log post.originalHTML + a2 = $.el 'a', + textContent: 'Test HTML building' + $.on a2, 'click', @testAll + $.event 'AddMenuEntry', + type: 'header' + el: a2 + + runTest: (post) -> $.cache "//a.4cdn.org/#{post.board.ID}/thread/#{post.thread.ID}.json", -> for postData in @response.posts if postData.no is post.ID root = Build.postFromObject postData, post.board.ID post2 = new Post root, post.thread, post.board - c.log post2.originalHTML + if post.normalizedHTML is post2.normalizedHTML + c.log "#{post.fullID} correct" + else + c.log "#{post.fullID} differs" + i = 0 + while i < post.normalizedHTML.length and i < post2.normalizedHTML.length + break unless post.normalizedHTML[i] is post2.normalizedHTML[i] + i++ + c.log post.normalizedHTML[i..i+80] + c.log post2.normalizedHTML[i..i+80] + c.log post.normalizedHTML + c.log post2.normalizedHTML + post2.isFetchedQuote = true + Main.callbackNodes Post, [post2] + testOne: -> + BuildTest.runTest g.posts[@dataset.fullID] + + testAll: -> + g.posts.forEach (post) -> + unless post.isClone or post.isFetchedQuote + BuildTest.runTest post diff --git a/src/General/lib/post.class b/src/General/lib/post.class index 5c1dcea3f..897e18de0 100755 --- a/src/General/lib/post.class +++ b/src/General/lib/post.class @@ -4,8 +4,15 @@ class Post constructor: (root, @thread, @board, that={}) -> root2 = root.cloneNode true - $.rm el for el in $$ '.mobile', root2 - @originalHTML = root2.outerHTML + for el in $$ '.mobile', root2 + $.rm el + for el in $$ 'a[href]', root2 + href = el.href + href = href.replace /(^\w+:\/\/boards.4chan.org\/[^\/]+\/thread\/\d+)\/.*/, '$1' + el.setAttribute 'href', href + for el in $$ 'img[src]', root2 + el.src = el.src.replace /^(\w+:\/\/)[0-2](\.t\.4cdn\.org\/)/, '$10$2' + @normalizedHTML = root2.outerHTML @ID = +root.id[2..] @fullID = "#{@board}.#{@ID}"