Start working on fixing things after the last merge

This commit is contained in:
Zixaphir 2014-02-28 14:48:24 -07:00
parent 9d95bbea35
commit 6ba92efcd4
11 changed files with 263 additions and 901 deletions

View File

@ -1,5 +1,5 @@
/*
* 4chan X - Version 1.3.10 - 2014-02-23
* 4chan X - Version 1.3.10 - 2014-02-28
*
* Licensed under the MIT license.
* https://github.com/Spittie/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

@ -7,6 +7,7 @@
<select id="index-mode" name="Index Mode">
<option disabled>Index Mode</option>
<option value="paged">Paged</option>
<option value="infinite">Infinite Scrolling</option>
<option value="all pages">All threads</option>
<option value="catalog">Catalog</option>
</select>

View File

@ -52,6 +52,7 @@ PostHiding =
Get.postFromNode @
else
Get.threadFromNode(@).OP
toggle: (post) ->
if post.isHidden
post.show()
@ -59,9 +60,14 @@ PostHiding =
post.hide 'Manually hidden'
PostHiding.saveHiddenState post
return if post.isReply
Index.updateHideLabel()
Index.sort()
Index.buildIndex()
if Conf['JSON Navigation']
Index.updateHideLabel()
Index.sort()
Index.buildIndex()
else
# XXX Tempfix until I feel like writing out real functionality for thread hiding without JSON functions
$.rm post.nodes.root.parentElement
saveHiddenState: (post, val) ->
data =

View File

@ -1,211 +0,0 @@
ThreadHiding =
init: ->
return if g.VIEW isnt 'index' or !Conf['Thread Hiding Buttons'] and !Conf['Thread Hiding Link']
@db = new DataBoard 'hiddenThreads'
@syncCatalog()
$.on d, 'IndexBuild', @onIndexBuild
Thread.callbacks.push
name: 'Thread Hiding'
cb: @node
node: ->
if data = ThreadHiding.db.get {boardID: @board.ID, threadID: @ID}
ThreadHiding.hide @, data.makeStub
return unless Conf['Thread Hiding Buttons']
$.prepend @OP.nodes.root, ThreadHiding.makeButton @, 'hide'
onIndexBuild: ({detail: nodes}) ->
for root, i in nodes by 2
thread = Get.threadFromRoot root
continue unless thread.isHidden
unless thread.stub
nodes[i + 1].hidden = true
else unless root.contains thread.stub
# When we come back to a page, the stub is already there.
ThreadHiding.makeStub thread, root
return
syncCatalog: ->
# Sync hidden threads from the catalog into the index.
hiddenThreads = ThreadHiding.db.get
boardID: g.BOARD.ID
defaultValue: {}
hiddenThreadsOnCatalog = JSON.parse(localStorage.getItem "4chan-hide-t-#{g.BOARD}") or {}
# Add threads that were hidden in the catalog.
for threadID of hiddenThreadsOnCatalog
unless threadID of hiddenThreads
hiddenThreads[threadID] = {}
# Remove threads that were un-hidden in the catalog.
for threadID of hiddenThreads
unless threadID of hiddenThreadsOnCatalog
delete hiddenThreads[threadID]
if (ThreadHiding.db.data.lastChecked or 0) > Date.now() - $.MINUTE
# Was cleaned just now.
ThreadHiding.cleanCatalog hiddenThreadsOnCatalog
ThreadHiding.db.set
boardID: g.BOARD.ID
val: hiddenThreads
cleanCatalog: (hiddenThreadsOnCatalog) ->
# We need to clean hidden threads on the catalog ourselves,
# otherwise if we don't visit the catalog regularly
# it will pollute the localStorage and our data.
$.cache "//a.4cdn.org/#{g.BOARD}/threads.json", ->
return unless @status is 200
threads = {}
for page in @response
for thread in page.threads
if thread.no of hiddenThreadsOnCatalog
threads[thread.no] = hiddenThreadsOnCatalog[thread.no]
if Object.keys(threads).length
localStorage.setItem "4chan-hide-t-#{g.BOARD}", JSON.stringify threads
else
localStorage.removeItem "4chan-hide-t-#{g.BOARD}"
menu:
init: ->
return if g.VIEW isnt 'index' or !Conf['Menu'] or !Conf['Thread Hiding Link']
div = $.el 'div',
className: 'hide-thread-link'
textContent: 'Hide thread'
apply = $.el 'a',
textContent: 'Apply'
href: 'javascript:;'
$.on apply, 'click', ThreadHiding.menu.hide
makeStub = $.el 'label',
innerHTML: "<input type=checkbox #{if Conf['Stubs'] then 'checked' else ''}> Make stub"
$.event 'AddMenuEntry',
type: 'post'
el: div
order: 20
open: ({thread, isReply}) ->
if isReply or thread.isHidden
return false
ThreadHiding.menu.thread = thread
true
subEntries: [el: apply; el: makeStub]
div = $.el 'a',
className: 'show-thread-link'
textContent: 'Show thread'
href: 'javascript:;'
$.on div, 'click', ThreadHiding.menu.show
$.event 'AddMenuEntry',
type: 'post'
el: div
order: 20
open: ({thread, isReply}) ->
if isReply or !thread.isHidden
return false
ThreadHiding.menu.thread = thread
true
hideStubLink = $.el 'a',
textContent: 'Hide stub'
href: 'javascript:;'
$.on hideStubLink, 'click', ThreadHiding.menu.hideStub
$.event 'AddMenuEntry',
type: 'post'
el: hideStubLink
order: 15
open: ({thread, isReply}) ->
if isReply or !thread.isHidden
return false
ThreadHiding.menu.thread = thread
hide: ->
makeStub = $('input', @parentNode).checked
{thread} = ThreadHiding.menu
ThreadHiding.hide thread, makeStub
ThreadHiding.saveHiddenState thread, makeStub
$.event 'CloseMenu'
show: ->
{thread} = ThreadHiding.menu
ThreadHiding.show thread
ThreadHiding.saveHiddenState thread
$.event 'CloseMenu'
hideStub: ->
{thread} = ThreadHiding.menu
ThreadHiding.hide thread, false
$.event 'CloseMenu'
return
makeButton: (thread, type) ->
a = $.el 'a',
className: "#{type}-thread-button"
innerHTML: "<span class='fa fa-#{if type is 'hide' then 'minus' else 'plus'}-square'></span>"
href: 'javascript:;'
a.dataset.fullID = thread.fullID
$.on a, 'click', ThreadHiding.toggle
a
makeStub: (thread, root) ->
numReplies = $$('.thread > .replyContainer', root).length
numReplies += +summary.textContent.match /\d+/ if summary = $ '.summary', root
opInfo = if Conf['Anonymize']
'Anonymous'
else
$('.nameBlock', thread.OP.nodes.info).textContent
a = ThreadHiding.makeButton thread, 'show'
$.add a, $.tn " #{opInfo} (#{if numReplies is 1 then '1 reply' else "#{numReplies} replies"})"
thread.stub = $.el 'div',
className: 'stub'
if Conf['Menu']
$.add thread.stub, [a, Menu.makeButton()]
else
$.add thread.stub, a
$.prepend root, thread.stub
saveHiddenState: (thread, makeStub) ->
hiddenThreadsOnCatalog = JSON.parse(localStorage.getItem "4chan-hide-t-#{g.BOARD}") or {}
if thread.isHidden
ThreadHiding.db.set
boardID: thread.board.ID
threadID: thread.ID
val: {makeStub}
hiddenThreadsOnCatalog[thread] = true
else
ThreadHiding.db.delete
boardID: thread.board.ID
threadID: thread.ID
delete hiddenThreadsOnCatalog[thread]
localStorage.setItem "4chan-hide-t-#{g.BOARD}", JSON.stringify hiddenThreadsOnCatalog
toggle: (thread) ->
unless thread instanceof Thread
thread = g.threads[@dataset.fullID]
if thread.isHidden
ThreadHiding.show thread
else
ThreadHiding.hide thread
ThreadHiding.saveHiddenState thread
hide: (thread, makeStub=Conf['Stubs']) ->
return if thread.isHidden
threadRoot = thread.OP.nodes.root.parentNode
thread.isHidden = true
return threadRoot.hidden = threadRoot.nextElementSibling.hidden = true unless makeStub # <hr>
ThreadHiding.makeStub thread, threadRoot
show: (thread) ->
if thread.stub
$.rm thread.stub
delete thread.stub
threadRoot = thread.OP.nodes.root.parentNode
threadRoot.nextElementSibling.hidden =
threadRoot.hidden = thread.isHidden = false

View File

@ -143,6 +143,9 @@ Header =
Header.boardList = boardList = $.el 'span',
id: 'board-list'
innerHTML: "<span id=custom-board-list></span><span id=full-board-list hidden><span class='hide-board-list-container brackets-wrap'><a href=javascript:; class='hide-board-list-button'>&nbsp;-&nbsp;</a></span> #{fourchannav.innerHTML}</span>"
$.on $('#custom-board-list', Header.boardList), 'click', Index.cb.headerNav if Conf['JSON Navigation']
for a in $$ 'a', boardList
if Conf['JSON Navigation']
$.on a, 'click', Navigate.navigate

View File

@ -87,6 +87,16 @@ Index =
$.addClass doc, 'index-loading'
@root = $.el 'div', className: 'board'
@pagelist = $.el 'div',
className: 'pagelist'
hidden: true
innerHTML: <%= importHTML('Features/Index-pagelist') %>
@navLinks = $.el 'div',
className: 'navLinks'
innerHTML: <%= importHTML('Features/Index-navlinks') %>
@searchInput = $ '#index-search', @navLinks
@hideLabel = $ '#hidden-label', @navLinks
@selectMode = $ '#index-mode', @navLinks
@ -102,16 +112,6 @@ Index =
$.on @selectSort, 'change', @cb.sort
$.on @selectSize, 'change', @cb.size
@root = $.el 'div', className: 'board'
@pagelist = $.el 'div',
className: 'pagelist'
hidden: true
innerHTML: <%= importHTML('Features/Index-pagelist') %>
@navLinks = $.el 'div',
className: 'navLinks'
innerHTML: <%= importHTML('Features/Index-navlinks') %>
@searchInput = $ '#index-search', @navLinks
@currentPage = @getCurrentPage()
@ -140,8 +140,6 @@ Index =
$.after $.x('child::form/preceding-sibling::hr[1]'), Index.navLinks
$.rmClass doc, 'index-loading'
$.on $('#custom-board-list', Header.bar), 'click', @cb.headerNav
@cb.toggleCatalogMode()
$.asap (-> $('.pagelist', doc) or d.readyState isnt 'loading'), ->
@ -152,16 +150,12 @@ Index =
scroll: $.debounce 100, ->
return if Index.req or Conf['Index Mode'] isnt 'infinite' or (doc.scrollTop <= doc.scrollHeight - (300 + window.innerHeight)) or g.VIEW is 'thread'
Index.pageNum = Index.getCurrentPage() unless Index.pageNum? # Avoid having to pushState to keep track of the current page
Index.pageNum = (Index.pageNum or Index.getCurrentPage()) + 1 # Avoid having to pushState to keep track of the current page
pageNum = Index.pageNum++
return Index.endNotice() if pageNum >= Index.pagesNum
return Index.endNotice() if Index.pageNum >= Index.pagesNum
Index.buildIndex true
nodes = Index.buildSinglePage pageNum
Index.buildReplies nodes if Conf['Show Replies']
Index.buildStructure nodes
Index.setPage pageNum
endNotice: do ->
notify = false
reset = -> notify = false
@ -289,6 +283,7 @@ Index =
else
$.rmClass doc, 'catalog-mode'
Index.cb.size()
toggleHiddenThreads: ->
$('#hidden-toggle a', Index.navLinks).textContent = if Index.showHiddenThreads = !Index.showHiddenThreads
'Hide'
@ -299,6 +294,7 @@ Index =
Index.pageNav 0
else
Index.buildIndex()
mode: (e) ->
Index.cb.toggleCatalogMode()
Index.togglePagelist()
@ -312,9 +308,11 @@ Index =
QR.hide()
else
QR.unhide()
sort: (e) ->
Index.sort()
Index.buildIndex() if e
size: (e) ->
if Conf['Index Mode'] isnt 'catalog'
$.rmClass Index.root, 'catalog-small'
@ -326,9 +324,11 @@ Index =
$.addClass Index.root, 'catalog-large'
$.rmClass Index.root, 'catalog-small'
Index.buildIndex() if e
threadsNum: ->
return unless Conf['Index Mode'] is 'paged'
Index.buildIndex()
target: ->
for threadID, thread of g.BOARD.threads when thread.catalogView
{thumb} = thread.catalogView.nodes
@ -337,10 +337,12 @@ Index =
else
thumb.removeAttribute 'target'
return
replies: ->
Index.buildThreads()
Index.sort()
Index.buildIndex()
pageNav: (e) ->
return if e.shiftKey or e.altKey or e.ctrlKey or e.metaKey or e.button isnt 0
switch e.target.nodeName
@ -353,6 +355,7 @@ Index =
e.preventDefault()
return if Index.cb.indexNav a, true
Index.userPageNav +a.pathname.split('/')[2]
headerNav: (e) ->
a = e.target
return if e.button isnt 0 or a.nodeName isnt 'A' or a.hostname isnt 'boards.4chan.org'
@ -363,6 +366,7 @@ Index =
return if e.shiftKey or e.altKey or e.ctrlKey or e.metaKey or !onSameIndex
e.preventDefault()
Index.update() unless needChange
indexNav: (a, onSameIndex) ->
{indexMode, indexSort} = a.dataset
if indexMode and Conf['Index Mode'] isnt indexMode
@ -388,12 +392,16 @@ Index =
Header.scrollToIfNeeded Index.navLinks
getCurrentPage: ->
if Conf['Index Mode'] is 'infinite' and Index.pageNum
return Index.pageNum
+window.location.pathname.split('/')[2]
userPageNav: (pageNum) ->
if Conf['Refreshed Navigation'] and Conf['Index Mode'] isnt 'all pages'
Index.update pageNum
else
Index.pageNav pageNum
pageNav: (pageNum) ->
return if Index.currentPage is pageNum
history.pushState null, '', if pageNum is 0 then './' else pageNum
@ -541,7 +549,7 @@ Index =
new Notice 'error', 'Index refresh failed.', 1
return
timeEl = $ '#index-last-refresh time', Index.navLinks
timeEl = $ 'time#index-last-refresh', Index.navLinks
timeEl.dataset.utc = Date.parse req.getResponseHeader 'Last-Modified'
RelativeDates.update timeEl
Index.scrollToIndex()
@ -679,7 +687,7 @@ Index =
Index.sortedThreads.splice offset++, 0, Index.sortedThreads.splice(i, 1)[0]
return
buildIndex: ->
buildIndex: (infinite) ->
switch Conf['Index Mode']
when 'paged', 'infinite'
pageNum = Index.getCurrentPage()
@ -687,7 +695,7 @@ Index =
# Go to the last available page if we were past the limit.
Index.pageNav Index.getMaxPageNum()
return
threadsPerPage = Index.getThreadsNumPerPage()
threads = Index.sortedThreads[threadsPerPage * pageNum ... threadsPerPage * (pageNum + 1)]
nodes = threads.map (thread) -> thread.OP.nodes.root.parentNode
Index.buildReplies threads
@ -701,7 +709,7 @@ Index =
nodes = Index.sortedThreads.map (thread) -> thread.OP.nodes.root.parentNode
Index.buildReplies Index.sortedThreads
nodes = Index.buildHRs nodes
$.rmAll Index.root
$.rmAll Index.root unless infinite
$.add Index.root, nodes
$.event 'IndexBuild', nodes

View File

@ -290,14 +290,12 @@ Main =
['Reveal Spoilers', RemoveSpoilers]
['Resurrect Quotes', Quotify]
['Filter', Filter]
['Thread Hiding Buttons', ThreadHiding]
['Reply Hiding Buttons', PostHiding]
['Recursive', Recursive]
['Strike-through Quotes', QuoteStrikeThrough]
['Quick Reply', QR]
['Menu', Menu]
['Report Link', ReportLink]
['Thread Hiding (Menu)', ThreadHiding.menu]
['Reply Hiding (Menu)', PostHiding.menu]
['Delete Link', DeleteLink]
['Filter (Menu)', Filter.menu]

View File

@ -483,6 +483,9 @@ div.center:not(.ad-cnt) {
:root.index-loading .pagelist {
display: none;
}
.index #returnlink {
display: none;
}
#index-search {
padding-right: 1.5em;
width: 100px;
@ -506,13 +509,110 @@ div.center:not(.ad-cnt) {
.summary {
text-decoration: none;
}
.index #returnlink,
.index #bottomlink,
.thread #index-last-refresh,
.thread #index-search-clear,
.thread #index-search {
.catalog-mode .board {
text-align: center;
}
.catalog-thread {
display: inline-flex;
text-align: left;
flex-direction: column;
align-items: center;
margin: 0 2px 5px;
word-break: break-word;
vertical-align: top;
}
.catalog-small .catalog-thread {
width: 165px;
max-height: 320px;
}
.catalog-large .catalog-thread {
width: 270px;
max-height: 410px;
}
.thumb {
flex-shrink: 0;
position: relative;
background-size: 100% 100%;
background-repeat: no-repeat;
background-position: center;
border-radius: 2px;
box-shadow: 0 0 5px rgba(0, 0, 0, .25);
}
.thumb:not(.deleted-file):not(.no-file) {
min-width: 30px;
min-height: 30px;
}
.thumb.spoiler-file {
background-size: 100px;
width: 100px;
height: 100px;
}
.thumb.deleted-file {
background-size: 127px 13px;
width: 127px;
height: 13px;
padding: 20px 11px;
}
.thumb.no-file {
background-size: 77px 13px;
width: 77px;
height: 13px;
padding: 20px 36px;
}
.thread-icons > img {
width: 1em;
height: 1em;
margin: 0;
vertical-align: text-top;
}
.thumb:not(:hover):not(:focus) > .menu-button:not(.open):not(:focus) > i {
display: none;
}
.thumb > .menu-button {
position: absolute;
top: 0;
right: 0;
}
.thumb > .menu-button > i {
width: 1em;
height: 1em;
padding: 1px;
border-radius: 0 2px 0 2px;
font-size: 14px;
text-align: center;
<% if (type === 'userscript') { %>
line-height: normal;
<% } %>
}
.thread-stats {
flex-shrink: 0;
cursor: help;
font-size: 10px;
font-weight: 700;
margin-top: 2px;
}
.catalog-thread > .subject {
flex-shrink: 0;
font-weight: 700;
line-height: 1;
text-align: center;
}
.catalog-thread > .comment {
flex-shrink: 1;
align-self: stretch;
overflow: hidden;
text-align: center;
}
.thread-info {
position: fixed;
background-color: inherit;
padding: 2px;
border-radius: 2px;
box-shadow: 0 0 5px rgba(0, 0, 0, .25);
}
.thread-info .post {
margin: 0;
}
/* Announcement Hiding */
:root.hide-announcement #globalMessage {
@ -766,27 +866,16 @@ span.hide-announcement {
color: white !important;
}
/* Thread & Reply Hiding */
.hide-thread-button,
.hide-reply-button {
/* Post Hiding */
.hide-post-button,
.show-post-button {
font-size: 14px;
line-height: 12px; /* Prevent the floating effect from affecting the thumbnail too */
}
.opContainer > .show-post-button,
.hide-post-button {
float: left;
margin-right: 4px;
padding: 2px;
}
.hide-thread-button:not(:hover),
.hide-reply-button:not(:hover) {
opacity: 0.4;
}
.threadContainer .hide-reply-button {
margin-left: 2px !important;
position: relative;
left: 1px;
}
.hide-thread-button {
margin-top: -1px;
}
.stub ~ * {
display: none !important;
margin-right: 3px;
}
.stub input {
display: inline-block;

View File

@ -1,6 +1,28 @@
<span class=brackets-wrap id=returnlink><a href=.././>Return</a></span>
<span class=brackets-wrap id=cataloglink><a href=javascript:;>Catalog</a></span>
<span class=brackets-wrap id=bottomlink><a href="#bottom">Bottom</a></span>
<span class=brackets-wrap id="index-last-refresh"><time title="Last index refresh">...</time></span>
<input type="search" id="index-search" class="field" placeholder="Search">
<a id="index-search-clear" href="javascript:;" title="Clear search">×</a>
<a id="index-search-clear" class="fa fa-times-circle" href="javascript:;"></a>
&nbsp;
<time id="index-last-refresh" title="Last index refresh">...</time>
<span id="hidden-label" hidden>&nbsp;&mdash; <span id="hidden-count"></span> <span id="hidden-toggle">[<a href="javascript:;">Show</a>]</span></span>
<span style="flex:1"></span>
<select id="index-mode" name="Index Mode">
<option disabled>Index Mode</option>
<option value="paged">Paged</option>
<option value="infinite">Infinite Scrolling</option>
<option value="all pages">All threads</option>
<option value="catalog">Catalog</option>
</select>
<select id="index-sort" name="Index Sort">
<option disabled>Index Sort</option>
<option value="bump">Bump order</option>
<option value="lastreply">Last reply</option>
<option value="birth">Creation date</option>
<option value="replycount">Reply count</option>
<option value="filecount">File count</option>
</select>
<select id="index-size" name="Index Size">
<option disabled>Image Size</option>
<option value="small">Small</option>
<option value="large">Large</option>
</select>