From 50dbd920f9645701cb455b68e2b58fbc9d0bd76a Mon Sep 17 00:00:00 2001 From: James Campos Date: Sun, 21 Aug 2011 01:15:47 -0700 Subject: [PATCH] refactor --- 4chan_x.user.js | 21 +++++++++++---------- script.coffee | 11 +++++------ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index c5db8f971..c2d9bbbba 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -296,6 +296,13 @@ return object; }; $.extend($, { + innerText: function(el) { + var span; + span = $.el('span', { + innerHTML: el.innerHTML.replace(/
/g, ' ') + }); + return span.textContent; + }, id: function(id) { return d.getElementById(id); }, @@ -1868,7 +1875,7 @@ return watcher.refresh(); }, watch: function(thread, id) { - var el, props, span, watched, _name; + var el, props, watched, _name; el = $('span.filetitle'); if (!el.textContent) { el = $('blockquote'); @@ -1876,11 +1883,8 @@ return; } } - span = $.el('span', { - innerHTML: el.innerHTML.replace(/
/g, ' ') - }); props = { - textContent: "/" + g.BOARD + "/ - " + span.textContent.slice(0, 25), + textContent: "/" + g.BOARD + "/ - " + ($.innerText(el).slice(0, 25)), href: "/" + g.BOARD + "/res/" + id }; watched = $.get('watched', {}); @@ -2066,7 +2070,7 @@ }; titlePost = { init: function() { - var el, span; + var el; el = $('span.filetitle'); if (!el.textContent) { el = $('blockquote'); @@ -2074,10 +2078,7 @@ return; } } - span = $.el('span', { - innerHTML: el.innerHTML.replace(/
/g, ' ') - }); - return d.title = "/" + g.BOARD + "/ - " + span.textContent; + return d.title = "/" + g.BOARD + "/ - " + ($.innerText(el)); } }; quoteBacklink = { diff --git a/script.coffee b/script.coffee index 256dc2f81..36f451a26 100644 --- a/script.coffee +++ b/script.coffee @@ -206,6 +206,9 @@ $.extend = (object, properties) -> object $.extend $, + innerText: (el) -> + span = $.el 'span', innerHTML: el.innerHTML.replace /
/g, ' ' + span.textContent id: (id) -> d.getElementById id globalEval: (code) -> @@ -1540,10 +1543,8 @@ watcher = el = $ 'blockquote' if not el.textContent return - span = $.el 'span', - innerHTML: el.innerHTML.replace /
/g, ' ' props = - textContent: "/#{g.BOARD}/ - #{span.textContent[...25]}" + textContent: "/#{g.BOARD}/ - #{$.innerText(el)[...25]}" href: "/#{g.BOARD}/res/#{id}" watched = $.get 'watched', {} @@ -1659,9 +1660,7 @@ titlePost = el = $ 'blockquote' if not el.textContent return - span = $.el 'span', - innerHTML: el.innerHTML.replace /
/g, ' ' - d.title = "/#{g.BOARD}/ - #{span.textContent}" + d.title = "/#{g.BOARD}/ - #{$.innerText el}" quoteBacklink = init: ->