From d2c670090b1e1fc84b5fe648208bedb18978d548 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Fri, 4 Aug 2017 04:36:52 -0700 Subject: [PATCH 1/5] Add an extension ID. --- package.json | 1 + src/meta/manifest.json | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index a0d89c1c6..8aa1496af 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "newIssue": "https://gitreports.com/issue/ccd0/4chan-x?issue_title=%title&details=%details", "newIssueMaxLength": 8181, "appid": "lacclbnghgdicfifcamcmcnilckjamag", + "appidGecko": "4chan-x@4chan-x.net", "chromeStoreID": "ohnjgmpcibpbafdlkimncjhflgedgpam", "recaptchaKey": "6Ldp2bsSAAAAAAJ5uyx_lx34lJeEpTLVkP5k04qc", "youtubeAPIKey": "AIzaSyB5_zaen_-46Uhz1xGR-lz1YoUMHqCD6CE", diff --git a/src/meta/manifest.json b/src/meta/manifest.json index af5b31144..5ae8a594c 100644 --- a/src/meta/manifest.json +++ b/src/meta/manifest.json @@ -28,5 +28,10 @@ ], "optional_permissions": [ "*://*/" - ] + ], + "applications": { + "gecko": { + "id": "<%= meta.appidGecko %>" + } + } } From 42ab72a543001d2c24eb5f1b34ca4a25d7acda98 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Fri, 4 Aug 2017 05:13:17 -0700 Subject: [PATCH 2/5] WebExtensions doesn't like protocol relative URLs in AJAX requests. --- src/General/BoardConfig.coffee | 2 +- src/General/Build.Test.coffee | 2 +- src/General/Index.coffee | 2 +- src/Images/ImageCommon.coffee | 2 +- src/Linkification/Embedding.coffee | 2 +- src/Miscellaneous/ExpandComment.coffee | 2 +- src/Miscellaneous/ExpandThread.coffee | 2 +- src/Monitoring/ThreadStats.coffee | 2 +- src/Monitoring/ThreadUpdater.coffee | 4 ++-- src/Monitoring/ThreadWatcher.coffee | 2 +- src/classes/DataBoard.coffee | 4 ++-- src/classes/Fetcher.coffee | 4 ++-- src/main/Main.coffee | 2 +- 13 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/General/BoardConfig.coffee b/src/General/BoardConfig.coffee index 206d78d49..bd05250a0 100644 --- a/src/General/BoardConfig.coffee +++ b/src/General/BoardConfig.coffee @@ -4,7 +4,7 @@ BoardConfig = init: -> now = Date.now() unless now - 2 * $.HOUR < (Conf['boardConfig'].lastChecked or 0) <= now - $.ajax '//a.4cdn.org/boards.json', + $.ajax "#{location.protocol}//a.4cdn.org/boards.json", onloadend: @load else @set Conf['boardConfig'].boards diff --git a/src/General/Build.Test.coffee b/src/General/Build.Test.coffee index b12520405..9ff50cceb 100644 --- a/src/General/Build.Test.coffee +++ b/src/General/Build.Test.coffee @@ -65,7 +65,7 @@ Build.Test = testOne: (post) -> Build.Test.postsRemaining++ - $.cache "//a.4cdn.org/#{post.board.ID}/thread/#{post.thread.ID}.json", -> + $.cache "#{location.protocol}//a.4cdn.org/#{post.board.ID}/thread/#{post.thread.ID}.json", -> {posts} = @response Build.spoilerRange[post.board.ID] = posts[0].custom_spoiler for postData in posts diff --git a/src/General/Index.coffee b/src/General/Index.coffee index e2ccf6e37..52d30e79d 100644 --- a/src/General/Index.coffee +++ b/src/General/Index.coffee @@ -591,7 +591,7 @@ Index = location.reload() return - Index.req = $.ajax "//a.4cdn.org/#{g.BOARD}/catalog.json", + Index.req = $.ajax "#{location.protocol}//a.4cdn.org/#{g.BOARD}/catalog.json", onabort: Index.load onloadend: Index.load , diff --git a/src/Images/ImageCommon.coffee b/src/Images/ImageCommon.coffee index 7ec92690e..eec68dafa 100644 --- a/src/Images/ImageCommon.coffee +++ b/src/Images/ImageCommon.coffee @@ -54,7 +54,7 @@ ImageCommon = clearTimeout timeoutID if delay? cb URL - $.ajax "//a.4cdn.org/#{post.board}/thread/#{post.thread}.json", onload: -> + $.ajax "#{location.protocol}//a.4cdn.org/#{post.board}/thread/#{post.thread}.json", onload: -> post.kill !post.isClone if @status is 404 return redirect() if @status isnt 200 for postObj in @response.posts diff --git a/src/Linkification/Embedding.coffee b/src/Linkification/Embedding.coffee index 473050a88..f6d398160 100644 --- a/src/Linkification/Embedding.coffee +++ b/src/Linkification/Embedding.coffee @@ -376,7 +376,7 @@ Embedding = $.el 'iframe', src: "https://w.soundcloud.com/player/?visual=true&show_comments=false&url=https%3A%2F%2Fsoundcloud.com%2F#{encodeURIComponent a.dataset.uid}" title: - api: (uid) -> "//soundcloud.com/oembed?format=json&url=https%3A%2F%2Fsoundcloud.com%2F#{encodeURIComponent uid}" + api: (uid) -> "#{location.protocol}//soundcloud.com/oembed?format=json&url=https%3A%2F%2Fsoundcloud.com%2F#{encodeURIComponent uid}" text: (_) -> _.title , key: 'StrawPoll' diff --git a/src/Miscellaneous/ExpandComment.coffee b/src/Miscellaneous/ExpandComment.coffee index 91cfe17dc..09d596774 100644 --- a/src/Miscellaneous/ExpandComment.coffee +++ b/src/Miscellaneous/ExpandComment.coffee @@ -26,7 +26,7 @@ ExpandComment = return return if not (a = $ '.abbr > a', post.nodes.comment) a.textContent = "Post No.#{post} Loading..." - $.cache "//a.4cdn.org#{a.pathname.split(/\/+/).splice(0,4).join('/')}.json", -> ExpandComment.parse @, a, post + $.cache "#{location.protocol}//a.4cdn.org#{a.pathname.split(/\/+/).splice(0,4).join('/')}.json", -> ExpandComment.parse @, a, post contract: (post) -> return unless post.nodes.shortComment diff --git a/src/Miscellaneous/ExpandThread.coffee b/src/Miscellaneous/ExpandThread.coffee index ce9e1d91a..0fba9b288 100644 --- a/src/Miscellaneous/ExpandThread.coffee +++ b/src/Miscellaneous/ExpandThread.coffee @@ -43,7 +43,7 @@ ExpandThread = expand: (thread, a) -> ExpandThread.statuses[thread] = status = {} a.textContent = Build.summaryText '...', a.textContent.match(/\d+/g)... - status.req = $.cache "//a.4cdn.org/#{thread.board}/thread/#{thread}.json", -> + status.req = $.cache "#{location.protocol}//a.4cdn.org/#{thread.board}/thread/#{thread}.json", -> delete status.req ExpandThread.parse @, thread, a diff --git a/src/Monitoring/ThreadStats.coffee b/src/Monitoring/ThreadStats.coffee index 1ad67cb3c..a274ac80a 100644 --- a/src/Monitoring/ThreadStats.coffee +++ b/src/Monitoring/ThreadStats.coffee @@ -75,7 +75,7 @@ ThreadStats = $.addClass ThreadStats.pageCountEl, 'warning' return ThreadStats.timeout = setTimeout ThreadStats.fetchPage, 2 * $.MINUTE - $.ajax "//a.4cdn.org/#{ThreadStats.thread.board}/threads.json", onload: ThreadStats.onThreadsLoad, + $.ajax "#{location.protocol}//a.4cdn.org/#{ThreadStats.thread.board}/threads.json", onload: ThreadStats.onThreadsLoad, whenModified: 'ThreadStats' onThreadsLoad: -> diff --git a/src/Monitoring/ThreadUpdater.coffee b/src/Monitoring/ThreadUpdater.coffee index f2596a8da..d23988e62 100644 --- a/src/Monitoring/ThreadUpdater.coffee +++ b/src/Monitoring/ThreadUpdater.coffee @@ -138,7 +138,7 @@ ThreadUpdater = ThreadUpdater.setInterval() when 404 # XXX workaround for 4chan sending false 404s - $.ajax "//a.4cdn.org/#{ThreadUpdater.thread.board}/catalog.json", onloadend: -> + $.ajax "#{location.protocol}//a.4cdn.org/#{ThreadUpdater.thread.board}/catalog.json", onloadend: -> if @status is 200 confirmed = true for page in @response @@ -231,7 +231,7 @@ ThreadUpdater = clearTimeout ThreadUpdater.timeoutID ThreadUpdater.set 'timer', '...', 'loading' ThreadUpdater.req?.abort() - ThreadUpdater.req = $.ajax "//a.4cdn.org/#{ThreadUpdater.thread.board}/thread/#{ThreadUpdater.thread}.json", + ThreadUpdater.req = $.ajax "#{location.protocol}//a.4cdn.org/#{ThreadUpdater.thread.board}/thread/#{ThreadUpdater.thread}.json", onloadend: ThreadUpdater.cb.load timeout: $.MINUTE , diff --git a/src/Monitoring/ThreadWatcher.coffee b/src/Monitoring/ThreadWatcher.coffee index 970921c60..144a8a34b 100644 --- a/src/Monitoring/ThreadWatcher.coffee +++ b/src/Monitoring/ThreadWatcher.coffee @@ -211,7 +211,7 @@ ThreadWatcher = if ThreadWatcher.requests.length is 0 ThreadWatcher.status.textContent = '...' $.addClass ThreadWatcher.refreshButton, 'fa-spin' - req = $.ajax "//a.4cdn.org/#{boardID}/thread/#{threadID}.json", + req = $.ajax "#{location.protocol}//a.4cdn.org/#{boardID}/thread/#{threadID}.json", onloadend: -> ThreadWatcher.parseStatus.call @, thread timeout: $.MINUTE diff --git a/src/classes/DataBoard.coffee b/src/classes/DataBoard.coffee index 8bcd7a3bb..7c89a4a8d 100644 --- a/src/classes/DataBoard.coffee +++ b/src/classes/DataBoard.coffee @@ -91,9 +91,9 @@ class DataBoard return ajaxClean: (boardID) -> - $.cache "//a.4cdn.org/#{boardID}/threads.json", (e1) => + $.cache "#{location.protocol}//a.4cdn.org/#{boardID}/threads.json", (e1) => return unless e1.target.status in [200, 404] - $.cache "//a.4cdn.org/#{boardID}/archive.json", (e2) => + $.cache "#{location.protocol}//a.4cdn.org/#{boardID}/archive.json", (e2) => return unless e2.target.status in [200, 404] @ajaxCleanParse boardID, e1.target.response, e2.target.response diff --git a/src/classes/Fetcher.coffee b/src/classes/Fetcher.coffee index f67adf4b2..81f5e15a0 100644 --- a/src/classes/Fetcher.coffee +++ b/src/classes/Fetcher.coffee @@ -16,7 +16,7 @@ class Fetcher @root.textContent = "Loading post No.#{@postID}..." if @threadID - $.cache "//a.4cdn.org/#{@boardID}/thread/#{@threadID}.json", (e, isCached) => + $.cache "#{location.protocol}//a.4cdn.org/#{@boardID}/thread/#{@threadID}.json", (e, isCached) => @fetchedPost e.target, isCached else @archivedPost() @@ -79,7 +79,7 @@ class Fetcher if post.no isnt @postID # Cached requests can be stale and must be rechecked. if isCached - api = "//a.4cdn.org/#{@boardID}/thread/#{@threadID}.json" + api = "#{location.protocol}//a.4cdn.org/#{@boardID}/thread/#{@threadID}.json" $.cleanCache (url) -> url is api $.cache api, (e) => @fetchedPost e.target, false diff --git a/src/main/Main.coffee b/src/main/Main.coffee index ca6a1eb04..10eec3ece 100644 --- a/src/main/Main.coffee +++ b/src/main/Main.coffee @@ -315,7 +315,7 @@ Main = threads[0].ipCount = if m = scriptData.match /\bunique_ips *= *(\d+)\b/ then +m[1] if g.BOARD.ID is 'f' and g.VIEW is 'thread' - $.ajax "//a.4cdn.org/f/thread/#{g.THREADID}.json", + $.ajax "#{location.protocol}//a.4cdn.org/f/thread/#{g.THREADID}.json", timeout: $.MINUTE onloadend: -> if @response and posts[0].file From e6bd2d9cb2d75fa7f714ae89e9ab33598f35a385 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Fri, 29 Sep 2017 03:16:10 -0700 Subject: [PATCH 3/5] Use page XHR for Firefox WE, and list host permissions explicitly. --- src/meta/jshint.json | 1 + src/meta/manifest.json | 4 +--- src/platform/$.coffee | 10 +++++++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/meta/jshint.json b/src/meta/jshint.json index 45f62a3eb..1b58dc59c 100644 --- a/src/meta/jshint.json +++ b/src/meta/jshint.json @@ -20,6 +20,7 @@ "BroadcastChannel": false, "GM_info": false, "cloneInto": false, + "XPCNativeWrapper": false, "unsafeWindow": false, "chrome": false, "GM": false<%= diff --git a/src/meta/manifest.json b/src/meta/manifest.json index 5ae8a594c..dec9c0068 100644 --- a/src/meta/manifest.json +++ b/src/meta/manifest.json @@ -23,9 +23,7 @@ <% if (channel !== '-noupdate') { %> "update_url": "<%= meta.downloads %>updates<%= channel %>.xml", "key": "<%= meta.appid %>", <% } %> "minimum_chrome_version": "<%= meta.min.chrome %>", - "permissions": [ - "storage" - ], + "permissions": <%= JSON.stringify(meta.matches_only.concat(["storage"])) %>, "optional_permissions": [ "*://*/" ], diff --git a/src/platform/$.coffee b/src/platform/$.coffee index abc9c3c65..a989a8fda 100644 --- a/src/platform/$.coffee +++ b/src/platform/$.coffee @@ -45,6 +45,10 @@ $.ajax = do -> # With the `If-Modified-Since` header we only receive the HTTP headers and no body for 304 responses. # This saves a lot of bandwidth and CPU time for both the users and the servers. lastModified = {} + <% if (type === 'crx') { %> + if XPCNativeWrapper? + pageXHR = XPCNativeWrapper window.wrappedJSObject.XMLHttpRequest + <% } %> (url, options={}, extra={}) -> {type, whenModified, upCallbacks, form} = extra @@ -53,7 +57,11 @@ $.ajax = do -> url = url.replace /^((?:https?:)?\/\/(?:\w+\.)?4c(?:ha|d)n\.org)\/adv\//, '$1//adv/' # XXX https://bugs.chromium.org/p/chromium/issues/detail?id=643659 url += "?s=#{whenModified}" if $.engine is 'blink' and whenModified - r = new XMLHttpRequest() + xhr = XMLHttpRequest + <% if (type === 'crx') { %> + xhr = pageXHR or xhr + <% } %> + r = new xhr() type or= form and 'post' or 'get' try r.open type, url, true From fe6a4e595881cae6a0823af9189b6bba9be9ac3c Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sun, 8 Oct 2017 03:02:38 -0700 Subject: [PATCH 4/5] Work around performance issue with chrome.storage.sync in Firefox. --- src/platform/$.coffee | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/platform/$.coffee b/src/platform/$.coffee index a989a8fda..871a82747 100644 --- a/src/platform/$.coffee +++ b/src/platform/$.coffee @@ -421,9 +421,17 @@ $.get = $.oneItemSugar (data, cb) -> return unless $.crxWorking() results = {} get = (area) -> - chrome.storage[area].get Object.keys(data), (result) -> + keys = Object.keys data + # XXX slow performance in Firefox + if $.engine is 'gecko' and area is 'sync' and keys.length > 3 + keys = null + chrome.storage[area].get keys, (result) -> if chrome.runtime.lastError c.error chrome.runtime.lastError.message + if keys is null + result2 = {} + result2[key] = val for key, val of result when key of data + result = result2 for key of data $.oldValue[area][key] = result[key] results[area] = result From 1be0f1e0d42aab2e6af083e91d81ce18a9ac1211 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sun, 8 Oct 2017 16:57:38 -0700 Subject: [PATCH 5/5] Add update manifest for Firefox WebExtension. --- Makefile | 7 +++++-- src/meta/manifest.json | 5 +++-- src/meta/updates.json | 12 ++++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 src/meta/updates.json diff --git a/Makefile b/Makefile index 0bb797c6c..b2152c72e 100644 --- a/Makefile +++ b/Makefile @@ -87,7 +87,7 @@ crx_contents := script.js eventPage.js icon16.png icon48.png icon128.png manifes release := \ $(foreach f, \ - $(foreach c,. -beta.,$(name)$(c)crx updates$(c)xml $(name)$(c)user.js $(name)$(c)meta.js) \ + $(foreach c,. -beta.,$(name)$(c)crx updates$(c)xml updates$(c)json $(name)$(c)user.js $(name)$(c)meta.js) \ $(name)-noupdate.crx \ $(name)-noupdate.user.js \ $(name).zip \ @@ -184,6 +184,9 @@ testbuilds/crx$1/manifest.json : src/meta/manifest.json version.json $(template_ testbuilds/updates$1.xml : src/meta/updates.xml version.json $(template_deps) | testbuilds/crx$1 $(template) $$< $$@ type=crx channel=$1 +testbuilds/updates$1.json : src/meta/updates.json version.json $(template_deps) | testbuilds/crx$1 + $(template) $$< $$@ type=crx channel=$1 + testbuilds/$(name)$1.crx.zip : \ $(foreach f,$(crx_contents),testbuilds/crx$1/$(f)) \ package.json version.json tools/zip-crx.js node_modules/jszip/package.json @@ -342,7 +345,7 @@ stable : distready git push . HEAD:bstable git tag -af stable -m "$(meta_name) v$(version)." cd dist && git merge --no-commit -s ours stable - cd dist && git checkout stable "builds/$(name).*" builds/updates.xml + cd dist && git checkout stable "builds/$(name).*" builds/updates.xml builds/updates.json cd dist && git commit -am "Move $(meta_name) v$(version) to stable channel." web : index.html distready diff --git a/src/meta/manifest.json b/src/meta/manifest.json index dec9c0068..8438753bb 100644 --- a/src/meta/manifest.json +++ b/src/meta/manifest.json @@ -29,7 +29,8 @@ ], "applications": { "gecko": { - "id": "<%= meta.appidGecko %>" - } + "id": "<%= meta.appidGecko %>"<% if (channel !== '-noupdate') { %>, + "update_url": "<%= meta.downloads %>updates<%= channel %>.json" +<% } %> } } } diff --git a/src/meta/updates.json b/src/meta/updates.json new file mode 100644 index 000000000..dc9d876f6 --- /dev/null +++ b/src/meta/updates.json @@ -0,0 +1,12 @@ +{ + "addons": { + "<%= meta.appidGecko %>": { + "updates": [ + { + "version": "<%= readJSON('/version.json').version %>", + "update_link": "<%= meta.downloads %><%= name %><%= channel %>.crx" + } + ] + } + } +}