From 68761aac287adb5c53126e4a72245dc12340b3fd Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Sun, 3 Mar 2013 17:31:07 +0100 Subject: [PATCH] Fix $.open. #932 --- 4chan_x.user.js | 32 ++++++++++++++++++++++---------- lib/$.coffee | 10 ++++++++-- src/features.coffee | 3 ++- src/main.coffee | 8 ++++---- src/qr.coffee | 4 ++-- 5 files changed, 38 insertions(+), 19 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index da2f500dd..dc872815b 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -842,9 +842,21 @@ detail: detail })); }, - open: function(url) { - return (window.GM_openInTab || window.open)(url, '_blank'); - }, + open: (function() { + if (typeof GM_openInTab !== "undefined" && GM_openInTab !== null) { + return function(URL) { + var a; + a = $.el('a', { + href: URL + }); + return GM_openInTab(a.href, '_blank'); + }; + } else { + return function(URL) { + return window.open(URL, '_blank'); + }; + } + })(), debounce: function(wait, fn) { var args, exec, that, timeout; timeout = null; @@ -2907,7 +2919,7 @@ if (g.VIEW !== 'index') { return; } - url = "//boards.4chan.org/" + thread.board + "/res/" + thread; + url = "/" + thread.board + "/res/" + thread; if (tab) { return $.open(url); } else { @@ -4533,6 +4545,9 @@ completeExpand: function(post) { var rect, root, thumb; thumb = post.file.thumb; + if (!$.hasClass(thumb, 'expanding')) { + return; + } rect = post.nodes.root.getBoundingClientRect(); $.addClass(post.nodes.root, 'expanded-image'); $.rmClass(post.file.thumb, 'expanding'); @@ -6808,9 +6823,9 @@ isReply: !!threadID }); if (threadID === postID) { - $.open("//boards.4chan.org/" + g.BOARD + "/res/" + threadID); + $.open("/" + g.BOARD + "/res/" + threadID); } else if (g.VIEW === 'index' && !QR.cooldown.auto) { - $.open("//boards.4chan.org/" + g.BOARD + "/res/" + threadID + "#p" + postID); + $.open("/" + g.BOARD + "/res/" + threadID + "#p" + postID); } if (!(Conf['Persistent QR'] || QR.cooldown.auto)) { QR.close(); @@ -7243,7 +7258,6 @@ return; } initFeature = function(name, module) { - console.time("" + name + " initialization"); try { return module.init(); } catch (err) { @@ -7252,10 +7266,9 @@ error: err }); } finally { - console.timeEnd("" + name + " initialization"); + } }; - console.time('All initializations'); initFeature('Polyfill', Polyfill); initFeature('Header', Header); initFeature('Settings', Settings); @@ -7301,7 +7314,6 @@ initFeature('Thread Watcher', ThreadWatcher); initFeature('Index Navigation', Nav); initFeature('Keybinds', Keybinds); - console.timeEnd('All initializations'); $.on(d, 'AddCallback', Main.addCallback); $.on(d, '4chanMainInit', Main.initStyle); return $.ready(Main.initReady); diff --git a/lib/$.coffee b/lib/$.coffee index d3127ac57..e374a6e71 100644 --- a/lib/$.coffee +++ b/lib/$.coffee @@ -138,8 +138,14 @@ $.extend $, return event: (event, detail, root=d) -> root.dispatchEvent new CustomEvent event, {bubbles: true, detail} - open: (url) -> - (window.GM_openInTab or window.open) url, '_blank' + open: do -> + if GM_openInTab? + (URL) -> + # XXX fix GM opening file://// for protocol-less URLs. + a = $.el 'a', href: URL + GM_openInTab a.href, '_blank' + else + (URL) -> window.open URL, '_blank' debounce: (wait, fn) -> timeout = null that = null diff --git a/src/features.coffee b/src/features.coffee index 4b5834eea..1281eaeea 100644 --- a/src/features.coffee +++ b/src/features.coffee @@ -1616,7 +1616,7 @@ Keybinds = open: (thread, tab) -> return if g.VIEW isnt 'index' - url = "//boards.4chan.org/#{thread.board}/res/#{thread}" + url = "/#{thread.board}/res/#{thread}" if tab $.open url else @@ -3023,6 +3023,7 @@ ImageExpand = completeExpand: (post) -> {thumb} = post.file + return unless $.hasClass thumb, 'expanding' # contracted before the image loaded rect = post.nodes.root.getBoundingClientRect() $.addClass post.nodes.root, 'expanded-image' $.rmClass post.file.thumb, 'expanding' diff --git a/src/main.coffee b/src/main.coffee index 7fcfcec01..1fc9074bb 100644 --- a/src/main.coffee +++ b/src/main.coffee @@ -300,7 +300,7 @@ Main = return initFeature = (name, module) -> - console.time "#{name} initialization" + # console.time "#{name} initialization" try module.init() catch err @@ -308,9 +308,9 @@ Main = message: "\"#{name}\" initialization crashed." error: err finally - console.timeEnd "#{name} initialization" + # console.timeEnd "#{name} initialization" - console.time 'All initializations' + # console.time 'All initializations' initFeature 'Polyfill', Polyfill initFeature 'Header', Header initFeature 'Settings', Settings @@ -356,7 +356,7 @@ Main = initFeature 'Thread Watcher', ThreadWatcher initFeature 'Index Navigation', Nav initFeature 'Keybinds', Keybinds - console.timeEnd 'All initializations' + # console.timeEnd 'All initializations' $.on d, 'AddCallback', Main.addCallback $.on d, '4chanMainInit', Main.initStyle diff --git a/src/qr.coffee b/src/qr.coffee index c4e0ca321..96ed44b5e 100644 --- a/src/qr.coffee +++ b/src/qr.coffee @@ -981,9 +981,9 @@ QR = isReply: !!threadID if threadID is postID # new thread - $.open "//boards.4chan.org/#{g.BOARD}/res/#{threadID}" + $.open "/#{g.BOARD}/res/#{threadID}" else if g.VIEW is 'index' and !QR.cooldown.auto # posting from the index - $.open "//boards.4chan.org/#{g.BOARD}/res/#{threadID}#p#{postID}" + $.open "/#{g.BOARD}/res/#{threadID}#p#{postID}" unless Conf['Persistent QR'] or QR.cooldown.auto QR.close()