From 158390bed108b103e60affcf6e4b426b1cdf824e Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Mon, 19 Aug 2013 20:46:14 -0700 Subject: [PATCH 1/2] Fix #436, fix #435 --- LICENSE | 2 +- builds/appchan-x.user.js | 73 +++++++++++++++++----------------- builds/crx/script.js | 73 +++++++++++++++++----------------- src/Theming/Style.coffee | 85 +++++++++++++++++++--------------------- 4 files changed, 113 insertions(+), 120 deletions(-) diff --git a/LICENSE b/LICENSE index f089058e1..c4ffbf010 100644 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,5 @@ /* -* appchan x - Version 2.3.4 - 2013-08-18 +* appchan x - Version 2.3.4 - 2013-08-19 * * Licensed under the MIT license. * https://github.com/zixaphir/appchan-x/blob/master/LICENSE diff --git a/builds/appchan-x.user.js b/builds/appchan-x.user.js index 86571389a..78dafb7b6 100644 --- a/builds/appchan-x.user.js +++ b/builds/appchan-x.user.js @@ -20,7 +20,7 @@ // ==/UserScript== /* -* appchan x - Version 2.3.4 - 2013-08-18 +* appchan x - Version 2.3.4 - 2013-08-19 * * Licensed under the MIT license. * https://github.com/zixaphir/appchan-x/blob/master/LICENSE @@ -12136,7 +12136,21 @@ Style = { init: function() { - this.setup(); + var i, item, items, theme; + + theme = Themes[Conf['theme']] || Themes['Yotsuba B']; + Style.svg = $.el('div', { + id: 'svg_filters' + }); + items = [['layoutCSS', Style.layout, 'layout'], ['themeCSS', Style.theme(theme), 'theme'], ['emojiCSS', Emoji.css(), 'emoji'], ['dynamicCSS', Style.dynamic(), 'dynamic'], ['icons', "", 'icons'], ['paddingSheet', "", 'padding'], ['mascot', "", 'mascotSheet']]; + i = 0; + while (item = items[i++]) { + Style[item[0]] = $.addStyle(item[1], item[2]); + } + $.addStyle(JSColor.css(), 'jsColor'); + $.asap((function() { + return d.head; + }), Style.observe); $.asap((function() { return d.body; }), this.asapInit); @@ -12198,57 +12212,42 @@ }); } }, - setup: function() { - var i, item, items, theme; - - theme = Themes[Conf['theme']] || Themes['Yotsuba B']; - Style.svg = $.el('div', { - id: 'svg_filters' - }); - items = [['layoutCSS', Style.layout, 'layout'], ['themeCSS', Style.theme(theme), 'theme'], ['emojiCSS', Emoji.css(), 'emoji'], ['dynamicCSS', Style.dynamic(), 'dynamic'], ['icons', "", 'icons'], ['paddingSheet', "", 'padding'], ['mascot', "", 'mascotSheet']]; - i = 0; - while (item = items[i++]) { - Style[item[0]] = $.addStyle(item[1], item[2]); - } - $.addStyle(JSColor.css(), 'jsColor'); - if (d.head) { - this.remStyle(); - } - return this.observe(); - }, observe: function() { var onMutationObserver; if (window.MutationObserver) { - Style.observer = new MutationObserver(onMutationObserver = this.wrapper); - return Style.observer.observe(d, { + Style.observer = new MutationObserver(onMutationObserver = Style.wrapper); + return Style.observer.observe(d.head, { childList: true, subtree: true }); } else { - return $.on(d, 'DOMNodeInserted', this.wrapper); + return $.on(d.head, 'DOMNodeInserted', Style.wrapper); } }, wrapper: function() { - if (d.head) { - Style.remStyle(); - if (d.readyState === 'complete') { - if (Style.observer) { - return Style.observer.disconnect(); - } else { - return $.off(d, 'DOMNodeInserted', Style.wrapper); - } + var first; + + first = { + addedNodes: d.head.children + }; + Style.remStyle(first); + if (d.readyState === 'complete') { + if (Style.observer) { + return Style.observer.disconnect(); + } else { + return $.off(d, 'DOMNodeInserted', Style.wrapper); } } }, - remStyle: function() { - var href, i, node, nodes; + remStyle: function(_arg) { + var addedNodes, href, i, node; - nodes = d.head.children; - i = nodes.length; + addedNodes = _arg.addedNodes; + i = addedNodes.length; while (i--) { - node = nodes[i]; - if (node.id || !['STYLE', 'LINK'].contains(node.nodeName) || node.rel && !(/stylesheet/.test(node.rel) || (/flags.*\.css$/.test(href = node.href) || href.slice(0, 4) === 'data')) || (/\.typeset/.test(node.textContent))) { + node = addedNodes[i]; + if (node.nodeName === 'STYLE' && node.id || node.nodeName !== 'LINK' || node.rel && (!/stylesheet/.test(node.rel) || /flags.*\.css$/.test(href = node.href) || href.slice(0, 4) === 'data') || /\.typeset/.test(node.textContent)) { continue; } $.rm(node); diff --git a/builds/crx/script.js b/builds/crx/script.js index 4f9e3c6bb..05ff306d3 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -1,6 +1,6 @@ // Generated by CoffeeScript /* -* appchan x - Version 2.3.4 - 2013-08-18 +* appchan x - Version 2.3.4 - 2013-08-19 * * Licensed under the MIT license. * https://github.com/zixaphir/appchan-x/blob/master/LICENSE @@ -12129,7 +12129,21 @@ Style = { init: function() { - this.setup(); + var i, item, items, theme; + + theme = Themes[Conf['theme']] || Themes['Yotsuba B']; + Style.svg = $.el('div', { + id: 'svg_filters' + }); + items = [['layoutCSS', Style.layout, 'layout'], ['themeCSS', Style.theme(theme), 'theme'], ['emojiCSS', Emoji.css(), 'emoji'], ['dynamicCSS', Style.dynamic(), 'dynamic'], ['icons', "", 'icons'], ['paddingSheet', "", 'padding'], ['mascot', "", 'mascotSheet']]; + i = 0; + while (item = items[i++]) { + Style[item[0]] = $.addStyle(item[1], item[2]); + } + $.addStyle(JSColor.css(), 'jsColor'); + $.asap((function() { + return d.head; + }), Style.observe); $.asap((function() { return d.body; }), this.asapInit); @@ -12191,57 +12205,42 @@ }); } }, - setup: function() { - var i, item, items, theme; - - theme = Themes[Conf['theme']] || Themes['Yotsuba B']; - Style.svg = $.el('div', { - id: 'svg_filters' - }); - items = [['layoutCSS', Style.layout, 'layout'], ['themeCSS', Style.theme(theme), 'theme'], ['emojiCSS', Emoji.css(), 'emoji'], ['dynamicCSS', Style.dynamic(), 'dynamic'], ['icons', "", 'icons'], ['paddingSheet', "", 'padding'], ['mascot', "", 'mascotSheet']]; - i = 0; - while (item = items[i++]) { - Style[item[0]] = $.addStyle(item[1], item[2]); - } - $.addStyle(JSColor.css(), 'jsColor'); - if (d.head) { - this.remStyle(); - } - return this.observe(); - }, observe: function() { var onMutationObserver; if (window.MutationObserver) { - Style.observer = new MutationObserver(onMutationObserver = this.wrapper); - return Style.observer.observe(d, { + Style.observer = new MutationObserver(onMutationObserver = Style.wrapper); + return Style.observer.observe(d.head, { childList: true, subtree: true }); } else { - return $.on(d, 'DOMNodeInserted', this.wrapper); + return $.on(d.head, 'DOMNodeInserted', Style.wrapper); } }, wrapper: function() { - if (d.head) { - Style.remStyle(); - if (d.readyState === 'complete') { - if (Style.observer) { - return Style.observer.disconnect(); - } else { - return $.off(d, 'DOMNodeInserted', Style.wrapper); - } + var first; + + first = { + addedNodes: d.head.children + }; + Style.remStyle(first); + if (d.readyState === 'complete') { + if (Style.observer) { + return Style.observer.disconnect(); + } else { + return $.off(d, 'DOMNodeInserted', Style.wrapper); } } }, - remStyle: function() { - var href, i, node, nodes; + remStyle: function(_arg) { + var addedNodes, href, i, node; - nodes = d.head.children; - i = nodes.length; + addedNodes = _arg.addedNodes; + i = addedNodes.length; while (i--) { - node = nodes[i]; - if (node.id || !['STYLE', 'LINK'].contains(node.nodeName) || node.rel && !(/stylesheet/.test(node.rel) || (/flags.*\.css$/.test(href = node.href) || href.slice(0, 4) === 'data')) || (/\.typeset/.test(node.textContent))) { + node = addedNodes[i]; + if (node.nodeName === 'STYLE' && node.id || node.nodeName !== 'LINK' || node.rel && (!/stylesheet/.test(node.rel) || /flags.*\.css$/.test(href = node.href) || href.slice(0, 4) === 'data') || /\.typeset/.test(node.textContent)) { continue; } $.rm(node); diff --git a/src/Theming/Style.coffee b/src/Theming/Style.coffee index a5fd42e05..7f008ee46 100644 --- a/src/Theming/Style.coffee +++ b/src/Theming/Style.coffee @@ -1,6 +1,28 @@ Style = init: -> - @setup() + theme = Themes[Conf['theme']] or Themes['Yotsuba B'] + Style.svg = $.el 'div', + id: 'svg_filters' + + items = [ + ['layoutCSS', Style.layout, 'layout'] + ['themeCSS', Style.theme(theme), 'theme'] + ['emojiCSS', Emoji.css(), 'emoji'] + ['dynamicCSS', Style.dynamic(), 'dynamic'] + ['icons', "", 'icons'] + ['paddingSheet', "", 'padding'] + ['mascot', "", 'mascotSheet'] + ] + + i = 0 + while item = items[i++] + Style[item[0]] = $.addStyle item[1], item[2] + + # Non-customizable + $.addStyle JSColor.css(), 'jsColor' + + $.asap (-> d.head), Style.observe + $.asap (-> d.body), @asapInit $.on window, "resize", Style.padding $.ready @readyInit @@ -47,61 +69,34 @@ Style = $.on exLink, "click", -> setTimeout Rice.nodes, 100 - setup: -> - theme = Themes[Conf['theme']] or Themes['Yotsuba B'] - Style.svg = $.el 'div', - id: 'svg_filters' - - items = [ - ['layoutCSS', Style.layout, 'layout'] - ['themeCSS', Style.theme(theme), 'theme'] - ['emojiCSS', Emoji.css(), 'emoji'] - ['dynamicCSS', Style.dynamic(), 'dynamic'] - ['icons', "", 'icons'] - ['paddingSheet', "", 'padding'] - ['mascot', "", 'mascotSheet'] - ] - - i = 0 - while item = items[i++] - Style[item[0]] = $.addStyle item[1], item[2] - - # Non-customizable - $.addStyle JSColor.css(), 'jsColor' - - if d.head - @remStyle() - @observe() - observe: -> if window.MutationObserver - Style.observer = new MutationObserver onMutationObserver = @wrapper - Style.observer.observe d, + Style.observer = new MutationObserver onMutationObserver = Style.wrapper + Style.observer.observe d.head, childList: true subtree: true else - $.on d, 'DOMNodeInserted', @wrapper + $.on d.head, 'DOMNodeInserted', Style.wrapper wrapper: -> - if d.head - Style.remStyle() + first = {addedNodes: d.head.children} + Style.remStyle(first) - if d.readyState is 'complete' - if Style.observer - Style.observer.disconnect() - else - $.off d, 'DOMNodeInserted', Style.wrapper + if d.readyState is 'complete' + if Style.observer + Style.observer.disconnect() + else + $.off d, 'DOMNodeInserted', Style.wrapper - remStyle: -> - nodes = d.head.children - i = nodes.length + remStyle: ({addedNodes}) -> + i = addedNodes.length while i-- - node = nodes[i] + node = addedNodes[i] - continue if node.id or - !['STYLE', 'LINK'].contains(node.nodeName) or - node.rel and !(/stylesheet/.test(node.rel) or (/flags.*\.css$/.test(href = node.href) or href[..3] is 'data')) or - (/\.typeset/.test node.textContent) + continue if node.nodeName is 'STYLE' and node.id or + node.nodeName isnt 'LINK' or + node.rel and ((!/stylesheet/.test(node.rel) or /flags.*\.css$/.test(href = node.href) or href[..3] is 'data')) or + /\.typeset/.test node.textContent $.rm node return From 00c1976ddd7860775f7ac068658f60cc206719f1 Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Mon, 19 Aug 2013 20:52:24 -0700 Subject: [PATCH 2/2] Fix --- builds/appchan-x.user.js | 2 +- builds/crx/script.js | 2 +- src/Theming/Style.coffee | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/builds/appchan-x.user.js b/builds/appchan-x.user.js index 78dafb7b6..476a51f90 100644 --- a/builds/appchan-x.user.js +++ b/builds/appchan-x.user.js @@ -12247,7 +12247,7 @@ i = addedNodes.length; while (i--) { node = addedNodes[i]; - if (node.nodeName === 'STYLE' && node.id || node.nodeName !== 'LINK' || node.rel && (!/stylesheet/.test(node.rel) || /flags.*\.css$/.test(href = node.href) || href.slice(0, 4) === 'data') || /\.typeset/.test(node.textContent)) { + if (node.nodeName === 'STYLE' && node.id || !['LINK', 'STYLE'].contains(node.nodeName) || node.rel && (!/stylesheet/.test(node.rel) || /flags.*\.css$/.test(href = node.href) || href.slice(0, 4) === 'data') || /\.typeset/.test(node.textContent)) { continue; } $.rm(node); diff --git a/builds/crx/script.js b/builds/crx/script.js index 05ff306d3..0c198e22b 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -12240,7 +12240,7 @@ i = addedNodes.length; while (i--) { node = addedNodes[i]; - if (node.nodeName === 'STYLE' && node.id || node.nodeName !== 'LINK' || node.rel && (!/stylesheet/.test(node.rel) || /flags.*\.css$/.test(href = node.href) || href.slice(0, 4) === 'data') || /\.typeset/.test(node.textContent)) { + if (node.nodeName === 'STYLE' && node.id || !['LINK', 'STYLE'].contains(node.nodeName) || node.rel && (!/stylesheet/.test(node.rel) || /flags.*\.css$/.test(href = node.href) || href.slice(0, 4) === 'data') || /\.typeset/.test(node.textContent)) { continue; } $.rm(node); diff --git a/src/Theming/Style.coffee b/src/Theming/Style.coffee index 7f008ee46..592330f5a 100644 --- a/src/Theming/Style.coffee +++ b/src/Theming/Style.coffee @@ -94,7 +94,7 @@ Style = node = addedNodes[i] continue if node.nodeName is 'STYLE' and node.id or - node.nodeName isnt 'LINK' or + !['LINK', 'STYLE'].contains(node.nodeName) or node.rel and ((!/stylesheet/.test(node.rel) or /flags.*\.css$/.test(href = node.href) or href[..3] is 'data')) or /\.typeset/.test node.textContent $.rm node