Skip to content

Commit

Permalink
Help out decaffeinate. #829
Browse files Browse the repository at this point in the history
  • Loading branch information
ccd0 committed Oct 1, 2016
1 parent 6a16010 commit ad9c3df
Show file tree
Hide file tree
Showing 52 changed files with 152 additions and 131 deletions.
2 changes: 1 addition & 1 deletion src/Archive/Redirect.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ Redirect =
if type is 'capcode'
value = {'Developer': 'dev'}[value] or value.toLowerCase()
else if type is 'image'
value = value.replace /[+/=]/g, (c) -> {'+': '-', '/': '_', '=': ''}[c]
value = value.replace /[+/=]/g, (c) -> ({'+': '-', '/': '_', '=': ''})[c]
value = encodeURIComponent value
path = if archive.software is 'foolfuuka'
"#{boardID}/search/#{type}/#{value}/"
Expand Down
2 changes: 1 addition & 1 deletion src/Filtering/Filter.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Filter =
for line in Conf[key].split '\n'
continue if line[0] is '#'

unless regexp = line.match /\/(.+)\/(\w*)/
if not (regexp = line.match /\/(.+)\/(\w*)/)
continue

# Don't mix up filter flags with the regular expression.
Expand Down
4 changes: 2 additions & 2 deletions src/Filtering/PostHiding.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ PostHiding =
open: (post) ->
if !post.isReply or post.isClone or !post.isHidden
return false
unless data = PostHiding.db.get {boardID: post.board.ID, threadID: post.thread.ID, postID: post.ID}
if not (data = PostHiding.db.get {boardID: post.board.ID, threadID: post.thread.ID, postID: post.ID})
return false
PostHiding.menu.post = post
thisPost.firstChild.checked = post.isHidden
Expand All @@ -104,7 +104,7 @@ PostHiding =
open: (post) ->
if !post.isReply or post.isClone or !post.isHidden
return false
unless data = PostHiding.db.get {boardID: post.board.ID, threadID: post.thread.ID, postID: post.ID}
if not (data = PostHiding.db.get {boardID: post.board.ID, threadID: post.thread.ID, postID: post.ID})
return false
PostHiding.menu.post = post

Expand Down
5 changes: 3 additions & 2 deletions src/Filtering/Recursive.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ Recursive =
return

add: (recursive, post, args...) ->
obj = Recursive.recursives[post.fullID] or=
obj = Recursive.recursives[post.fullID] or= {
recursives: []
args: []
}
obj.recursives.push recursive
obj.args.push args

rm: (recursive, post) ->
return unless obj = Recursive.recursives[post.fullID]
return if not (obj = Recursive.recursives[post.fullID])
for rec, i in obj.recursives when rec is recursive
obj.recursives.splice i, 1
obj.args.splice i, 1
Expand Down
5 changes: 3 additions & 2 deletions src/Filtering/ThreadHiding.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ ThreadHiding =
@hiddenThreads = JSON.parse(localStorage.getItem "4chan-hide-t-#{g.BOARD}") or {}
Main.ready ->
# 4chan's catalog sets the style to "display: none;" when hiding or unhiding a thread.
new MutationObserver(ThreadHiding.catalogSave).observe $.id('threads'),
new MutationObserver(ThreadHiding.catalogSave).observe $.id('threads'), {
attributes: true
subtree: true
attributeFilter: ['style']
}

catalogSave: ->
hiddenThreads2 = JSON.parse(localStorage.getItem "4chan-hide-t-#{g.BOARD}") or {}
Expand Down Expand Up @@ -78,7 +79,7 @@ ThreadHiding =
return false
ThreadHiding.menu.thread = thread
true
subEntries: [el: apply; el: makeStub]
subEntries: [{el: apply}, {el: makeStub}]

div = $.el 'a',
className: 'show-thread-link'
Expand Down
2 changes: 1 addition & 1 deletion src/General/Build.Test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Build.Test =
testAll: ->
g.posts.forEach (post) ->
unless post.isClone or post.isFetchedQuote
unless (abbr = $ '.abbr', post.nodes.comment) and /Comment too long\./.test(abbr.textContent)
if not ((abbr = $ '.abbr', post.nodes.comment) and /Comment too long\./.test(abbr.textContent))
Build.Test.testOne post
return

