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 Sep 30, 2016
1 parent 6a16010 commit 9d5d05a
Show file tree
Hide file tree
Showing 42 changed files with 92 additions and 77 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
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
6 changes: 3 additions & 3 deletions src/General/Index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,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 +681,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 +816,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
13 changes: 8 additions & 5 deletions src/General/Settings.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -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 Down
4 changes: 2 additions & 2 deletions src/General/UI.coffee
Original file line number Diff line number Diff line change
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
4 changes: 2 additions & 2 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 @@ -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
2 changes: 1 addition & 1 deletion 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
4 changes: 2 additions & 2 deletions src/Images/Sauce.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Sauce =
cb: @node

createSauceLink: (link, post) ->
return null unless link = link.trim()
return null if not (link = link.trim())

parts = {}
for part, i in link.split /;(?=(?:text|boards|types|sandbox):?)/
Expand Down Expand Up @@ -60,7 +60,7 @@ Sauce =
nodes = []
skipped = []
for link in Sauce.links
unless (node = Sauce.createSauceLink link, @)
if not (node = Sauce.createSauceLink link, @)
node = Sauce.link.cloneNode false
skipped.push [link, node]
nodes.push $.tn(' '), node
Expand Down
2 changes: 1 addition & 1 deletion src/Images/Volume.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Volume =

wheel: (e) ->
return if e.shiftKey or e.altKey or e.ctrlKey or e.metaKey
return unless el = $ 'video:not([data-md5])', @
return if not (el = $ 'video:not([data-md5])', @)
return if el.muted or not $.hasAudio el
volume = el.volume + 0.1
volume *= 1.1 if e.deltaY < 0
Expand Down
4 changes: 2 additions & 2 deletions src/Linkification/Embedding.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Embedding =

title: (data) ->
{key, uid, options, link, post} = data
return unless service = Embedding.types[key].title
return if not (service = Embedding.types[key].title)
$.addClass link, key.toLowerCase()
if service.batchSize
(service.queue or= []).push data
Expand All @@ -117,7 +117,7 @@ Embedding =
click: (e) ->
e.preventDefault()
if Conf['Floating Embeds'] or $.hasClass(doc, 'catalog-mode')
return unless div = Embedding.media.firstChild
return if not (div = Embedding.media.firstChild)
$.replace div, Embedding.cb.embed @
Embedding.lastEmbed = Get.postFromNode(@).nodes.root
$.rmClass Embedding.dialog, 'empty'
Expand Down
2 changes: 1 addition & 1 deletion src/Miscellaneous/ExpandComment.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ExpandComment =
$.replace post.nodes.shortComment, post.nodes.longComment
post.nodes.comment = post.nodes.longComment
return
return unless a = $ '.abbr > a', post.nodes.comment
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

Expand Down
6 changes: 3 additions & 3 deletions src/Miscellaneous/ExpandThread.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ExpandThread =
statuses: {}
init: ->
return unless g.VIEW is 'index' and Conf['Thread Expansion']
return if not (g.VIEW is 'index' and Conf['Thread Expansion'])
if Conf['JSON Index']
$.on d, 'IndexRefreshInternal', @onIndexRefresh
else
Expand All @@ -10,7 +10,7 @@ ExpandThread =
cb: -> ExpandThread.setButton @

setButton: (thread) ->
return unless thread.nodes.root and (a = $ '.summary', thread.nodes.root)
return if not (thread.nodes.root and (a = $ '.summary', thread.nodes.root))
a.textContent = Build.summaryText '+', a.textContent.match(/\d+/g)...
a.style.cursor = 'pointer'
$.on a, 'click', ExpandThread.cbToggle
Expand All @@ -35,7 +35,7 @@ ExpandThread =

