diff --git a/src/General/Header.coffee b/src/General/Header.coffee
index f2f003cab..054d5ba8c 100644
--- a/src/General/Header.coffee
+++ b/src/General/Header.coffee
@@ -1,5 +1,12 @@
Header =
init: ->
+ $.onExists doc, 'body', =>
+ return unless Main.isThisPageLegit()
+ $.add @bar, [@noticesRoot, @toggle]
+ $.prepend d.body, @bar
+ $.add d.body, Header.hover
+ @setBarPosition Conf['Bottom Header']
+
@menu = new UI.Menu 'header'
menuButton = $.el 'span',
@@ -86,12 +93,6 @@ Header =
@setBoardList()
- $.onExists doc, 'body', =>
- return unless Main.isThisPageLegit()
- $.prepend d.body, @bar
- $.add d.body, Header.hover
- @setBarPosition Conf['Bottom Header']
-
$.onExists doc, "#{g.SITE.selectors.boardList} + *", Header.generateFullBoardList
Main.ready ->
@@ -102,7 +103,8 @@ Header =
$('#navtopright', footer).id = 'navbotright'
$('#settingsWindowLink', footer).id = 'settingsWindowLinkBot'
$.before absbot, footer
- $.globalEval 'window.cloneTopNav = function() {};'
+ $.global ->
+ window.cloneTopNav = ->
if (Header.bottomBoardList = $ g.SITE.selectors.boardListBottom)
for a in $$ 'a', Header.bottomBoardList
a.className = 'current' if a.hostname is location.hostname and a.pathname.split('/')[1] is g.BOARD.ID
@@ -154,7 +156,7 @@ Header =
btn = $('.hide-board-list-button', boardList)
$.on btn, 'click', Header.toggleBoardList
- $.add Header.bar, [Header.boardList, Header.shortcuts, Header.noticesRoot, Header.toggle]
+ $.prepend Header.bar, [Header.boardList, Header.shortcuts]
Header.setCustomNav Conf['Custom Board Navigation']
Header.generateBoardList Conf['boardnav']
@@ -392,7 +394,7 @@ Header =
Header.previousOffset = offsetY
setBarPosition: (bottom) ->
- Header.barPositionToggler.checked = bottom
+ Header.barPositionToggler?.checked = bottom
$.event 'CloseMenu'
args = if bottom then [
'bottom-header'
diff --git a/src/General/Settings.coffee b/src/General/Settings.coffee
index 25c7165d9..af1da0bb9 100644
--- a/src/General/Settings.coffee
+++ b/src/General/Settings.coffee
@@ -21,7 +21,7 @@ Settings =
$.on d, 'AddSettingsSection', Settings.addSection
$.on d, 'OpenSettings', (e) -> Settings.open e.detail
- if Conf['Disable Native Extension']
+ if g.SITE.software is 'yotsuba' and Conf['Disable Native Extension']
if $.hasStorage
# Run in page context to handle case where 4chan X has localStorage access but not the page.
# (e.g. Pale Moon 26.2.2, GM 3.8, cookies disabled for 4chan only)
diff --git a/src/General/Test.coffee b/src/General/Test.coffee
index 43f985eb4..98ce9d8e7 100644
--- a/src/General/Test.coffee
+++ b/src/General/Test.coffee
@@ -18,6 +18,10 @@ Test =
Header.menu.addEntry
el: a2
+ assert: (condition) ->
+ unless condition()
+ new Notice 'warning', "Assertion failed: #{condition}", 30
+
normalize: (root) ->
root2 = root.cloneNode true
for el in $$ '.mobile', root2
diff --git a/src/Linkification/Linkify.coffee b/src/Linkification/Linkify.coffee
index d1abed37a..7a82bd1a7 100644
--- a/src/Linkification/Linkify.coffee
+++ b/src/Linkification/Linkify.coffee
@@ -71,7 +71,10 @@ Linkify =
if Linkify.regString.test word
links.push Linkify.makeRange node, endNode, index, length
- <% if (readJSON('/.tests_enabled')) { %><%= assert('word is links[links.length-1].toString()') %><% } %>
+ <% if (readJSON('/.tests_enabled')) { %>
+ Test.assert ->
+ word is links[links.length-1].toString()
+ <% } %>
break unless test.lastIndex and node is endNode
diff --git a/src/Miscellaneous/Fourchan.coffee b/src/Miscellaneous/Fourchan.coffee
index 7064f3c1b..9a50a5c1c 100644
--- a/src/Miscellaneous/Fourchan.coffee
+++ b/src/Miscellaneous/Fourchan.coffee
@@ -12,17 +12,16 @@ Fourchan =
unless $.hasClass pre, 'prettyprinted'
pre.innerHTML = e.detail.html
$.addClass pre, 'prettyprinted'
- $.globalEval '''
- window.addEventListener('prettyprint', function(e) {
+ $.global ->
+ window.addEventListener('prettyprint', (e) ->
window.dispatchEvent(new CustomEvent('prettyprint:cb', {
detail: {
ID: e.detail.ID,
i: e.detail.i,
- html: prettyPrintOne(e.detail.html)
+ html: window.prettyPrintOne(e.detail.html)
}
- }));
- }, false);
- '''
+ }))
+ , false)
Callbacks.Post.push
name: 'Parse [code] tags'
cb: Fourchan.code
diff --git a/src/main/Main.coffee b/src/main/Main.coffee
index 7d513a3ad..f5bd1fa07 100644
--- a/src/main/Main.coffee
+++ b/src/main/Main.coffee
@@ -99,6 +99,7 @@ Main =
# Fresh install
else if !items.previousversion?
+ Main.isFirstRun = true
Main.ready ->
$.set 'previousversion', g.VERSION
Settings.open()
@@ -502,6 +503,16 @@ Main =
new Notice 'error', 'Error: Multiple copies of 4chan X are enabled.'
$.addClass doc, 'tainted'
+ # Detect conflicts with native extension
+ if g.SITE.testNativeExtension and not $.hasClass(doc, 'tainted')
+ {enabled} = g.SITE.testNativeExtension()
+ if enabled
+ $.addClass doc, 'tainted'
+ if Conf['Disable Native Extension'] and !Main.isFirstRun
+ msg = $.el 'div',
+ <%= html('Failed to disable the native extension. You may need to block it.') %>
+ new Notice 'error', msg
+
unless errors instanceof Array
error = errors
else if errors.length is 1
@@ -556,7 +567,7 @@ Main =
addDetails data.error.stack.replace(data.error.toString(), '').trim() if data.error.stack
addDetails '\n`' + data.html + '`' if data.html
details = details.replace /file:\/{3}.+\//g, '' # Remove local file paths
- url = "<%= meta.newIssue.replace('%title', '#{encodeURIComponent title}').replace('%details', '#{encodeURIComponent details}') %>"
+ url = '<%= meta.newIssue %>'.replace('%title', encodeURIComponent title).replace('%details', encodeURIComponent details)
<%= html(' [report]') %>
isThisPageLegit: ->
diff --git a/src/platform/$.coffee b/src/platform/$.coffee
index bc195b1df..731f34a61 100644
--- a/src/platform/$.coffee
+++ b/src/platform/$.coffee
@@ -445,19 +445,19 @@ $.queueTask = do ->
taskQueue.push arguments
setTimeout execTask, 0
-$.globalEval = (code, data) ->
- script = $.el 'script',
- textContent: code
- $.extend script.dataset, data if data
- $.add (d.head or doc), script
- $.rm script
-
$.global = (fn, data) ->
if doc
- $.globalEval "(#{fn})();", data
+ script = $.el 'script',
+ textContent: "(#{fn}).call(document.currentScript.dataset);"
+ $.extend script.dataset, data if data
+ $.add (d.head or doc), script
+ $.rm script
+ script.dataset
else
# XXX dwb
- fn()
+ try
+ fn.call(data)
+ data
$.bytesToString = (size) ->
unit = 0 # Bytes
diff --git a/src/site/SW.yotsuba.coffee b/src/site/SW.yotsuba.coffee
index 44521b85a..c29f51cfe 100644
--- a/src/site/SW.yotsuba.coffee
+++ b/src/site/SW.yotsuba.coffee
@@ -225,3 +225,7 @@ SW.yotsuba =
isLinkified: (link) ->
ImageHost.test(link.hostname)
+
+ testNativeExtension: ->
+ $.global ->
+ @enabled = 'true' if window.Parser.postMenuIcon
diff --git a/tools/template.js b/tools/template.js
index 2e361ea93..b75cab4cc 100644
--- a/tools/template.js
+++ b/tools/template.js
@@ -168,11 +168,7 @@ tools.html = function(template) {
if (stream.text) {
throw new Error(`Unexpected characters in template (${stream.text}): ${template}`);
}
- return `(innerHTML: \`${output}\`)`;
-};
-
-tools.assert = function(statement) {
- return `throw new Error 'Assertion failed: ' + \`${constExpression(statement)}\` unless ${statement}`;
+ return `\`{innerHTML: ${output}}\``;
};
function includesDir(templateName) {