Settings.coffee (and some attached files)

This commit is contained in:
Zixaphir 2015-01-09 15:33:57 -07:00
parent f86ea6d328
commit 28f694591d
6 changed files with 422 additions and 270 deletions

View File

@ -1,5 +1,5 @@
/* /*
* appchan x - Version 2.9.43 - 2015-01-08 * appchan x - Version 2.9.43 - 2015-01-09
* *
* Licensed under the MIT license. * Licensed under the MIT license.
* https://github.com/zixaphir/appchan-x/blob/master/LICENSE * https://github.com/zixaphir/appchan-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

@ -83,9 +83,9 @@ PostHiding =
@cb = -> PostHiding.menu.hide post @cb = -> PostHiding.menu.hide post
$.on @el, 'click', @cb $.on @el, 'click', @cb
true true
thisPost = el: UI.checkbox 'thisPost', ' This post', true thisPost = el: UI.checkbox 'thisPost', 'This post', true
replies = el: UI.checkbox 'replies', ' Hide replies', Conf['Recursive Hiding'] replies = el: UI.checkbox 'replies', 'Hide replies', Conf['Recursive Hiding']
makeStub = el: UI.checkbox 'makeStub', ' Make stub', Conf['Stubs'] makeStub = el: UI.checkbox 'makeStub', 'Make stub', Conf['Stubs']
Menu.menu.addEntry Menu.menu.addEntry
el: $.el 'div', el: $.el 'div',
@ -104,12 +104,12 @@ PostHiding =
$.on @el, 'click', @cb $.on @el, 'click', @cb
true true
thisPost = thisPost =
el: UI.checkbox 'thisPost', ' This post', false el: UI.checkbox 'thisPost', 'This post', false
open: (post) -> open: (post) ->
@el.firstChild.checked = post.isHidden @el.firstChild.checked = post.isHidden
true true
replies = replies =
el: UI.checkbox 'replies', ' Show replies', false el: UI.checkbox 'replies', 'Show replies', false
open: (post) -> open: (post) ->
data = PostHiding.db.get {boardID: post.board.ID, threadID: post.thread.ID, postID: post.ID} data = PostHiding.db.get {boardID: post.board.ID, threadID: post.thread.ID, postID: post.ID}
@el.firstChild.checked = if 'hideRecursively' of data then data.hideRecursively else Conf['Recursive Hiding'] @el.firstChild.checked = if 'hideRecursively' of data then data.hideRecursively else Conf['Recursive Hiding']

View File

@ -12,18 +12,18 @@ Settings =
el: el el: el
order: 1 order: 1
{addSection} = @ add = @addSection
addSection arr[1], Settings[arr[0]] for arr in [
['style', 'Style'] add 'Style', @style
['themes', 'Themes'] add 'Themes', @themes
['mascots', 'Mascots'] add 'Mascots', @mascots
['main', 'Script'] add 'Main', @main
['filter', 'Filter'] add 'Filter', @filter
['sauce', 'Sauce'] add 'Sauce', @sauce
['advanced', 'Advanced'] add 'Advanced', @advanced
['keybinds', 'Keybinds'] add 'Keybinds', @keybinds
]
$.on d, 'AddSettingsSection', Settings.addSection
$.on d, 'OpenSettings', (e) -> Settings.open e.detail $.on d, 'OpenSettings', (e) -> Settings.open e.detail
settings = JSON.parse(localStorage.getItem '4chan-settings') or {} settings = JSON.parse(localStorage.getItem '4chan-settings') or {}
@ -84,6 +84,8 @@ Settings =
close: -> close: ->
return unless Settings.dialog return unless Settings.dialog
# Unfocus current field to trigger change event.
d.activeElement?.blur()
$.rm Settings.overlay $.rm Settings.overlay
$.rm Settings.dialog $.rm Settings.dialog
delete Settings.overlay delete Settings.overlay
@ -92,6 +94,8 @@ Settings =
sections: [] sections: []
addSection: (title, open) -> addSection: (title, open) ->
if typeof title isnt 'string'
{title, open} = title.detail
hyphenatedTitle = title.toLowerCase().replace /\s+/g, '-' hyphenatedTitle = title.toLowerCase().replace /\s+/g, '-'
Settings.sections.push {title, hyphenatedTitle, open} Settings.sections.push {title, hyphenatedTitle, open}
@ -111,27 +115,41 @@ Settings =
inputs = {} inputs = {}
for key, obj of Config.main for key, obj of Config.main
fs = $.el 'fieldset', fs = $.el 'fieldset',
innerHTML: "<legend>#{key}</legend>" <%= html('<legend>${key}</legend>') %>
containers = [fs]
for key, arr of obj for key, arr of obj
description = arr[1] description = arr[1]
div = $.el 'div', div = $.el 'div'
innerHTML: "<label><input type=checkbox name='#{key}'>#{key}</label><span class=description>#{description}</span>" $.add div, [
UI.checkbox key, key, false
$.el 'span', class: 'description', textContent: ": #{description}"
]
input = $ 'input', div input = $ 'input', div
$.on $('label', div), 'mouseover', Settings.mouseover $.on $('label', div), 'mouseover', Settings.mouseover
$.on input, 'change', $.cb.checked $.on input, 'change', ->
@parentNode.parentNode.dataset.checked = @checked
$.cb.checked.call @
items[key] = Conf[key] items[key] = Conf[key]
inputs[key] = input inputs[key] = input
$.add fs, div level = arr[2] or 0
if containers.length <= level
container = $.el 'div', className: 'suboption-list'
$.add containers[containers.length-1].lastElementChild, container
containers[level] = container
else if containers.length > level+1
containers.splice level+1, containers.length - (level+1)
$.add containers[level], div
Rice.nodes fs Rice.nodes fs
$.add section, fs $.add section, fs
$.get items, (items) -> $.get items, (items) ->
for key, val of items for key, val of items
inputs[key].checked = val inputs[key].checked = val
inputs[key].parentNode.parentNode.dataset.checked = val
return return
div = $.el 'div', div = $.el 'div',
innerHTML: "<button></button><span class=description>: Clear manually-hidden threads and posts on all boards. Reload the page to apply." <%= html('<button></button><span class="description">: Clear manually-hidden threads and posts on all boards. Reload the page to apply.') %>
button = $ 'button', div button = $ 'button', div
$.get 'hiddenPosts', {}, ({hiddenPosts}) -> $.get 'hiddenPosts', {}, ({hiddenPosts}) ->
hiddenNum = 0 hiddenNum = 0
@ -163,18 +181,19 @@ Settings =
onImport: -> onImport: ->
return unless file = @files[0] return unless file = @files[0]
return unless confirm 'Your current settings will be entirely overwritten, are you sure?' unless confirm 'Your current settings will be entirely overwritten, are you sure?'
new Notice 'info', "Import aborted.", 1
return
reader = new FileReader() reader = new FileReader()
reader.onload = (e) -> reader.onload = (e) ->
try try
Settings.loadSettings JSON.parse e.target.result Settings.loadSettings JSON.parse e.target.result
if confirm 'Import successful. Reload now?'
window.location.reload()
catch err catch err
alert 'Import failed due to an error.' alert 'Import failed due to an error.'
c.error err.stack c.error err.stack
return
if confirm 'Import successful. Reload now?'
window.location.reload()
reader.readAsText file reader.readAsText file
loadSettings: (data) -> loadSettings: (data) ->
@ -207,28 +226,19 @@ Settings =
$.add div, ta $.add div, ta
return return
$.extend div, <%= importHTML('Settings/Filter-guide') %> $.extend div, <%= importHTML('Settings/Filter-guide') %>
$('.warning', div).hidden = Conf['Filter']
sauce: (section) -> sauce: (section) ->
$.extend section, <%= importHTML('Settings/Sauce') %> $.extend section, <%= importHTML('Settings/Sauce') %>
ta = $ 'textarea', section ta = $ 'textarea', section
$.get 'sauces', Conf['sauces'], (item) -> $.get 'sauces', Conf['sauces'], (item) ->
# XXX remove .replace func after 31-7-2013 (v1 transitioning) ta.value = item['sauces']
ta.value = item['sauces'].replace /\$\d/g, (c) ->
switch c
when '$1'
'%TURL'
when '$2'
'%URL'
when '$3'
'%MD5'
when '$4'
'%board'
else
c
$.on ta, 'change', $.cb.value $.on ta, 'change', $.cb.value
advanced: (section) -> advanced: (section) ->
$.extend section, <%= importHTML('Settings/Advanced') %> $.extend section, <%= importHTML('Settings/Advanced') %>
warning.hidden = Conf[warning.dataset.feature] for warning in $$ '.warning', section
items = {} items = {}
inputs = {} inputs = {}
for name in ['boardnav', 'time', 'backlink', 'fileInfo', 'favicon', 'usercss'] for name in ['boardnav', 'time', 'backlink', 'fileInfo', 'favicon', 'usercss']
@ -256,9 +266,16 @@ Settings =
Settings[key].call input Settings[key].call input
Rice.nodes section Rice.nodes section
$.on $('input[name=Interval]', section), 'change', ThreadUpdater.cb.interval interval = $ 'input[name="Interval"]', section
$.on $('input[name="Custom CSS"]', section), 'change', Settings.togglecss customCSS = $ 'input[name="Custom CSS"]', section
$.on $.id('apply-css'), 'click', Settings.usercss
interval.value = Conf['Interval']
customCSS.checked = Conf['Custom CSS']
inputs['usercss'].disabled = !Conf['Custom CSS']
$.on interval, 'change', ThreadUpdater.cb.interval
$.on customCSS, 'change', Settings.togglecss
$.on $('#apply-css', section), 'click', Settings.usercss
archBoards = {} archBoards = {}
for {name, boards, files, software, withCredentials} in Redirect.archives for {name, boards, files, software, withCredentials} in Redirect.archives
@ -293,6 +310,8 @@ Settings =
$.add row, Settings.addArchiveCell boardID, o, item for item in ['thread', 'post', 'file'] $.add row, Settings.addArchiveCell boardID, o, item for item in ['thread', 'post', 'file']
rows.push row rows.push row
rows[0].hidden = not g.BOARD.ID of archBoards
$.add $('tbody', section), rows $.add $('tbody', section), rows
boardSelect = $('#archive-board-select', section) boardSelect = $('#archive-board-select', section)
@ -327,7 +346,7 @@ Settings =
textContent: archive textContent: archive
value: archive value: archive
td.innerHTML = '<select></select>' $.extend td, <%= html('<select></select>') %>
select = td.firstElementChild select = td.firstElementChild
unless select.disabled = length is 1 unless select.disabled = length is 1
# XXX GM can't into datasets # XXX GM can't into datasets
@ -350,7 +369,7 @@ Settings =
@nextElementSibling.textContent = Time.format @value, new Date() @nextElementSibling.textContent = Time.format @value, new Date()
backlink: -> backlink: ->
@nextElementSibling.textContent = @value.replace /%id/g, '123456789' @nextElementSibling.textContent = @value.replace /%(?:id|%)/g, (x) -> {'%id': '123456789', '%%': '%'}[x]
fileInfo: -> fileInfo: ->
data = data =
@ -362,22 +381,20 @@ Settings =
sizeInBytes: 276 * 1024 sizeInBytes: 276 * 1024
dimensions: '1280x720' dimensions: '1280x720'
isImage: true isImage: true
isVideo: false
isSpoiler: true isSpoiler: true
@nextElementSibling.innerHTML = FileInfo.format @value, data FileInfo.format @value, data, @nextElementSibling
favicon: -> favicon: ->
Favicon.init() Favicon.switch()
Unread.update() if g.VIEW is 'thread' and Conf['Unread Favicon'] Unread.update() if g.VIEW is 'thread' and Conf['Unread Favicon']
$.id('favicon-preview').innerHTML = """ img = @nextElementSibling.children
<img src=#{Favicon.default}> img[0].src = Favicon.default
<img src=#{Favicon.unreadSFW}> img[1].src = Favicon.unreadSFW
<img src=#{Favicon.unreadNSFW}> img[2].src = Favicon.unreadNSFW
<img src=#{Favicon.unreadDead}> img[3].src = Favicon.unreadDead
"""
togglecss: -> togglecss: ->
if $('textarea', @parentNode.parentNode).disabled = !@checked if $('textarea[name=usercss]', $.x 'ancestor::fieldset[1]', @).disabled = !@checked
CustomCSS.rmStyle() CustomCSS.rmStyle()
else else
CustomCSS.addStyle() CustomCSS.addStyle()
@ -388,13 +405,14 @@ Settings =
keybinds: (section) -> keybinds: (section) ->
$.extend section, <%= importHTML('Settings/Keybinds') %> $.extend section, <%= importHTML('Settings/Keybinds') %>
$('.warning', section).hidden = Conf['Keybinds']
tbody = $ 'tbody', section tbody = $ 'tbody', section
items = {} items = {}
inputs = {} inputs = {}
for key, arr of Config.hotkeys for key, arr of Config.hotkeys
tr = $.el 'tr', tr = $.el 'tr',
innerHTML: "<td>#{arr[1]}</td><td><input class=field></td>" <%= html('<td>${arr[1]}</td><td><input class="field"></td>') %>
input = $ 'input', tr input = $ 'input', tr
input.name = key input.name = key
input.spellcheck = false input.spellcheck = false
@ -437,7 +455,7 @@ Settings =
if type is 'text' if type is 'text'
div.innerHTML = "<div class=option><span class=optionlabel>#{key}</span></div><div class=description>#{description}</div><div class=option><input name='#{key}' style=width: 100%></div>" $.extend div, <%= html('<div class="option"><span class="optionlabel">${key}</span></div><div class="description">${description}</div><div class="option"><input name="${key}" style="width: 100%"></div>') %>
input = $ "input", div input = $ "input", div
else else
@ -450,8 +468,17 @@ Settings =
input = $ "select", div input = $ "select", div
else else
span = $.el 'span',
class: 'description'
textContent: description
span.style.display = 'none'
div.innerHTML = "<div class=option><label><input type=checkbox name='#{key}'>#{key}</label></div><span style='display:none;'>#{description}</span>" $.add div, [
UI.checkbox key, key
span
]
input = $ 'input', div input = $ 'input', div
items[key] = Conf[key] items[key] = Conf[key]
@ -507,7 +534,8 @@ Settings =
div = $.el 'div', div = $.el 'div',
className: "theme #{if name is Conf[g.THEMESTRING] then 'selectedtheme' else ''}" className: "theme #{if name is Conf[g.THEMESTRING] then 'selectedtheme' else ''}"
id: name id: name
innerHTML: """<%= grunt.file.read('src/General/html/Settings/Theme.html').replace(/>\s+</g, '><').trim() %>"""
$.extend div, <%= importHTML('Settings/Theme') %>
div.style.backgroundColor = theme['Background Color'] div.style.backgroundColor = theme['Background Color']
@ -526,7 +554,8 @@ Settings =
div = $.el 'div', div = $.el 'div',
id: 'addthemes' id: 'addthemes'
innerHTML: """<%= grunt.file.read('src/General/html/Settings/Batch-Theme.html').replace(/>\s+</g, '><').trim() %>"""
$.extend div, <%= importHTML('Settings/Batch-Theme') %>
$.on $("#newtheme", div), 'click', -> $.on $("#newtheme", div), 'click', ->
ThemeTools.init "untitled" ThemeTools.init "untitled"
@ -556,7 +585,8 @@ Settings =
div = $.el 'div', div = $.el 'div',
id: name id: name
className: theme className: theme
innerHTML: """<%= grunt.file.read('src/General/html/Settings/Deleted-Theme.html').replace(/>\s+</g, '><').trim() %>"""
$.extend div, <%= importHTML('Settings/Deleted-Theme') %>
$.on div, 'click', cb.restore $.on div, 'click', cb.restore
@ -611,7 +641,7 @@ Settings =
mascotHide = $.el "div", mascotHide = $.el "div",
id: "mascot_hide" id: "mascot_hide"
className: "reply" className: "reply"
innerHTML: "Hide Categories <span class=drop-marker></span><div></div>" <%= html('Hide Categories <span class="drop-marker"></span><div></div>') %>
keys = Object.keys Mascots keys = Object.keys Mascots
keys.sort() keys.sort()
@ -619,7 +649,7 @@ Settings =
if mode is 'default' if mode is 'default'
mascotoptions = $.el 'div', mascotoptions = $.el 'div',
id: 'mascot-options' id: 'mascot-options'
innerHTML: """<a class=edit href='javascript:;'>Edit</a><a class=delete href='javascript:;'>Delete</a><a class=export href='javascript:;'>Export</a>""" <%= html('<a class="edit" href="javascript:;">Edit</a><a class="delete" href="javascript:;">Delete</a><a class="export" href="javascript:;">Export</a>') %>
$.on $('.edit', mascotoptions), 'click', cb.edit $.on $('.edit', mascotoptions), 'click', cb.edit
$.on $('.delete', mascotoptions), 'click', cb.delete $.on $('.delete', mascotoptions), 'click', cb.delete
@ -635,12 +665,10 @@ Settings =
categories[name] = div = $.el "div", categories[name] = div = $.el "div",
id: name id: name
className: "mascots-container" className: "mascots-container"
innerHTML: "<h3 class=mascotHeader>#{name}</h3>" <%= html('<h3 class="mascotHeader">${name}</h3>') %>
hidden: name in Conf["Hidden Categories"] hidden: name in Conf["Hidden Categories"]
option = $.el "label", option = UI.checkbox name, name, name in Conf["Hidden Categories"]
name: name
innerHTML: "<input name='#{name}' type=checkbox #{if name in Conf["Hidden Categories"] then 'checked' else ''}>#{name}"
$.on $('input', option), 'change', cb.category $.on $('input', option), 'change', cb.category
@ -653,7 +681,8 @@ Settings =
mascotEl = $.el 'div', mascotEl = $.el 'div',
id: name id: name
className: if name in Conf[g.MASCOTSTRING] then 'mascot enabled' else 'mascot' className: if name in Conf[g.MASCOTSTRING] then 'mascot enabled' else 'mascot'
innerHTML: "<%= grunt.file.read('src/General/html/Settings/Mascot.html') %>"
$.extend div, <%= importHTML('Settings/Mascot') %>
$.on mascotEl, 'click', cb.select $.on mascotEl, 'click', cb.select
$.on mascotEl, 'mouseover', addoptions $.on mascotEl, 'mouseover', addoptions
@ -662,7 +691,8 @@ Settings =
batchmascots = $.el 'div', batchmascots = $.el 'div',
id: "mascots_batch" id: "mascots_batch"
innerHTML: """<%= grunt.file.read('src/General/html/Settings/Batch-Mascot.html') %>"""
$.extend batchmascots, <%= importHTML('Settings/Batch-Mascot') %>
$.on $('#clear', batchmascots), 'click', -> $.on $('#clear', batchmascots), 'click', ->
enabledMascots = JSON.parse(JSON.stringify(Conf[g.MASCOTSTRING])) enabledMascots = JSON.parse(JSON.stringify(Conf[g.MASCOTSTRING]))
@ -704,10 +734,8 @@ Settings =
mascotEl = $.el 'div', mascotEl = $.el 'div',
className: 'mascot' className: 'mascot'
id: name id: name
innerHTML: "
<div class='mascotname'>#{name.replace /_/g, " "}</span> $.extend mascotEl, <%= importHTML('Settings/Mascot') %>
<div class='mascotcontainer #{mascot.category} #{if mascot.silhouette then 'silhouette' else ''}'><img class=mascotimg src='#{mascot.image}'></div>
"
$.on mascotEl, 'click', cb.restore $.on mascotEl, 'click', cb.restore
@ -717,7 +745,7 @@ Settings =
batchmascots = $.el 'div', batchmascots = $.el 'div',
id: "mascots_batch" id: "mascots_batch"
innerHTML: """<a href="javascript:;" id="return">Return</a>""" <%= html('<a href="javascript:;" id="return">Return</a>') %>
$.on $('#return', batchmascots), 'click', -> $.on $('#return', batchmascots), 'click', ->
mascots = mascots =

View File

@ -1,2 +1,2 @@
<div class='mascotname'>#{name.replace /_/g, " "}</div> <div class='mascotname'>#{name.replace /_/g, ' '}</div>
<div class='mascotcontainer #{if mascot.silhouette then 'silhouette' else ''}'><div class='mAlign #{mascot.category}'><img class=mascotimg src='#{mascot.image}'></div></div> <div class='mascotcontainer #{if mascot.silhouette then 'silhouette' else ''}'><div class='mAlign #{mascot.category}'><img class='mascotimg' src='#{mascot.image}'></div></div>