diff --git a/4chan_x.user.js b/4chan_x.user.js index 674deb1f4..1c24e63a8 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -43,7 +43,7 @@ */ (function() { - var $, $$, Anonymize, AutoGIF, Board, Build, Clone, Conf, Config, FileInfo, Get, ImageHover, Main, Post, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, Quotify, Redirect, RevealSpoilers, Sauce, Thread, ThreadUpdater, Time, UI, d, g, + var $, $$, Anonymize, AutoGIF, Board, Build, Clone, Conf, Config, FileInfo, Get, ImageHover, Main, Post, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, Quotify, Redirect, RevealSpoilers, Sauce, Thread, ThreadUpdater, Time, UI, d, g, unitTesting, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; @@ -170,7 +170,9 @@ imageFit: 'fit width' }; - if (!/^(boards|images|sys)\.4chan\.org$/.test(location.hostname)) { + unitTesting = !!window.QUnit; + + if (!(/^(boards|images|sys)\.4chan\.org$/.test(location.hostname) || unitTesting)) { return; } @@ -601,7 +603,7 @@ $.add(d.head, script); return $.rm(script); }, - unsafeWindow: window.opera ? window : unsafeWindow !== window ? unsafeWindow : (function() { + unsafeWindow: unitTesting || window.opera ? window : unsafeWindow !== window ? unsafeWindow : (function() { var p; p = d.createElement('p'); p.setAttribute('onclick', 'return window'); @@ -2571,8 +2573,8 @@ val = Conf[key]; Conf[key] = $.get(key, val); } - if (QUnit) { - Main.initQUnit(); + if (unitTesting) { + Main.initUnitTesting(); return; } pathname = location.pathname.split('/'); @@ -2599,7 +2601,7 @@ }); } }, - initQUnit: function() { + initUnitTesting: function() { window.x = { UI: UI, $: $, diff --git a/lib/$.coffee b/lib/$.coffee index 9cb8d1e7c..263564d85 100644 --- a/lib/$.coffee +++ b/lib/$.coffee @@ -163,8 +163,9 @@ $.extend $, $.rm script # http://mths.be/unsafewindow unsafeWindow: - if window.opera # Opera - window + if unitTesting or # unit testing + window.opera # Opera + window else if unsafeWindow isnt window # Firefox unsafeWindow else # Chrome diff --git a/src/globals.coffee b/src/globals.coffee index 3240504f0..2f86bbc11 100644 --- a/src/globals.coffee +++ b/src/globals.coffee @@ -1,6 +1,8 @@ +unitTesting = !!window.QUnit + # Opera doesn't support the @match metadata key, # return 4chan X here if we're not on 4chan. -return unless /^(boards|images|sys)\.4chan\.org$/.test location.hostname +return unless /^(boards|images|sys)\.4chan\.org$/.test(location.hostname) or unitTesting Conf = {} d = document diff --git a/src/main.coffee b/src/main.coffee index c4d6cae80..44e01e913 100644 --- a/src/main.coffee +++ b/src/main.coffee @@ -266,8 +266,8 @@ Main = for key, val of Conf Conf[key] = $.get key, val - if QUnit - Main.initQUnit() + if unitTesting + Main.initUnitTesting() return pathname = location.pathname.split '/' @@ -289,7 +289,7 @@ Main = location.href = url if url return - initQUnit: -> + initUnitTesting: -> window.x = # ui.coffee UI: UI