From 9037ad32da0d2368709df4d70c1cf6f832568038 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Sun, 23 Sep 2012 19:10:28 +0200 Subject: [PATCH] Simplify stuff. --- 4chan_x.user.js | 31 ++++++++++++++++--------------- script.coffee | 29 +++++++++++++++-------------- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 6985f5290..4b0a90118 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -760,7 +760,7 @@ }; function Post(root, thread, board, that) { - var alt, anchor, bq, capcode, data, date, email, file, flag, i, info, name, node, nodes, post, quotelink, quotes, size, subject, text, thumb, tripcode, uniqueID, unit, _i, _j, _k, _len, _len1, _ref, _ref1, _ref2; + var alt, anchor, bq, capcode, data, date, email, file, fileInfo, flag, i, info, name, node, nodes, post, quotelink, quotes, size, subject, text, thumb, tripcode, uniqueID, unit, _i, _j, _k, _len, _len1, _ref, _ref1, _ref2; this.thread = thread; this.board = board; if (that == null) { @@ -838,9 +838,10 @@ if ((file = $('.file', post)) && (thumb = $('img[data-md5]', file))) { alt = thumb.alt; anchor = thumb.parentNode; + fileInfo = file.firstElementChild; this.file = { - info: $('.fileInfo', file), - text: $('.fileText', file), + info: fileInfo, + text: fileInfo.firstElementChild, thumb: thumb, URL: anchor.href, MD5: thumb.dataset.md5, @@ -853,7 +854,7 @@ } this.file.size = size; this.file.thumbURL = that.isArchived ? thumb.src : "" + location.protocol + "//thumbs.4chan.org/" + board + "/thumb/" + (this.file.URL.match(/(\d+)\./)[1]) + "s.jpg"; - this.file.name = $('span[title]', this.file.info).title.replace(/%22/g, '"'); + this.file.name = $('span[title]', fileInfo).title.replace(/%22/g, '"'); if (this.file.isImage = /(jpg|png|gif)$/i.test(this.file.name)) { this.file.dimensions = this.file.text.textContent.match(/\d+x\d+/)[0]; } @@ -1007,8 +1008,8 @@ this.file[key] = val; } file = $('.file', post); - this.file.info = $('.fileInfo', file); - this.file.text = $('.fileText', file); + this.file.info = file.firstElementChild; + this.file.text = this.file.info.firstElementChild; this.file.thumb = $('img[data-md5]', file); } if (origin.isDead) { @@ -1495,7 +1496,7 @@ } flag = flagCode ? ("  + flagCode + ") : ''; if (file != null ? file.isDeleted : void 0) { - fileHTML = isOP ? ("
") + ("File deleted.") + "
" : ("
") + ("File deleted.") + "
"; + fileHTML = isOP ? ("
") + ("File deleted.") + "
" : ("
") + ("File deleted.") + "
"; } else if (file) { ext = file.name.slice(-3); if (!file.twidth && !file.theight && ext === 'gif') { @@ -1570,17 +1571,17 @@ if (link.host === 'boards.4chan.org') { path = link.pathname.split('/'); board = path[1]; - threadID = +path[3]; - postID = +link.hash.slice(2); + threadID = path[3]; + postID = link.hash.slice(2); } else { board = link.dataset.board; - threadID = +link.dataset.threadid || ''; - postID = +link.dataset.postid; + threadID = link.dataset.threadid || 0; + postID = link.dataset.postid; } return { board: board, - threadID: threadID, - postID: postID + threadID: +threadID, + postID: +postID }; }, contextFromLink: function(quotelink) { @@ -2135,13 +2136,13 @@ for (_i = 0, _len = quotelinks.length; _i < _len; _i++) { quote = quotelinks[_i]; data = Get.postDataFromLink(quote); - if (data.threadID === '') { + if (!data.threadID) { continue; } if (this.isClone) { quote.textContent = quote.textContent.replace(QuoteCT.text, ''); } - if (data.board === board.ID && data.threadID !== thread.ID) { + if (data.board === this.board.ID && data.threadID !== thread.ID) { $.add(quote, $.tn(QuoteCT.text)); } } diff --git a/script.coffee b/script.coffee index 90ede66f6..08bb28e82 100644 --- a/script.coffee +++ b/script.coffee @@ -643,9 +643,10 @@ class Post # Flash files are not supported. alt = thumb.alt anchor = thumb.parentNode + fileInfo = file.firstElementChild @file = - info: $ '.fileInfo', file - text: $ '.fileText', file + info: fileInfo + text: fileInfo.firstElementChild thumb: thumb URL: anchor.href MD5: thumb.dataset.md5 @@ -665,7 +666,7 @@ class Post # webk.it/62107 # https://www.w3.org/Bugs/Public/show_bug.cgi?id=16909 # http://www.whatwg.org/specs/web-apps/current-work/#multipart-form-data - @file.name = $('span[title]', @file.info).title.replace /%22/g, '"' + @file.name = $('span[title]', fileInfo).title.replace /%22/g, '"' if @file.isImage = /(jpg|png|gif)$/i.test @file.name @file.dimensions = @file.text.textContent.match(/\d+x\d+/)[0] @@ -779,8 +780,8 @@ class Clone extends Post for key, val of origin.file @file[key] = val file = $ '.file', post - @file.info = $ '.fileInfo', file - @file.text = $ '.fileText', file + @file.info = file.firstElementChild + @file.text = @file.info.firstElementChild @file.thumb = $ 'img[data-md5]', file @isDead = true if origin.isDead @@ -1348,7 +1349,7 @@ Build = if file?.isDeleted fileHTML = if isOP - "
" + + "
" + "File deleted." + "
" else @@ -1496,16 +1497,16 @@ Get = if link.host is 'boards.4chan.org' path = link.pathname.split '/' board = path[1] - threadID = +path[3] - postID = +link.hash[2..] + threadID = path[3] + postID = link.hash[2..] else # resurrected quote board = link.dataset.board - threadID = +link.dataset.threadid or '' - postID = +link.dataset.postid + threadID = link.dataset.threadid or 0 + postID = link.dataset.postid return { board: board - threadID: threadID - postID: postID + threadID: +threadID + postID: +postID } contextFromLink: (quotelink) -> Get.postFromRoot $.x 'ancestor::div[parent::div[@class="thread"]][1]', quotelink @@ -1999,10 +2000,10 @@ QuoteCT = {board, thread} = if @isClone then @context else @ for quote in quotelinks data = Get.postDataFromLink quote - continue if data.threadID is '' # deadlink + continue unless data.threadID # deadlink if @isClone quote.textContent = quote.textContent.replace QuoteCT.text, '' - if data.board is board.ID and data.threadID isnt thread.ID + if data.board is @board.ID and data.threadID isnt thread.ID $.add quote, $.tn QuoteCT.text return