Tighten up Get.threadFromRoom, Get.contextFromNode

This commit is contained in:
Zixaphir 2014-03-11 11:57:30 -07:00
parent 5db027356e
commit 3f438d55ff
5 changed files with 12 additions and 14 deletions

View File

@ -1,5 +1,5 @@
/*
* 4chan X - Version 1.4.1 - 2014-03-10
* 4chan X - Version 1.4.1 - 2014-03-11
*
* Licensed under the MIT license.
* https://github.com/Spittie/4chan-x/blob/master/LICENSE

View File

@ -24,7 +24,7 @@
// ==/UserScript==
/*
* 4chan X - Version 1.4.1 - 2014-03-10
* 4chan X - Version 1.4.1 - 2014-03-11
*
* Licensed under the MIT license.
* https://github.com/Spittie/4chan-x/blob/master/LICENSE
@ -1087,6 +1087,7 @@
this.thread.OP = this;
this.thread.isSticky = !!$('.stickyIcon', info);
this.thread.isClosed = !!$('.closedIcon', info);
root.parentElement.dataset.fullID = this.fullID;
}
this.info = {};
if (subject = $('.subject', info)) {
@ -3844,7 +3845,7 @@
return "/" + thread.board + "/ - " + excerpt;
},
threadFromRoot: function(root) {
return g.threads["" + g.BOARD + "." + root.id.slice(1)];
return g.threads[root.dataset.fullID];
},
threadFromNode: function(node) {
return Get.threadFromRoot($.x('ancestor::div[@class="thread"]', node));
@ -3862,9 +3863,7 @@
return Get.postFromRoot($.x('ancestor::div[contains(@class,"postContainer")][1]', node));
},
contextFromNode: function(node) {
var snapshot;
snapshot = $.X('ancestor::div[contains(@class,"postContainer")]', node);
return Get.postFromRoot(snapshot.snapshotItem(snapshot.length - 1));
return Get.postFromRoot($.x('ancestor::div[@class="thread"]', node).firstElementChild);
},
postDataFromLink: function(link) {
var boardID, path, postID, threadID, _ref;

View File

@ -1,6 +1,6 @@
// Generated by CoffeeScript
/*
* 4chan X - Version 1.4.1 - 2014-03-10
* 4chan X - Version 1.4.1 - 2014-03-11
*
* Licensed under the MIT license.
* https://github.com/Spittie/4chan-x/blob/master/LICENSE
@ -1141,6 +1141,7 @@
this.thread.OP = this;
this.thread.isSticky = !!$('.stickyIcon', info);
this.thread.isClosed = !!$('.closedIcon', info);
root.parentElement.dataset.fullID = this.fullID;
}
this.info = {};
if (subject = $('.subject', info)) {
@ -3903,7 +3904,7 @@
return "/" + thread.board + "/ - " + excerpt;
},
threadFromRoot: function(root) {
return g.threads["" + g.BOARD + "." + root.id.slice(1)];
return g.threads[root.dataset.fullID];
},
threadFromNode: function(node) {
return Get.threadFromRoot($.x('ancestor::div[@class="thread"]', node));
@ -3921,9 +3922,7 @@
return Get.postFromRoot($.x('ancestor::div[contains(@class,"postContainer")][1]', node));
},
contextFromNode: function(node) {
var snapshot;
snapshot = $.X('ancestor::div[contains(@class,"postContainer")]', node);
return Get.postFromRoot(snapshot.snapshotItem(snapshot.length - 1));
return Get.postFromRoot($.x('ancestor::div[@class="thread"]', node).firstElementChild);
},
postDataFromLink: function(link) {
var boardID, path, postID, threadID, _ref;

View File

@ -8,7 +8,7 @@ Get =
excerpt = "#{excerpt[...67]}..."
"/#{thread.board}/ - #{excerpt}"
threadFromRoot: (root) ->
g.threads["#{g.BOARD}.#{root.id[1..]}"]
g.threads[root.dataset.fullID]
threadFromNode: (node) ->
Get.threadFromRoot $.x 'ancestor::div[@class="thread"]', node
postFromRoot: (root) ->
@ -17,8 +17,7 @@ Get =
postFromNode: (node) ->
Get.postFromRoot $.x 'ancestor::div[contains(@class,"postContainer")][1]', node
contextFromNode: (node) ->
snapshot = $.X 'ancestor::div[contains(@class,"postContainer")]', node
Get.postFromRoot snapshot.snapshotItem(snapshot.length - 1)
Get.postFromRoot $.x('ancestor::div[@class="thread"]', node).firstElementChild
postDataFromLink: (link) ->
if link.hostname is 'boards.4chan.org'
path = link.pathname.split '/'

View File

@ -23,6 +23,7 @@ class Post
@thread.OP = @
@thread.isSticky = !!$ '.stickyIcon', info
@thread.isClosed = !!$ '.closedIcon', info
root.parentElement.dataset.fullID = @fullID
@info = {}
if subject = $ '.subject', info