toggle: (thread) ->
threadRoot = thread.nodes.root
return unless a = $ '.summary', threadRoot
return if not (a = $ '.summary', threadRoot)
if thread.ID of ExpandThread.statuses
ExpandThread.contract thread, a, threadRoot
else
Expand Down
4 changes: 2 additions & 2 deletions src/Miscellaneous/Fourchan.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Fourchan =

if g.BOARD.ID is 'g'
$.on window, 'prettyprint:cb', (e) ->
return unless post = g.posts[e.detail.ID]
return unless pre = $$('.prettyprint', post.nodes.comment)[e.detail.i]
return if not (post = g.posts[e.detail.ID])
return if not (pre = $$('.prettyprint', post.nodes.comment)[e.detail.i])
unless $.hasClass pre, 'prettyprinted'
pre.innerHTML = e.detail.html
$.addClass pre, 'prettyprinted'
Expand Down
6 changes: 3 additions & 3 deletions src/Miscellaneous/Keybinds.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Keybinds =
Conf[hotkey] = key

keydown: (e) ->
return unless key = Keybinds.keyCode e
return if not (key = Keybinds.keyCode e)
{target} = e
if target.nodeName in ['INPUT', 'TEXTAREA']
return unless /(Esc|Alt|Ctrl|Meta|Shift\+\w{2,})/.test(key) and not /^Alt\+(\d|Up|Down|Left|Right)$/.test(key)
Expand Down Expand Up @@ -272,7 +272,7 @@ Keybinds =
value[selEnd..]

# Move the caret to the end of the selection.
range = "[#{tag}]".length + selEnd
range = ("[#{tag}]").length + selEnd
ta.setSelectionRange range, range

# Fire the 'input' event
Expand Down Expand Up @@ -314,7 +314,7 @@ Keybinds =
'following'
else
'preceding'
return unless next = $.x "#{axis}-sibling::div[contains(@class,'replyContainer') and not(@hidden) and not(child::div[@class='stub'])][1]/child::div[contains(@class,'reply')]", root
return if not (next = $.x "#{axis}-sibling::div[contains(@class,'replyContainer') and not(@hidden) and not(child::div[@class='stub'])][1]/child::div[contains(@class,'reply')]", root)
Header.scrollToIfNeeded next, delta is +1
@focus next
$.rmClass postEl, 'highlight'
Expand Down
2 changes: 1 addition & 1 deletion src/Miscellaneous/PSAHiding.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ PSAHiding =
$.one d, '4chanXInitFinished', @setup

setup: ->
unless psa = PSAHiding.psa = $.id 'globalMessage'
if not (psa = PSAHiding.psa = $.id 'globalMessage')
$.rmClass doc, 'hide-announcement'
return
if (hr = $.id('globalToggle')?.previousElementSibling) and hr.nodeName is 'HR'
Expand Down
4 changes: 2 additions & 2 deletions src/Miscellaneous/Report.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Report =
init: ->
return unless (match = location.search.match /\bno=(\d+)/)
return if not (match = location.search.match /\bno=(\d+)/)
Captcha.replace.init()
@postID = +match[1]
$.ready @ready
Expand All @@ -20,6 +20,6 @@ Report =
Report.fit 'body'

fit: (selector) ->
return unless (el = $ selector, doc) and getComputedStyle(el).visibility isnt 'hidden'
return if not ((el = $ selector, doc) and getComputedStyle(el).visibility isnt 'hidden')
dy = el.getBoundingClientRect().bottom - doc.clientHeight + 8
window.resizeBy 0, dy if dy > 0
2 changes: 1 addition & 1 deletion src/Monitoring/Favicon.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Favicon =
init: ->
$.asap (-> d.head and Favicon.el = $ 'link[rel="shortcut icon"]', d.head), Favicon.initAsap
$.asap (-> d.head and (Favicon.el = $ 'link[rel="shortcut icon"]', d.head)), Favicon.initAsap

initAsap: ->
Favicon.el.type = 'image/x-icon'
Expand Down
Loading

0 comments on commit 9d5d05a

Please sign in to comment.