From 61b2a51836a4f328889dc371b8fa965c4bffa2c0 Mon Sep 17 00:00:00 2001 From: seaweedchan Date: Fri, 16 Aug 2013 05:30:10 -0700 Subject: [PATCH] More optimizations --- builds/4chan-X.user.js | 66 +++++++++++++++----------------- builds/crx/script.js | 66 +++++++++++++++----------------- src/Miscellaneous/Banner.coffee | 67 ++++++++++++++++++--------------- 3 files changed, 96 insertions(+), 103 deletions(-) diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 3183fe205..bd4ce9185 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -8465,44 +8465,38 @@ }); }, ready: function() { - var banner, btitle, child, children, i, subtitle; + var banner, child, children, i; banner = $(".boardBanner"); - if (Conf['Custom Board Titles']) { - btitle = $(".boardTitle", banner); - subtitle = $(".boardSubtitle", banner); - btitle.title = "Ctrl+click to edit board title"; - subtitle.title = "Ctrl+click to edit board subtitle"; - } children = banner.children; i = 0; while (child = children[i++]) { - if (child.tagName.toLowerCase() === "img") { + if (i === 1) { child.id = "Banner"; child.title = "Click to change"; $.on(child, 'click', Banner.cb.toggle); continue; } if (Conf['Custom Board Titles']) { - Banner.custom(child); + Banner.custom(child).title = "Ctrl+click to edit board " + (i === 3 ? 'sub' : '') + "title"; + Banner.custom(child).spellcheck = false; } } }, - types: { - jpg: 227, - png: 270, - gif: 253 - }, cb: { toggle: function() { - var num, type; - type = ['jpg', 'png', 'gif'][Math.floor(3 * Math.random())]; - num = Math.floor(Banner.types[type] * Math.random()); + var num, type, types; + types = { + jpg: 227, + png: 270, + gif: 253 + }; + type = Object.keys(types)[Math.floor(3 * Math.random())]; + num = Math.floor(types[type] * Math.random()); return this.src = "//static.4chan.org/image/title/" + num + "." + type; }, click: function(e) { if (e.ctrlKey) { this.contentEditable = true; - this.spellcheck = false; return this.focus(); } }, @@ -8514,6 +8508,7 @@ }, focus: function() { var items, string, string2; + this.textContent = this.innerHTML; string = "" + g.BOARD + "." + this.className; string2 = "" + string + ".orig"; items = { @@ -8526,40 +8521,39 @@ return $.set(string2, items.title); } }); - return this.textContent = this.innerHTML; }, blur: function() { - $.set("" + g.BOARD + "." + this.className, this.textContent); this.innerHTML = this.textContent; - return this.contentEditable = false; + this.contentEditable = false; + return $.set("" + g.BOARD + "." + this.className, this.textContent); } }, custom: function(child) { - var cachedTest, string, string2; + var cachedTest, string; cachedTest = child.innerHTML; string = "" + g.BOARD + "." + child.className; - string2 = "" + string + ".orig"; + $.on(child, 'click keydown focus blur', function(e) { + return Banner.cb[e.type].apply(this, [e]); + }); $.get(string, cachedTest, function(item) { - var title; + var string2, title; if (!(title = item[string])) { return; } if (Conf['Persistent Custom Board Titles']) { return child.innerHTML = title; - } else { - return $.get(string2, cachedTest, function(itemb) { - if (cachedTest === itemb[string2]) { - return child.innerHTML = title; - } else { - $.set(string, cachedTest); - return $.set(string2, cachedTest); - } - }); } + string2 = "" + string + ".orig"; + return $.get(string2, cachedTest, function(itemb) { + if (cachedTest === itemb[string2]) { + return child.innerHTML = title; + } else { + $.set(string, cachedTest); + return $.set(string2, cachedTest); + } + }); }); - return $.on(child, 'click keydown focus blur', function(e) { - return Banner.cb[e.type].apply(this, [e]); - }); + return child; } }; diff --git a/builds/crx/script.js b/builds/crx/script.js index 065477c4a..a5aad866e 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -8455,44 +8455,38 @@ }); }, ready: function() { - var banner, btitle, child, children, i, subtitle; + var banner, child, children, i; banner = $(".boardBanner"); - if (Conf['Custom Board Titles']) { - btitle = $(".boardTitle", banner); - subtitle = $(".boardSubtitle", banner); - btitle.title = "Ctrl+click to edit board title"; - subtitle.title = "Ctrl+click to edit board subtitle"; - } children = banner.children; i = 0; while (child = children[i++]) { - if (child.tagName.toLowerCase() === "img") { + if (i === 1) { child.id = "Banner"; child.title = "Click to change"; $.on(child, 'click', Banner.cb.toggle); continue; } if (Conf['Custom Board Titles']) { - Banner.custom(child); + Banner.custom(child).title = "Ctrl+click to edit board " + (i === 3 ? 'sub' : '') + "title"; + Banner.custom(child).spellcheck = false; } } }, - types: { - jpg: 227, - png: 270, - gif: 253 - }, cb: { toggle: function() { - var num, type; - type = ['jpg', 'png', 'gif'][Math.floor(3 * Math.random())]; - num = Math.floor(Banner.types[type] * Math.random()); + var num, type, types; + types = { + jpg: 227, + png: 270, + gif: 253 + }; + type = Object.keys(types)[Math.floor(3 * Math.random())]; + num = Math.floor(types[type] * Math.random()); return this.src = "//static.4chan.org/image/title/" + num + "." + type; }, click: function(e) { if (e.ctrlKey) { this.contentEditable = true; - this.spellcheck = false; return this.focus(); } }, @@ -8504,6 +8498,7 @@ }, focus: function() { var items, string, string2; + this.textContent = this.innerHTML; string = "" + g.BOARD + "." + this.className; string2 = "" + string + ".orig"; items = { @@ -8516,40 +8511,39 @@ return $.set(string2, items.title); } }); - return this.textContent = this.innerHTML; }, blur: function() { - $.set("" + g.BOARD + "." + this.className, this.textContent); this.innerHTML = this.textContent; - return this.contentEditable = false; + this.contentEditable = false; + return $.set("" + g.BOARD + "." + this.className, this.textContent); } }, custom: function(child) { - var cachedTest, string, string2; + var cachedTest, string; cachedTest = child.innerHTML; string = "" + g.BOARD + "." + child.className; - string2 = "" + string + ".orig"; + $.on(child, 'click keydown focus blur', function(e) { + return Banner.cb[e.type].apply(this, [e]); + }); $.get(string, cachedTest, function(item) { - var title; + var string2, title; if (!(title = item[string])) { return; } if (Conf['Persistent Custom Board Titles']) { return child.innerHTML = title; - } else { - return $.get(string2, cachedTest, function(itemb) { - if (cachedTest === itemb[string2]) { - return child.innerHTML = title; - } else { - $.set(string, cachedTest); - return $.set(string2, cachedTest); - } - }); } + string2 = "" + string + ".orig"; + return $.get(string2, cachedTest, function(itemb) { + if (cachedTest === itemb[string2]) { + return child.innerHTML = title; + } else { + $.set(string, cachedTest); + return $.set(string2, cachedTest); + } + }); }); - return $.on(child, 'click keydown focus blur', function(e) { - return Banner.cb[e.type].apply(this, [e]); - }); + return child; } }; diff --git a/src/Miscellaneous/Banner.coffee b/src/Miscellaneous/Banner.coffee index 52658c68f..2bc67ab37 100644 --- a/src/Miscellaneous/Banner.coffee +++ b/src/Miscellaneous/Banner.coffee @@ -5,40 +5,40 @@ Banner = ready: -> banner = $ ".boardBanner" - if Conf['Custom Board Titles'] - btitle = $ ".boardTitle", banner - subtitle = $ ".boardSubtitle", banner - btitle.title = "Ctrl+click to edit board title" - subtitle.title = "Ctrl+click to edit board subtitle" {children} = banner + i = 0 while child = children[i++] - if child.tagName.toLowerCase() is "img" + if i is 1 child.id = "Banner" child.title = "Click to change" $.on child, 'click', Banner.cb.toggle + continue if Conf['Custom Board Titles'] - Banner.custom child + Banner.custom(child).title = "Ctrl+click to edit board #{if i is 3 + 'sub' + else + ''}title" + Banner.custom(child).spellcheck = false return - types: - jpg: 227 - png: 270 - gif: 253 - cb: toggle: -> - type = ['jpg', 'png', 'gif'][Math.floor 3 * Math.random()] - num = Math.floor Banner.types[type] * Math.random() + types = + jpg: 227 + png: 270 + gif: 253 + + type = Object.keys(types)[Math.floor 3 * Math.random()] + num = Math.floor types[type] * Math.random() @src = "//static.4chan.org/image/title/#{num}.#{type}" click: (e) -> if e.ctrlKey @contentEditable = true - @spellcheck = false @focus() keydown: (e) -> @@ -46,38 +46,43 @@ Banner = return @blur() if !e.shiftKey and e.keyCode is 13 focus: -> + @textContent = @innerHTML + string = "#{g.BOARD}.#{@className}" string2 = "#{string}.orig" - items = - title: @innerHTML - items[string] = '' + + items = {title: @innerHTML} + items[string] = '' items[string2] = false $.get items, (items) -> unless items[string2] and items.title is items[string] $.set string2, items.title - @textContent = @innerHTML + + return blur: -> - $.set "#{g.BOARD}.#{@className}", @textContent @innerHTML = @textContent @contentEditable = false + $.set "#{g.BOARD}.#{@className}", @textContent custom: (child) -> cachedTest = child.innerHTML string = "#{g.BOARD}.#{child.className}" - string2 = "#{string}.orig" + + $.on child, 'click keydown focus blur', (e) -> Banner.cb[e.type].apply @, [e] $.get string, cachedTest, (item) -> return unless title = item[string] - if Conf['Persistent Custom Board Titles'] - child.innerHTML = title - else - $.get string2, cachedTest, (itemb) -> - if cachedTest is itemb[string2] - child.innerHTML = title - else - $.set string, cachedTest - $.set string2, cachedTest + return child.innerHTML = title if Conf['Persistent Custom Board Titles'] - $.on child, 'click keydown focus blur', (e) -> Banner.cb[e.type].apply @, [e] \ No newline at end of file + string2 = "#{string}.orig" + + $.get string2, cachedTest, (itemb) -> + if cachedTest is itemb[string2] + child.innerHTML = title + else + $.set string, cachedTest + $.set string2, cachedTest + + child \ No newline at end of file