From 9329c7ce6ec21aec1ac1195348ec66f14c2dbaac Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Fri, 14 Sep 2012 19:53:59 +0200 Subject: [PATCH] Close #753. --- 4chan_x.user.js | 12 ++++++++++-- script.coffee | 12 ++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index c3eec1885..8238b7acb 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -402,11 +402,19 @@ } }, addStyle: function(css) { - var style; + var f, style; style = $.el('style', { textContent: css }); - $.add(d.head || d.documentElement, style); + f = function() { + var root; + if (root = d.head || d.documentElement) { + return $.add(root, style); + } else { + return setTimeout(f, 20); + } + }; + f(); return style; }, x: function(path, root) { diff --git a/script.coffee b/script.coffee index 2e6a74815..522ff0783 100644 --- a/script.coffee +++ b/script.coffee @@ -315,8 +315,16 @@ $.extend $, addStyle: (css) -> style = $.el 'style', textContent: css - # XXX Only Chrome has no d.head on document-start. - $.add d.head or d.documentElement, style + # That's terrible. + # XXX tmp fix for scriptish: + # https://github.com/scriptish/scriptish/issues/16 + f = -> + # XXX Only Chrome has no d.head on document-start. + if root = d.head or d.documentElement + $.add root, style + else + setTimeout f, 20 + f() style x: (path, root=d.body) -> # XPathResult.ANY_UNORDERED_NODE_TYPE is 8