Expand Down
6 changes: 3 additions & 3 deletions src/General/Build.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Build =
unescape: (text) ->
return text unless text?
text.replace(/<[^>]*>/g, '').replace /&(amp|#039|quot|lt|gt|#44);/g, (c) ->
{'&amp;': '&', '&#039;': "'", '&quot;': '"', '&lt;': '<', '&gt;': '>', '&#44;': ','}[c]
(({'&amp;': '&', '&#039;': "'", '&quot;': '"', '&lt;': '<', '&gt;': '>', '&#44;': ','})[c])

shortFilename: (filename) ->
ext = filename.match(/\.?[^\.]*$/)[0]
Expand Down Expand Up @@ -149,7 +149,7 @@ Build =
for quote in $$ '.quotelink', container
href = quote.getAttribute 'href'
if (href[0] is '#') and !(Build.sameThread boardID, threadID)
quote.href = "/#{boardID}/thread/#{threadID}" + href
quote.href = ("/#{boardID}/thread/#{threadID}") + href
else if (match = href.match /^\/([^\/]+)\/thread\/(\d+)/) and (Build.sameThread match[1], match[2])
quote.href = href.match(/(#[^#]*)?$/)[0] or '#'
else if /^\d+(#|$)/.test(href) and not (g.VIEW is 'thread' and g.BOARD.ID is boardID) # used on /f/
Expand Down Expand Up @@ -199,7 +199,7 @@ Build =
src = "#{staticPath}spoiler"
if spoilerRange = Build.spoilerRange[thread.board]
# Randomize the spoiler image.
src += "-#{thread.board}" + Math.floor 1 + spoilerRange * Math.random()
src += ("-#{thread.board}") + Math.floor 1 + spoilerRange * Math.random()
src += '.png'
imgClass = 'spoiler-file'
else if data.filedeleted
Expand Down
2 changes: 1 addition & 1 deletion src/General/Get.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Get =
threadExcerpt: (thread) ->
{OP} = thread
excerpt = "/#{thread.board}/ - " + (
excerpt = ("/#{thread.board}/ - ") + (
OP.info.subject?.trim() or
OP.info.commentDisplay.replace(/\n+/g, ' // ') or
OP.file?.name or
Expand Down
2 changes: 1 addition & 1 deletion src/General/Header.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ Header =
a.textContent = if /-title/.test(t) or /-replace/.test(t) and boardID is g.BOARD.ID
a.title or a.textContent
else if /-full/.test t
"/#{boardID}/" + (if a.title then " - #{a.title}" else '')
("/#{boardID}/") + (if a.title then " - #{a.title}" else '')
else
text or boardID

Expand Down
15 changes: 8 additions & 7 deletions src/General/Index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ Index =
Conf['Index Mode'] = history.state?.mode
@currentSort = history.state?.sort
@currentSort or=
if typeof Conf['Index Sort'] is 'object'
if typeof Conf['Index Sort'] is 'object' then (
Conf['Index Sort'][g.BOARD.ID] or 'bump'
else
) else (
Conf['Index Sort']
)
@currentPage = @getCurrentPage()
@processHash()

Expand Down Expand Up @@ -594,7 +595,7 @@ Index =
if Index.liveThreadData[0]
Build.spoilerRange[g.BOARD.ID] = Index.liveThreadData[0].custom_spoiler
g.BOARD.threads.forEach (thread) ->
thread.collect() unless thread.ID in Index.liveThreadIDs
(thread.collect() unless thread.ID in Index.liveThreadIDs)
return

buildThreads: ->
Expand All @@ -616,7 +617,7 @@ Index =
thread = new Thread threadData.no, g.BOARD
threads.push thread

unless (OP = thread.OP) and not OP.isFetchedQuote
if not ((OP = thread.OP) and not OP.isFetchedQuote)
OP = new Post Build.postFromObject(threadData, g.BOARD.ID, true), thread, g.BOARD
posts.push OP
thread.setPage i // Index.threadsNumPerPage + 1
Expand All @@ -638,7 +639,7 @@ Index =
buildReplies: (threads) ->
posts = []
for thread in threads
continue unless (lastReplies = Index.liveThreadDict[thread.ID].last_replies)
continue if not (lastReplies = Index.liveThreadDict[thread.ID].last_replies)
nodes = []
for data in lastReplies
if (post = thread.posts[data.no]) and not post.isFetchedQuote
Expand Down Expand Up @@ -681,7 +682,7 @@ Index =
buildCatalogReplies: (threads) ->
for thread in threads
{nodes} = thread.catalogView
continue unless (lastReplies = Index.liveThreadDict[thread.ID].last_replies)
continue if not (lastReplies = Index.liveThreadDict[thread.ID].last_replies)

if nodes.replies
# RelativeDates will stop updating elements if they go out of document.
Expand Down Expand Up @@ -816,7 +817,7 @@ Index =
Index.pageLoad false

querySearch: (query) ->
return unless keywords = query.toLowerCase().match /\S+/g
return if not (keywords = query.toLowerCase().match /\S+/g)
Index.sortedThreads.filter (thread) ->
Index.searchMatch thread, keywords

Expand Down
23 changes: 13 additions & 10 deletions src/General/Settings.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,15 @@ Settings =
if $.hasStorage
for boardID of hiddenThreads.boards
localStorage.removeItem "4chan-hide-t-#{boardID}"
$.delete ['hiddenThreads', 'hiddenPosts']
($.delete ['hiddenThreads', 'hiddenPosts'])
$.after $('input[name="Stubs"]', section).parentNode.parentNode, div

export: ->
# Make sure to export the most recent data.
$.get Conf, (Conf) ->
# Don't export cached JSON data.
delete Conf['boardConfig']
Settings.downloadExport {version: g.VERSION, date: Date.now(), Conf}
(Settings.downloadExport {version: g.VERSION, date: Date.now(), Conf})

downloadExport: (data) ->
a = $.el 'a',
Expand All @@ -206,7 +206,7 @@ Settings =
$('input[type=file]', @parentNode).click()

onImport: ->
return unless file = @files[0]
return if not (file = @files[0])
@value = null
output = $('.imp-exp-result')
unless confirm 'Your current settings will be entirely overwritten, are you sure?'
Expand Down Expand Up @@ -437,7 +437,7 @@ Settings =
className: 'field'
spellcheck: false
$.get name, Conf[name], (item) ->
ta.value = item[name]
(ta.value = item[name])
$.on ta, 'change', $.cb.value
$.add div, ta
return
Expand All @@ -449,7 +449,7 @@ Settings =
$('.warning', section).hidden = Conf['Sauce']
ta = $ 'textarea', section
$.get 'sauces', Conf['sauces'], (item) ->
ta.value = item['sauces']
(ta.value = item['sauces'])
$.on ta, 'change', $.cb.value

advanced: (section) ->
Expand Down Expand Up @@ -530,10 +530,11 @@ Settings =
for {uid, name, boards, files, software} in Conf['archives']
continue unless software in ['fuuka', 'foolfuuka']
for boardID in boards
o = archBoards[boardID] or=
o = archBoards[boardID] or= {
thread: []
post: []
file: []
}
archive = [uid ? name, name]
o.thread.push archive
o.post.push archive if software is 'foolfuuka'
Expand All @@ -546,10 +547,11 @@ Settings =
className: "board-#{boardID}"
row.hidden = boardID isnt g.BOARD.ID

boardOptions.push $.el 'option',
boardOptions.push $.el 'option', {
textContent: "/#{boardID}/"
value: "board-#{boardID}"
selected: boardID is g.BOARD.ID
}

o = archBoards[boardID]
$.add row, Settings.addArchiveCell boardID, o, item for item in ['thread', 'post', 'file']
Expand Down Expand Up @@ -587,13 +589,14 @@ Settings =
i = 0
while i < length
archive = data[type][i++]
options.push $.el 'option',
options.push $.el 'option', {
value: JSON.stringify archive[0]
textContent: archive[1]
}

$.extend td, <%= html('<select></select>') %>
select = td.firstElementChild
unless select.disabled = length is 1
if not (select.disabled = length is 1)
# XXX GM can't into datasets
select.setAttribute 'data-boardid', boardID
select.setAttribute 'data-type', type
Expand All @@ -616,7 +619,7 @@ Settings =
@nextElementSibling.textContent = Time.format @value, new Date()

backlink: ->
@nextElementSibling.textContent = @value.replace /%(?:id|%)/g, (x) -> {'%id': '123456789', '%%': '%'}[x]
@nextElementSibling.textContent = @value.replace /%(?:id|%)/g, (x) -> ({'%id': '123456789', '%%': '%'})[x]

fileInfo: ->
data =
Expand Down
6 changes: 3 additions & 3 deletions src/General/UI.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ dialog = (id, position, properties) ->
$.extend el, properties
el.style.cssText = position
$.get "#{id}.position", position, (item) ->
el.style.cssText = item["#{id}.position"]
(el.style.cssText = item["#{id}.position"])

move = $ '.move', el
$.on move, 'touchstart mousedown', dragstart
Expand Down Expand Up @@ -153,7 +153,7 @@ class Menu
if next = @findNextEntry entry, +1
@focus next
when 39 # Right
if (submenu = $ '.submenu', entry) and next = submenu.firstElementChild
if (submenu = $ '.submenu', entry) and (next = submenu.firstElementChild)
while nextPrev = @findNextEntry next, -1
next = nextPrev
@focus next
Expand All @@ -178,7 +178,7 @@ class Menu
$.addClass entry, 'focused'

# Submenu positioning.
return unless submenu = $ '.submenu', entry
return if not (submenu = $ '.submenu', entry)
sRect = submenu.getBoundingClientRect()
eRect = entry.getBoundingClientRect()
cHeight = doc.clientHeight
Expand Down
6 changes: 3 additions & 3 deletions src/Images/Gallery.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gallery =
init: ->
return unless @enabled = Conf['Gallery'] and g.VIEW in ['index', 'thread'] and g.BOARD.ID isnt 'f'
return if not (@enabled = Conf['Gallery'] and g.VIEW in ['index', 'thread'] and g.BOARD.ID isnt 'f')

@delay = Conf['Slide Delay']

Expand Down Expand Up @@ -202,7 +202,7 @@ Gallery =
ImageCommon.error @, g.posts[@dataset.post], null, (url) =>
return unless url
Gallery.images[@dataset.id].href = url
@src = url if Gallery.nodes.current is @
(@src = url if Gallery.nodes.current is @)

cacheError: ->
delete Gallery.cache
Expand Down Expand Up @@ -236,7 +236,7 @@ Gallery =

cb:
keybinds: (e) ->
return unless key = Keybinds.keyCode e
return if not (key = Keybinds.keyCode e)

cb = switch key
when Conf['Close'], Conf['Open Gallery']
Expand Down
5 changes: 3 additions & 2 deletions src/Images/ImageCommon.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,18 @@ ImageCommon =

decodeError: (file, post) ->
return false unless file.error?.code is MediaError.MEDIA_ERR_DECODE
unless message = $ '.warning', post.file.thumb.parentNode
if not (message = $ '.warning', post.file.thumb.parentNode)
message = $.el 'div', className: 'warning'
$.after post.file.thumb, message
message.textContent = 'Error: Corrupt or unplayable video'
return true

error: (file, post, delay, cb) ->
src = post.file.url.split '/'
URL = Redirect.to 'file',
URL = Redirect.to 'file', {
boardID: post.board.ID
filename: src[src.length - 1]
}
unless Conf['404 Redirect'] and URL and Redirect.securityCheck URL
URL = null

Expand Down
4 changes: 2 additions & 2 deletions src/Images/ImageExpand.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ImageExpand =
init: ->
return unless @enabled = Conf['Image Expansion'] and g.VIEW in ['index', 'thread'] and g.BOARD.ID isnt 'f'
return if not (@enabled = Conf['Image Expansion'] and g.VIEW in ['index', 'thread'] and g.BOARD.ID isnt 'f')

@EAI = $.el 'a',
className: 'expand-all-shortcut fa fa-expand'
Expand Down Expand Up @@ -273,7 +273,7 @@ ImageExpand =
ImageCommon.error @, post, 10 * $.SECOND, (URL) ->
if post.file.isExpanding or post.file.isExpanded
ImageExpand.contract post
ImageExpand.expand post, URL if URL
(ImageExpand.expand post, URL if URL)

menu:
init: ->
Expand Down
Loading

0 comments on commit ad9c3df

Please sign in to comment.