Merge Zixaphir X

This commit is contained in:
seaweedchan 2013-08-25 01:15:47 -07:00
commit 6598b5a45e
13 changed files with 640 additions and 291 deletions

View File

@ -1,5 +1,5 @@
/*
* 4chan X - Version 1.2.35 - 2013-08-24
* 4chan X - Version 1.2.35 - 2013-08-25
*
* Licensed under the MIT license.
* https://github.com/seaweedchan/4chan-x/blob/master/LICENSE

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -179,6 +179,10 @@ Config =
false
'Hide posts without images. *hint* *hint*'
]
'Werk Tyme': [
false
'Hide all post images.'
]
'Menu':
'Menu': [
@ -313,6 +317,7 @@ Config =
true
'When disabled, shows a red border on the CAPTCHA input until a key is pressed instead of a notification.'
]
'Quote Links':
'Quote Backlinks': [
true
@ -396,6 +401,18 @@ Config =
false
'Advance to next post when contracting an expanded image.'
]
gallery:
# Gallery mostly gets its config from imageExpansion
'Hide thumbnails': [
false
]
'Gallery fit width': [
true
]
'Gallery fit height': [
true
]
threadWatcher:
'Current Board': [
@ -598,10 +615,18 @@ q-replace
'e'
'Expand all images.'
]
'Open Gallery': [
'g'
'Opens the gallery.'
]
'fappeTyme': [
'f'
'Fappe Tyme.'
]
'werkTyme': [
'Shift+w'
'Werk Tyme'
]
# Board Navigation
'Front page': [
'0'

View File

@ -54,6 +54,10 @@ a[href="javascript:;"] {
a {
outline: none !important;
}
.painted {
border-radius: 3px;
padding: 0px 2px;
}
/* 4chan style fixes */
.opContainer, .op {
@ -1097,7 +1101,6 @@ a:only-of-type > .remove {
<%= align %>-items: stretch;
<%= flex %>-direction: row;
<%= flex %>: 1 1 auto;
position: relative;
}
.gal-thumbnails {
<%= flex %>: 0 0 150px;
@ -1107,14 +1110,18 @@ a:only-of-type > .remove {
<%= align %>-items: stretch;
text-align: center;
background: rgba(0,0,0,.5);
border-left: 1px solid #222;
}
.gal-thumbnails img {
.hide-thumbnails .gal-thumbnails {
display: none;
}
.gal-thumb img {
max-width: 125px;
max-height: 125px;
height: auto;
width: auto;
}
.gal-thumbnails a {
.gal-thumb {
<%= flex %>: 0 0 auto;
padding: 3px;
line-height: 0;
@ -1125,6 +1132,7 @@ a:only-of-type > .remove {
}
.gal-prev {
order: 0;
border-right: 1px solid #222;
}
.gal-next {
order: 2;
@ -1135,7 +1143,6 @@ a:only-of-type > .remove {
<%= flex %>: 0 0 20px;
position: relative;
cursor: pointer;
border-right: 1px solid #222;
opacity: 0.7;
background-color: rgba(0, 0, 0, 0.3);
}
@ -1167,30 +1174,46 @@ a:only-of-type > .remove {
display: <%= flex %>;
<%= align %>-items: flex-start;
<%= justify %>: space-around;
overflow: hidden;
overflow: auto;
/* Flex > Non-Flex child max-width and overflow fix (Firefox only?) */
width: 1%;
}
.gal-image a {
margin: auto;
line-height: 0;
}
.gal-image img {
.fit-width .gal-image img {
max-width: 100%;
max-height: 100vh;
}
.gal-close {
.fit-height .gal-image img {
max-height: calc(100vh - 25px);
}
.gal-buttons {
font-size: 2em;
padding-right: 8px;
position: fixed;
margin-right: 10px;
top: 5px;
right: 180px;
color: #ffffff;
text-shadow: 0px 0px 1px #000000;
}
.gal-name {
.gal-buttons i {
vertical-align: baseline;
border-top-width: .5em;
border-right-width: .3em;
border-left-width: .3em;
}
.gal-buttons,
.gal-name,
.gal-count {
position: fixed;
bottom: 5px;
right: 178px;
}
.hide-thumbnails .gal-buttons,
.hide-thumbnails .gal-count,
.hide-thumbnails .gal-name {
right: 28px;
}
.gal-name {
bottom: 5px;
background: rgba(0,0,0,0.6) !important;
border-radius: 3px;
padding: 1px 5px 2px 5px;
@ -1202,9 +1225,7 @@ a:only-of-type > .remove {
color: rgb(95, 95, 101) !important;
}
.gal-count {
position: fixed;
bottom: 26px;
right: 178px;
background: rgba(0,0,0,0.6) !important;
border-radius: 3px;
padding: 1px 5px 2px 5px;

View File

@ -74,18 +74,15 @@ class DataBoard
ajaxClean: (boardID) ->
$.cache "//api.4chan.org/#{boardID}/threads.json", (e) =>
if e.target.status is 404
# Deleted board.
@delete boardID
else if e.target.status is 200
board = @data.boards[boardID]
threads = {}
for page in JSON.parse e.target.response
for thread in page.threads
if thread.no of board
threads[thread.no] = board[thread.no]
@data.boards[boardID] = threads
@deleteIfEmpty {boardID}
return if e.target.status isnt 200
board = @data.boards[boardID]
threads = {}
for page in JSON.parse e.target.response
for thread in page.threads
if thread.no of board
threads[thread.no] = board[thread.no]
@data.boards[boardID] = threads
@deleteIfEmpty {boardID}
@save()
onSync: (data) =>

View File

@ -22,7 +22,7 @@ Polyfill =
# DataUrl to Binary code from Aeosynth's 4chan X repo
l = data.length
ui8a = new Uint8Array l
for i in [0...l]
for i in [0...l] by 1
ui8a[i] = data.charCodeAt i
cb new Blob [ui8a], type: 'image/png'
visibility: ->

View File

@ -1,18 +1,34 @@
FappeTyme =
init: ->
return if !Conf['Fappe Tyme'] or g.VIEW is 'catalog' or g.BOARD is 'f'
el = $.el 'label',
innerHTML: "<input type=checkbox name=fappe-tyme> Fappe Tyme"
title: 'Fappe Tyme'
FappeTyme.input = input = el.firstElementChild
return if !(Conf['Fappe Tyme'] or Conf['Werk Tyme']) or g.VIEW is 'catalog' or g.BOARD is 'f'
$.on input, 'change', FappeTyme.toggle
if Conf['Fappe Tyme']
el = $.el 'label',
innerHTML: "<input type=checkbox name=fappe-tyme> Fappe Tyme"
title: 'Fappe Tyme'
$.event 'AddMenuEntry',
type: 'header'
el: el
order: 97
FappeTyme.fappe = input = el.firstElementChild
$.on input, 'change', FappeTyme.cb.fappe
$.event 'AddMenuEntry',
type: 'header'
el: el
order: 97
if Conf['Werk Tyme']
el = $.el 'label',
innerHTML: "<input type=checkbox name=werk-tyme> Werk Tyme"
title: 'Werk Tyme'
FappeTyme.werk = input = el.firstElementChild
$.on input, 'change', FappeTyme.cb.werk
$.event 'AddMenuEntry',
type: 'header'
el: el
order: 98
Post::callbacks.push
name: 'Fappe Tyme'
@ -22,6 +38,10 @@ FappeTyme =
return if @file
$.addClass @nodes.root, "noFile"
toggle: ->
$.event 'CloseMenu'
(if @checked then $.addClass else $.rmClass) doc, 'fappeTyme'
cb:
fappe: ->
$.toggleClass doc, 'fappeTyme'
FappeTyme.fappe.checked = $.hasClass doc, 'fappeTyme'
werk: ->
$.toggleClass doc, 'werkTyme'
FappeTyme.werk.checked = $.hasClass doc, 'werkTyme'

View File

@ -1,7 +1,7 @@
Gallery =
init: ->
return if g.VIEW is 'catalog' or g.BOARD is 'f' or !Conf['Gallery']
el = $.el 'a',
href: 'javascript:;'
id: 'appchan-gal'
@ -19,19 +19,25 @@ Gallery =
node: ->
return unless @file?.isImage
if Gallery.el
if Gallery.nodes
Gallery.generateThumb $ '.file', @nodes.root
Gallery.total.textContent = Gallery.images.length
Gallery.nodes.total.textContent = Gallery.images.length
unless Conf['Image Expansion']
$.on @file.thumb.parentNode, 'click', Gallery.cb.image
build: (image) ->
Gallery.el = dialog = $.el 'div',
Gallery.images = []
nodes = Gallery.nodes = {}
nodes.el = dialog = $.el 'div',
id: 'a-gallery'
innerHTML: """
<div class=gal-viewport>
<a href=javascript:; class=gal-close>×</a>
<span class=gal-buttons>
<a class="menu-button" href="javascript:;"><i></i></a>
<a href=javascript:; class=gal-close>×</a>
</span>
<a class=gal-name target="_blank"></a>
<span class=gal-count><span class='count'></span> / <span class='total'></span></a></span>
<div class=gal-prev></div>
@ -42,7 +48,8 @@ Gallery =
</div>
<div class=gal-thumbnails></div>
"""
Gallery[key] = $ value, dialog for key, value of {
nodes[key] = $ value, dialog for key, value of {
frame: '.gal-image'
name: '.gal-name'
count: '.count'
@ -52,34 +59,49 @@ Gallery =
current: '.gal-image img'
}
Gallery.images = []
menuButton = $ '.menu-button', dialog
nodes.menu = new UI.Menu 'gallery'
$.on Gallery.frame, 'click', Gallery.cb.blank
$.on Gallery.current, 'click', Gallery.cb.download
$.on Gallery.next, 'click', Gallery.cb.next
$.on ($ '.gal-prev', dialog), 'click', Gallery.cb.prev
$.on ($ '.gal-next', dialog), 'click', Gallery.cb.next
$.on ($ '.gal-close', dialog), 'click', Gallery.cb.close
{cb} = Gallery
$.on nodes.frame, 'click', cb.blank
$.on nodes.current, 'click', cb.download
$.on nodes.next, 'click', cb.next
$.on ($ '.gal-prev', dialog), 'click', cb.prev
$.on ($ '.gal-next', dialog), 'click', cb.next
$.on ($ '.gal-close', dialog), 'click', cb.close
$.on d, 'keydown', Gallery.cb.keybinds
$.on menuButton, 'click', (e) ->
nodes.menu.toggle e, @, g
{createSubEntry} = Gallery.menu
for name in ['Gallery fit width', 'Gallery fit height', 'Hide thumbnails']
{el} = createSubEntry name
$.event 'AddMenuEntry',
type: 'gallery'
el: el
order: 0
$.on d, 'keydown', cb.keybinds
$.off d, 'keydown', Keybinds.keydown
i = 0
files = $$ '.post .file'
while file = files[i++]
continue if $ '.fileDeletedRes, .fileDeleted', file
Gallery.generateThumb file
$.add d.body, dialog
Gallery.thumbs.scrollTop = 0
Gallery.current.parentElement.scrollTop = 0
nodes.thumbs.scrollTop = 0
nodes.current.parentElement.scrollTop = 0
Gallery.cb.open.call if image
$ "[href='#{image.href.replace /https?:/, ''}']", Gallery.thumbs
$ "[href='#{image.href.replace /https?:/, ''}']", nodes.thumbs
else
Gallery.images[0]
d.body.style.overflow = 'hidden'
Gallery.total.textContent = --i
nodes.total.textContent = --i
generateThumb: (file) ->
title = ($ '.fileText a', file).textContent
@ -87,7 +109,7 @@ Gallery =
if double = $ 'img + img', thumb
$.rm double
thumb.className = 'a-thumb'
thumb.className = 'gal-thumb'
thumb.title = title
thumb.dataset.id = Gallery.images.length
thumb.firstElementChild.style.cssText = ''
@ -95,7 +117,7 @@ Gallery =
$.on thumb, 'click', Gallery.cb.open
Gallery.images.push thumb
$.add Gallery.thumbs, thumb
$.add Gallery.nodes.thumbs, thumb
cb:
keybinds: (e) ->
@ -113,38 +135,81 @@ Gallery =
e.stopPropagation()
e.preventDefault()
cb()
open: (e) ->
e.preventDefault() if e
return unless @
{nodes} = Gallery
{name} = nodes
$.rmClass el, 'gal-highlight' if el = $ '.gal-highlight', Gallery.thumbs
$.addClass @, 'gal-highlight'
img = $.el 'img',
src: Gallery.name.href = @href
title: Gallery.name.download = Gallery.name.textContent = @title
src: name.href = @href
title: name.download = name.textContent = @title
img.dataset.id = @dataset.id
$.replace Gallery.current, img
Gallery.count.textContent = +@dataset.id + 1
Gallery.current = img
Gallery.frame.scrollTop = 0
Gallery.current.focus()
$.replace nodes.current, img
nodes.count.textContent = +@dataset.id + 1
nodes.current = img
nodes.frame.scrollTop = 0
nodes.next.focus()
# Scroll
rect = @getBoundingClientRect()
{top} = rect
if top > 0
top += rect.height - doc.clientHeight
return if top < 0
nodes.thumbs.scrollTop += top
image: (e) ->
e.preventDefault()
e.stopPropagation()
Gallery.build @
prev: -> Gallery.cb.open.call Gallery.images[+Gallery.current.dataset.id - 1]
next: -> Gallery.cb.open.call Gallery.images[+Gallery.current.dataset.id + 1]
toggle: -> (if Gallery.el then Gallery.cb.close else Gallery.build)()
prev: -> Gallery.cb.open.call Gallery.images[+Gallery.nodes.current.dataset.id - 1]
next: -> Gallery.cb.open.call Gallery.images[+Gallery.nodes.current.dataset.id + 1]
toggle: -> (if Gallery.nodes then Gallery.cb.close else Gallery.build)()
blank: (e) -> Gallery.cb.close() if e.target is @
close: ->
$.rm Gallery.el
delete Gallery.el
$.rm Gallery.nodes.el
delete Gallery.nodes
d.body.style.overflow = ''
$.off d, 'keydown', Gallery.cb.keybinds
$.on d, 'keydown', Keybinds.keydown
$.on d, 'keydown', Keybinds.keydown
menu:
init: ->
return if g.VIEW is 'catalog' or !Conf['Gallery'] or Conf['Image Expansion']
el = $.el 'span',
textContent: 'Gallery'
className: 'gallery-link'
{createSubEntry} = Gallery.menu
subEntries = []
for name in ['Gallery fit width', 'Gallery fit height', 'Hide thumbnails']
subEntries.push createSubEntry name
$.event 'AddMenuEntry',
type: 'header'
el: el
order: 105
subEntries: subEntries
createSubEntry: (name) ->
label = $.el 'label',
innerHTML: "<input type=checkbox name='#{name}'> #{name}"
input = label.firstElementChild
# Reusing ImageExpand here because this code doesn't need any auditing to work for what we need
$.on input, 'change', ImageExpand.cb.setFitness
input.checked = Conf[name]
$.event 'change', null, input
$.on input, 'change', $.cb.checked
el: label

View File

@ -189,6 +189,3 @@ ImageExpand =
$.event 'change', null, input
$.on input, 'change', $.cb.checked
el: label
menuToggle: (e) ->
ImageExpand.opmenu.toggle e, @, g

View File

@ -1,7 +1,6 @@
IDColor =
init: ->
return if g.VIEW is 'catalog' or !Conf['Color User IDs']
return if g.VIEW is 'catalog' or not Conf['Color User IDs']
@ids = {}
Post::callbacks.push
@ -9,30 +8,34 @@ IDColor =
cb: @node
node: ->
return if @isClone or not str = @info.uniqueID
uid = $ '.hand', @nodes.uniqueID
return unless uid and uid.nodeName is 'SPAN'
uid.style.cssText = IDColor.css IDColor.ids[str] or IDColor.compute str
return if @isClone or not uid = @info.uniqueID
span = $ '.hand', @nodes.uniqueID
return unless span and span.nodeName is 'SPAN'
rgb = IDColor.compute uid
{style} = span
style.color = rgb[3]
style.backgroundColor = "rgb(#{rgb[0]},#{rgb[1]},#{rgb[2]})"
$.addClass span, 'painted'
span.title = 'Highlight posts by this ID'
compute: (str) ->
hash = IDColor.hash str
compute: (uid) ->
return IDColor.ids[uid] if IDColor.ids[uid]
hash = IDColor.hash uid
rgb = [
(hash >> 24) & 0xFF
(hash >> 16) & 0xFF
(hash >> 8) & 0xFF
(hash >> 8) & 0xFF
]
rgb[3] = if (rgb[0] * 0.299 + rgb[1] * 0.587 + rgb[2] * 0.114) > 125
'#000'
else
'#fff'
@ids[uid] = rgb
rgb[3] = ((rgb[0] * 0.299) + (rgb[1] * 0.587) + (rgb[2] * 0.114)) > 125
@ids[str] = rgb
rgb
css: (rgb) -> "background-color: rgb(#{rgb[0]},#{rgb[1]},#{rgb[2]}); color: #{if rgb[3] then "#000" else "#fff"}; border-radius: 3px; padding: 0px 2px;"
hash: (str) ->
hash: (uid) ->
msg = 0
i = 0
while i < 8
msg = ((msg << 5) - msg) + str.charCodeAt i++
msg
msg = (msg << 5) - msg + uid.charCodeAt i++
msg

View File

@ -69,10 +69,12 @@ Keybinds =
Keybinds.img threadRoot
when Conf['Expand images']
Keybinds.img threadRoot, true
when Conf['Open Gallery']
Gallery.cb.toggle()
when Conf['fappeTyme']
unless $('#menu.left')
Header.menuButton.click()
FappeTyme.input.click()
FappeTyme.cb.fappe()
when Conf['werkTyme']
FappeTyme.cb.werk()
# Board Navigation
when Conf['Front page']
window.location = "/#{g.BOARD}/0#delform"

View File

@ -77,7 +77,8 @@ QR =
persist: ->
return unless QR.postingIsEnabled
QR.open()
QR.hide() if Conf['Auto Hide QR']
QR.hide() if Conf['Auto-Hide QR'] or g.VIEW is 'catalog'
open: ->
if QR.nodes
QR.nodes.el.hidden = false