Created
October 18, 2013 23:55
-
-
Save zixaphir/7049997 to your computer and use it in GitHub Desktop.
Starting on Infinite Scrolling (shh, don't tell)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
InfiniScroll = | |
init: -> | |
return unless g.VIEW is 'index' and Conf['Infinite Scroll'] | |
@threads = g.threads | |
$.on d, '4chanXInitFinished', @ready | |
ready: -> | |
$.off d, '4chanXInitFinished', InfiniScroll.ready | |
$.on d, 'scroll', InfiniScroll.scroll | |
scroll: -> | |
return if InfiniScroll.isFetching or (window.scrollTop <= d.height - window.innerHeight) | |
InfiniScroll.isFetching = true | |
url = "//api.4chan.org/#{g.board}/res/catalog.json" | |
InfiniScroll.req = $.ajax url, onloadend: InfiniScroll.cb.load, | |
whenModified: true | |
parse: (response) -> | |
threads = InfiniScroll.parsePages response | |
for thread in threads | |
posts = [] | |
{omitted_posts, omitted_images, no} = thread | |
el = $.el 'div' | |
className: 'thread' | |
id: "t#{no}" | |
op = Build.postFromObject thread | |
posts.push op | |
if omitted_posts | |
summary = $.el 'span', | |
className: 'summary desktop' | |
innerHTML: """ | |
#{omitted_posts} posts #{if omitted_images then "and " + omitted_images + " image replies"} omitted. Click <a class="replylink" href="res/#{no}">here</a> to view. | |
""" | |
mobileSummary = | |
for post in thread.last_replies | |
posts.push Build.postFromObject post | |
parsePages: (response) -> | |
newThreads = [] | |
for number, page of pages | |
{threads} = page | |
for thread in threads | |
continue if g.threads["#{g.BOARD}.#{thread.no}"] | |
newThreads.push thread | |
return newThreads if newThreads.length is 15 | |
return newThreads | |
cb: | |
load: -> | |
InfiniScroll.isFetching = false | |
{req} = InfiniScroll | |
switch req.status | |
when 200 | |
InfiniScroll.parse JSON.parse req.response | |
when 404 | |
return | |
else | |
return # WIP | |
pages = JSON.parse @response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment