Add Thread.OP|isSticky|isClosed.

This commit is contained in:
Nicolas Stepien 2013-02-23 00:02:34 +01:00
parent d4089d09c5
commit 02fc7fecb3
3 changed files with 48 additions and 51 deletions

View File

@ -20,7 +20,7 @@
// @icon data:image/gif;base64,R0lGODlhEAAQAKECAAAAAGbMM////////yH5BAEKAAIALAAAAAAQABAAAAIxlI+pq+D9DAgUoFkPDlbs7lGiI2bSVnKglnJMOL6omczxVZK3dH/41AG6Lh7i6qUoAAA7 // @icon data:image/gif;base64,R0lGODlhEAAQAKECAAAAAGbMM////////yH5BAEKAAIALAAAAAAQABAAAAIxlI+pq+D9DAgUoFkPDlbs7lGiI2bSVnKglnJMOL6omczxVZK3dH/41AG6Lh7i6qUoAAA7
// ==/UserScript== // ==/UserScript==
/* 4chan X Beta - Version 3.0.0 - 2013-02-22 /* 4chan X Beta - Version 3.0.0 - 2013-02-23
* http://mayhemydg.github.com/4chan-x/ * http://mayhemydg.github.com/4chan-x/
* *
* Copyright (c) 2009-2011 James Campos <james.r.campos@gmail.com> * Copyright (c) 2009-2011 James Campos <james.r.campos@gmail.com>
@ -1913,7 +1913,7 @@
if (!Conf['Hiding Buttons']) { if (!Conf['Hiding Buttons']) {
return; return;
} }
return $.prepend(this.posts[this].nodes.root, ThreadHiding.makeButton(this, 'hide')); return $.prepend(this.OP.nodes.root, ThreadHiding.makeButton(this, 'hide'));
}, },
getHiddenThreads: function() { getHiddenThreads: function() {
var hiddenThreads; var hiddenThreads;
@ -2032,15 +2032,14 @@
return ThreadHiding.saveHiddenState(thread); return ThreadHiding.saveHiddenState(thread);
}, },
hide: function(thread, makeStub) { hide: function(thread, makeStub) {
var a, numReplies, op, opInfo, span, threadRoot; var a, numReplies, opInfo, span, threadRoot;
if (makeStub == null) { if (makeStub == null) {
makeStub = Conf['Stubs']; makeStub = Conf['Stubs'];
} }
if (thread.hidden) { if (thread.hidden) {
return; return;
} }
op = thread.posts[thread]; threadRoot = thread.OP.nodes.root.parentNode;
threadRoot = op.nodes.root.parentNode;
threadRoot.hidden = thread.isHidden = true; threadRoot.hidden = thread.isHidden = true;
if (!makeStub) { if (!makeStub) {
threadRoot.nextElementSibling.hidden = true; threadRoot.nextElementSibling.hidden = true;
@ -2070,7 +2069,7 @@
$.rm(thread.stub); $.rm(thread.stub);
delete thread.stub; delete thread.stub;
} }
threadRoot = thread.posts[thread].nodes.root.parentNode; threadRoot = thread.OP.nodes.root.parentNode;
return threadRoot.nextElementSibling.hidden = threadRoot.hidden = thread.isHidden = false; return threadRoot.nextElementSibling.hidden = threadRoot.hidden = thread.isHidden = false;
} }
}; };
@ -3259,8 +3258,8 @@
fileHTML = ''; fileHTML = '';
} }
tripcode = tripcode ? " <span class=postertrip>" + tripcode + "</span>" : ''; tripcode = tripcode ? " <span class=postertrip>" + tripcode + "</span>" : '';
sticky = isSticky ? ' <img src=//static.4chan.org/image/sticky.gif alt=Sticky title=Sticky style="height:16px;width:16px">' : ''; sticky = isSticky ? ' <img src=//static.4chan.org/image/sticky.gif alt=Sticky title=Sticky class=stickyIcon>' : '';
closed = isClosed ? ' <img src=//static.4chan.org/image/closed.gif alt=Closed title=Closed style="height:16px;width:16px">' : ''; closed = isClosed ? ' <img src=//static.4chan.org/image/closed.gif alt=Closed title=Closed class=closedIcon>' : '';
container = $.el('div', { container = $.el('div', {
id: "pc" + postID, id: "pc" + postID,
className: "postContainer " + (isOP ? 'op' : 'reply') + "Container", className: "postContainer " + (isOP ? 'op' : 'reply') + "Container",
@ -3281,9 +3280,9 @@
Get = { Get = {
threadExcerpt: function(thread) { threadExcerpt: function(thread) {
var excerpt, op, _ref; var OP, excerpt, _ref;
op = thread.posts[thread]; OP = thread.OP;
excerpt = ((_ref = op.info.subject) != null ? _ref.trim() : void 0) || op.info.comment.replace(/\n+/g, ' // ') || Conf['Anonymize'] && 'Anonymous' || $('.nameBlock', op.nodes.info).textContent.trim(); excerpt = ((_ref = OP.info.subject) != null ? _ref.trim() : void 0) || OP.info.comment.replace(/\n+/g, ' // ') || Conf['Anonymize'] && 'Anonymous' || $('.nameBlock', OP.nodes.info).textContent.trim();
return "/" + thread.board + "/ - " + excerpt; return "/" + thread.board + "/ - " + excerpt;
}, },
postFromRoot: function(root) { postFromRoot: function(root) {
@ -4798,9 +4797,8 @@
}); });
}, },
node: function() { node: function() {
var a, op, span; var a, span;
op = this.posts[this]; if (!(span = $('.summary', this.OP.nodes.root.parentNode))) {
if (!(span = $('.summary', op.nodes.root.parentNode))) {
return; return;
} }
a = $.el('a', { a = $.el('a', {
@ -4818,7 +4816,7 @@
}, },
toggle: function(thread) { toggle: function(thread) {
var a, inlined, num, replies, reply, text, threadRoot, url, _i, _len; var a, inlined, num, replies, reply, text, threadRoot, url, _i, _len;
threadRoot = thread.posts[thread].nodes.root.parentNode; threadRoot = thread.OP.nodes.root.parentNode;
url = "//api.4chan.org/" + thread.board + "/res/" + thread + ".json"; url = "//api.4chan.org/" + thread.board + "/res/" + thread + ".json";
a = $('.summary', threadRoot); a = $('.summary', threadRoot);
text = a.textContent; text = a.textContent;
@ -4828,14 +4826,14 @@
$.cache(url, function() { $.cache(url, function() {
return ExpandThread.parse(this, thread, a); return ExpandThread.parse(this, thread, a);
}); });
ExpandComment.expand(thread.posts[thread]); ExpandComment.expand(thread.OP);
break; break;
case '×': case '×':
a.textContent = text.replace('× Loading...', '+'); a.textContent = text.replace('× Loading...', '+');
break; break;
case '-': case '-':
a.textContent = text.replace('-', '+'); a.textContent = text.replace('-', '+');
ExpandComment.contract(thread.posts[thread]); ExpandComment.contract(thread.OP);
num = (function() { num = (function() {
switch (g.BOARD) { switch (g.BOARD) {
case 'b': case 'b':
@ -5137,7 +5135,7 @@
node: function() { node: function() {
var input, _i, _len, _ref; var input, _i, _len, _ref;
ThreadUpdater.thread = this; ThreadUpdater.thread = this;
ThreadUpdater.root = this.posts[this].nodes.root.parentNode; ThreadUpdater.root = this.OP.nodes.root.parentNode;
ThreadUpdater.lastPost = +ThreadUpdater.root.lastElementChild.id.match(/\d+/)[0]; ThreadUpdater.lastPost = +ThreadUpdater.root.lastElementChild.id.match(/\d+/)[0];
ThreadUpdater.outdateCount = 0; ThreadUpdater.outdateCount = 0;
ThreadUpdater.lastModified = '0'; ThreadUpdater.lastModified = '0';
@ -5419,13 +5417,12 @@
}); });
}, },
node: function() { node: function() {
var favicon, op; var favicon;
op = this.posts[this];
favicon = $.el('img', { favicon = $.el('img', {
className: 'favicon' className: 'favicon'
}); });
$.on(favicon, 'click', ThreadWatcher.cb.toggle); $.on(favicon, 'click', ThreadWatcher.cb.toggle);
$.before($('input', op.nodes.post), favicon); $.before($('input', this.OP.nodes.post), favicon);
if (g.VIEW === 'thread' && this.ID === $.get('AutoWatch', 0)) { if (g.VIEW === 'thread' && this.ID === $.get('AutoWatch', 0)) {
ThreadWatcher.watch(this); ThreadWatcher.watch(this);
return $["delete"]('AutoWatch'); return $["delete"]('AutoWatch');
@ -5436,7 +5433,7 @@
return $.add(d.body, ThreadWatcher.dialog); return $.add(d.body, ThreadWatcher.dialog);
}, },
refresh: function(watched) { refresh: function(watched) {
var ID, board, div, favicon, id, link, nodes, op, props, thread, x, _ref, _ref1; var ID, board, div, favicon, id, link, nodes, props, thread, x, _ref, _ref1;
watched || (watched = $.get('WatchedThreads', {})); watched || (watched = $.get('WatchedThreads', {}));
nodes = [$('.move', ThreadWatcher.dialog)]; nodes = [$('.move', ThreadWatcher.dialog)];
for (board in watched) { for (board in watched) {
@ -5461,8 +5458,7 @@
_ref1 = g.BOARD.threads; _ref1 = g.BOARD.threads;
for (ID in _ref1) { for (ID in _ref1) {
thread = _ref1[ID]; thread = _ref1[ID];
op = thread.posts[thread]; favicon = $('.favicon', thread.OP.nodes.post);
favicon = $('.favicon', op.nodes.post);
favicon.src = ID in watched ? Favicon["default"] : Favicon.empty; favicon.src = ID in watched ? Favicon["default"] : Favicon.empty;
} }
}, },
@ -5488,9 +5484,7 @@
} }
}, },
toggle: function(thread) { toggle: function(thread) {
var op; if ($('.favicon', thread.OP.nodes.post).src === Favicon.empty) {
op = thread.posts[thread];
if ($('.favicon', op.nodes.post).src === Favicon.empty) {
return ThreadWatcher.watch(thread); return ThreadWatcher.watch(thread);
} else { } else {
return ThreadWatcher.unwatch(thread.board, thread.ID); return ThreadWatcher.unwatch(thread.board, thread.ID);
@ -6599,7 +6593,11 @@
this.file.dimensions = this.file.text.textContent.match(/\d+x\d+/)[0]; this.file.dimensions = this.file.text.textContent.match(/\d+x\d+/)[0];
} }
} }
this.isReply = $.hasClass(post, 'reply'); if (!(this.isReply = $.hasClass(post, 'reply'))) {
this.thread.OP = this;
this.thread.isSticky = !!$('.stickyIcon', this.nodes.info);
this.thread.isClosed = !!$('.closedIcon', this.nodes.info);
}
this.clones = []; this.clones = [];
g.posts["" + board + "." + this] = thread.posts[this] = board.posts[this] = this; g.posts["" + board + "." + this] = thread.posts[this] = board.posts[this] = this;
if (that.isArchived) { if (that.isArchived) {

View File

@ -889,7 +889,7 @@ ThreadHiding =
if data = ThreadHiding.hiddenThreads.threads[@] if data = ThreadHiding.hiddenThreads.threads[@]
ThreadHiding.hide @, data.makeStub ThreadHiding.hide @, data.makeStub
return unless Conf['Hiding Buttons'] return unless Conf['Hiding Buttons']
$.prepend @posts[@].nodes.root, ThreadHiding.makeButton @, 'hide' $.prepend @OP.nodes.root, ThreadHiding.makeButton @, 'hide'
getHiddenThreads: -> getHiddenThreads: ->
hiddenThreads = $.get "hiddenThreads.#{g.BOARD}" hiddenThreads = $.get "hiddenThreads.#{g.BOARD}"
@ -981,8 +981,7 @@ ThreadHiding =
hide: (thread, makeStub=Conf['Stubs']) -> hide: (thread, makeStub=Conf['Stubs']) ->
return if thread.hidden return if thread.hidden
op = thread.posts[thread] threadRoot = thread.OP.nodes.root.parentNode
threadRoot = op.nodes.root.parentNode
threadRoot.hidden = thread.isHidden = true threadRoot.hidden = thread.isHidden = true
unless makeStub unless makeStub
@ -1013,7 +1012,7 @@ ThreadHiding =
if thread.stub if thread.stub
$.rm thread.stub $.rm thread.stub
delete thread.stub delete thread.stub
threadRoot = thread.posts[thread].nodes.root.parentNode threadRoot = thread.OP.nodes.root.parentNode
threadRoot.nextElementSibling.hidden = threadRoot.nextElementSibling.hidden =
threadRoot.hidden = thread.isHidden = false threadRoot.hidden = thread.isHidden = false
@ -1948,12 +1947,12 @@ Build =
sticky = sticky =
if isSticky if isSticky
' <img src=//static.4chan.org/image/sticky.gif alt=Sticky title=Sticky style="height:16px;width:16px">' ' <img src=//static.4chan.org/image/sticky.gif alt=Sticky title=Sticky class=stickyIcon>'
else else
'' ''
closed = closed =
if isClosed if isClosed
' <img src=//static.4chan.org/image/closed.gif alt=Closed title=Closed style="height:16px;width:16px">' ' <img src=//static.4chan.org/image/closed.gif alt=Closed title=Closed class=closedIcon>'
else else
'' ''
@ -2022,11 +2021,11 @@ Build =
Get = Get =
threadExcerpt: (thread) -> threadExcerpt: (thread) ->
op = thread.posts[thread] {OP} = thread
excerpt = op.info.subject?.trim() or excerpt = OP.info.subject?.trim() or
op.info.comment.replace(/\n+/g, ' // ') or OP.info.comment.replace(/\n+/g, ' // ') or
Conf['Anonymize'] and 'Anonymous' or Conf['Anonymize'] and 'Anonymous' or
$('.nameBlock', op.nodes.info).textContent.trim() $('.nameBlock', OP.nodes.info).textContent.trim()
"/#{thread.board}/ - #{excerpt}" "/#{thread.board}/ - #{excerpt}"
postFromRoot: (root) -> postFromRoot: (root) ->
link = $ 'a[title="Highlight this post"]', root link = $ 'a[title="Highlight this post"]', root
@ -3182,8 +3181,7 @@ ExpandThread =
name: 'Thread Expansion' name: 'Thread Expansion'
cb: @node cb: @node
node: -> node: ->
op = @posts[@] return unless span = $ '.summary', @OP.nodes.root.parentNode
return unless span = $ '.summary', op.nodes.root.parentNode
a = $.el 'a', a = $.el 'a',
textContent: "+ #{span.textContent}" textContent: "+ #{span.textContent}"
className: 'summary' className: 'summary'
@ -3196,7 +3194,7 @@ ExpandThread =
ExpandThread.toggle op.thread ExpandThread.toggle op.thread
toggle: (thread) -> toggle: (thread) ->
threadRoot = thread.posts[thread].nodes.root.parentNode threadRoot = thread.OP.nodes.root.parentNode
url = "//api.4chan.org/#{thread.board}/res/#{thread}.json" url = "//api.4chan.org/#{thread.board}/res/#{thread}.json"
a = $ '.summary', threadRoot a = $ '.summary', threadRoot
@ -3205,14 +3203,14 @@ ExpandThread =
when '+' when '+'
a.textContent = text.replace '+', '× Loading...' a.textContent = text.replace '+', '× Loading...'
$.cache url, -> ExpandThread.parse @, thread, a $.cache url, -> ExpandThread.parse @, thread, a
ExpandComment.expand thread.posts[thread] ExpandComment.expand thread.OP
when '×' when '×'
a.textContent = text.replace '× Loading...', '+' a.textContent = text.replace '× Loading...', '+'
when '-' when '-'
a.textContent = text.replace '-', '+' a.textContent = text.replace '-', '+'
ExpandComment.contract thread.posts[thread] ExpandComment.contract thread.OP
#goddamit moot #goddamit moot
num = switch g.BOARD num = switch g.BOARD
# XXX boards config # XXX boards config
@ -3459,7 +3457,7 @@ ThreadUpdater =
node: -> node: ->
ThreadUpdater.thread = @ ThreadUpdater.thread = @
ThreadUpdater.root = @posts[@].nodes.root.parentNode ThreadUpdater.root = @OP.nodes.root.parentNode
ThreadUpdater.lastPost = +ThreadUpdater.root.lastElementChild.id.match(/\d+/)[0] ThreadUpdater.lastPost = +ThreadUpdater.root.lastElementChild.id.match(/\d+/)[0]
ThreadUpdater.outdateCount = 0 ThreadUpdater.outdateCount = 0
ThreadUpdater.lastModified = '0' ThreadUpdater.lastModified = '0'
@ -3688,11 +3686,10 @@ ThreadWatcher =
cb: @node cb: @node
node: -> node: ->
op = @posts[@]
favicon = $.el 'img', favicon = $.el 'img',
className: 'favicon' className: 'favicon'
$.on favicon, 'click', ThreadWatcher.cb.toggle $.on favicon, 'click', ThreadWatcher.cb.toggle
$.before $('input', op.nodes.post), favicon $.before $('input', @OP.nodes.post), favicon
if g.VIEW is 'thread' and @ID is $.get 'AutoWatch', 0 if g.VIEW is 'thread' and @ID is $.get 'AutoWatch', 0
ThreadWatcher.watch @ ThreadWatcher.watch @
$.delete 'AutoWatch' $.delete 'AutoWatch'
@ -3722,8 +3719,7 @@ ThreadWatcher =
watched = watched[g.BOARD] or {} watched = watched[g.BOARD] or {}
for ID, thread of g.BOARD.threads for ID, thread of g.BOARD.threads
op = thread.posts[thread] favicon = $ '.favicon', thread.OP.nodes.post
favicon = $ '.favicon', op.nodes.post
favicon.src = if ID of watched favicon.src = if ID of watched
Favicon.default Favicon.default
else else
@ -3745,8 +3741,7 @@ ThreadWatcher =
ThreadWatcher.watch g.BOARD.threads[threadID] ThreadWatcher.watch g.BOARD.threads[threadID]
toggle: (thread) -> toggle: (thread) ->
op = thread.posts[thread] if $('.favicon', thread.OP.nodes.post).src is Favicon.empty
if $('.favicon', op.nodes.post).src is Favicon.empty
ThreadWatcher.watch thread ThreadWatcher.watch thread
else else
ThreadWatcher.unwatch thread.board, thread.ID ThreadWatcher.unwatch thread.board, thread.ID

View File

@ -101,7 +101,11 @@ class Post
if @file.isImage = /(jpg|png|gif)$/i.test @file.name if @file.isImage = /(jpg|png|gif)$/i.test @file.name
@file.dimensions = @file.text.textContent.match(/\d+x\d+/)[0] @file.dimensions = @file.text.textContent.match(/\d+x\d+/)[0]
@isReply = $.hasClass post, 'reply' unless @isReply = $.hasClass post, 'reply'
@thread.OP = @
@thread.isSticky = !!$ '.stickyIcon', @nodes.info
@thread.isClosed = !!$ '.closedIcon', @nodes.info
@clones = [] @clones = []
g.posts["#{board}.#{@}"] = thread.posts[@] = board.posts[@] = @ g.posts["#{board}.#{@}"] = thread.posts[@] = board.posts[@] = @
@kill() if that.isArchived @kill() if that.isArchived