Merge branch 'json' -- this was safe and performance friendly, so.

Conflicts:
	builds/appchan-x.user.js
	builds/crx/script.js
This commit is contained in:
Zixaphir 2014-01-07 14:28:47 -07:00
commit bf89175d41
7 changed files with 173 additions and 185 deletions

View File

@ -110,7 +110,7 @@
'use strict'; 'use strict';
(function() { (function() {
var $, $$, Anonymize, ArchiveLink, AutoGIF, Banner, Board, Build, CatalogLinks, Clone, Color, Conf, Config, CustomCSS, DataBoard, DeleteLink, Dice, DownloadLink, Emoji, ExpandComment, ExpandThread, FappeTyme, Favicon, FileInfo, Filter, Fourchan, Gallery, Get, GlobalMessage, Header, IDColor, ImageExpand, ImageHover, ImageLoader, Index, InfiniScroll, JSColor, Keybinds, Linkify, Main, MascotTools, Mascots, Menu, Nav, Notice, PSAHiding, Polyfill, Post, PostHiding, QR, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, QuoteStrikeThrough, QuoteThreading, QuoteYou, Quotify, RandomAccessList, Recursive, Redirect, RelativeDates, RemoveSpoilers, Report, ReportLink, RevealSpoilers, Rice, Sauce, Settings, Style, ThemeTools, Themes, Thread, ThreadExcerpt, ThreadHiding, ThreadStats, ThreadUpdater, ThreadWatcher, Time, UI, Unread, c, d, doc, editMascot, editTheme, g, userNavigation, var $, $$, Anonymize, ArchiveLink, AutoGIF, Banner, Board, Build, Callbacks, CatalogLinks, Clone, Color, Conf, Config, CustomCSS, DataBoard, DeleteLink, Dice, DownloadLink, Emoji, ExpandComment, ExpandThread, FappeTyme, Favicon, FileInfo, Filter, Fourchan, Gallery, Get, GlobalMessage, Header, IDColor, ImageExpand, ImageHover, ImageLoader, Index, InfiniScroll, JSColor, Keybinds, Linkify, Main, MascotTools, Mascots, Menu, Nav, Notice, PSAHiding, Polyfill, Post, PostHiding, QR, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, QuoteStrikeThrough, QuoteThreading, QuoteYou, Quotify, RandomAccessList, Recursive, Redirect, RelativeDates, RemoveSpoilers, Report, ReportLink, RevealSpoilers, Rice, Sauce, Settings, Style, ThemeTools, Themes, Thread, ThreadExcerpt, ThreadHiding, ThreadStats, ThreadUpdater, ThreadWatcher, Time, UI, Unread, c, d, doc, editMascot, editTheme, g, userNavigation,
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }, __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
__slice = [].slice, __slice = [].slice,
__hasProp = {}.hasOwnProperty, __hasProp = {}.hasOwnProperty,
@ -3174,6 +3174,55 @@
return __slice.call(root.querySelectorAll(selector)); return __slice.call(root.querySelectorAll(selector));
}; };
Callbacks = (function() {
function Callbacks() {}
Callbacks.prototype.push = function(_arg) {
var cb, name;
name = _arg.name, cb = _arg.cb;
return this[name] = cb;
};
Callbacks.prototype.clean = function() {
var name;
for (name in this) {
if (this.hasOwnProperty(name)) {
this.rm(name);
}
}
};
Callbacks.prototype.rm = function(name) {
return delete this[name];
};
Callbacks.prototype.execute = function(node) {
var err, errors, name;
for (name in this) {
if (this.hasOwnProperty(name)) {
try {
this[name].call(node);
} catch (_error) {
err = _error;
if (!errors) {
errors = [];
}
errors.push({
message: ['"', name, '" crashed on node No.', node, ' (', node.board, ').'].join(''),
error: err
});
}
}
}
if (errors) {
return Main.handleErrors(errors);
}
};
return Callbacks;
})();
Board = (function() { Board = (function() {
Board.prototype.toString = function() { Board.prototype.toString = function() {
return this.ID; return this.ID;
@ -3191,7 +3240,7 @@
})(); })();
Thread = (function() { Thread = (function() {
Thread.callbacks = []; Thread.callbacks = new Callbacks();
Thread.prototype.toString = function() { Thread.prototype.toString = function() {
return this.ID; return this.ID;
@ -3265,7 +3314,7 @@
})(); })();
Post = (function() { Post = (function() {
Post.callbacks = []; Post.callbacks = new Callbacks();
Post.prototype.toString = function() { Post.prototype.toString = function() {
return this.ID; return this.ID;
@ -16749,90 +16798,40 @@
break; break;
} }
try { try {
localStorage.getItem('4chan-settings'); return localStorage.getItem('4chan-settings');
} catch (_error) { } catch (_error) {
err = _error; err = _error;
new Notice('warning', 'Cookies need to be enabled on 4chan for appchan x to operate properly.', 30); return new Notice('warning', 'Cookies need to be enabled on 4chan for appchan x to operate properly.', 30);
} }
return $.event('4chanXInitFinished');
}, },
callbackNodes: function(klass, nodes) { callbackNodes: function(klass, nodes) {
var callback, err, errors, i, len, node, _i, _len, _ref; var cb, i, node;
len = nodes.length; i = 0;
_ref = klass.callbacks; cb = klass.callbacks;
for (_i = 0, _len = _ref.length; _i < _len; _i++) { while (node = nodes[i++]) {
callback = _ref[_i]; cb.execute(node);
i = 0;
while (i < len) {
node = nodes[i++];
try {
callback.cb.call(node);
} catch (_error) {
err = _error;
if (!errors) {
errors = [];
}
errors.push({
message: "\"" + callback.name + "\" crashed on " + klass.name + " No." + node + " (/" + node.board + "/).",
error: err
});
}
}
}
if (errors) {
return Main.handleErrors(errors);
} }
}, },
callbackNodesDB: function(klass, nodes, cb) { callbackNodesDB: function(klass, nodes, cb) {
var errors, func, i, len, node, queue, softTask; var callbacks, errors, i, len, softTask;
queue = [];
errors = null; errors = null;
func = function(node) { len = 0;
var callback, err, _i, _len, _ref; i = 0;
_ref = klass.callbacks; callbacks = klass.callbacks;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
callback = _ref[_i];
try {
callback.cb.call(node);
} catch (_error) {
err = _error;
if (!errors) {
errors = [];
}
errors.push({
message: "\"" + callback.name + "\" crashed on " + klass.name + " No." + node + " (/" + node.board + "/).",
error: err
});
}
}
if (!queue.length) {
if (errors) {
Main.handleErrors(errors);
}
if (cb) {
return cb();
}
}
};
softTask = function() { softTask = function() {
var node; var node;
node = queue.shift(); node = nodes[i++];
func(node); callbacks.execute(node);
if (!queue.length) { if (len === i && cb) {
return; return cb();
} }
if (!(queue.length % 7)) { if (!(i % 7)) {
return setTimeout(softTask, 0); return setTimeout(softTask, 0);
} else { } else {
return softTask(); return softTask();
} }
}; };
len = nodes.length; len = nodes.length;
i = 0;
while (i < len) {
node = nodes[i++];
queue.push(node);
}
return softTask(); return softTask();
}, },
addCallback: function(e) { addCallback: function(e) {

View File

@ -88,7 +88,7 @@
'use strict'; 'use strict';
(function() { (function() {
var $, $$, Anonymize, ArchiveLink, AutoGIF, Banner, Board, Build, CatalogLinks, Clone, Color, Conf, Config, CustomCSS, DataBoard, DeleteLink, Dice, DownloadLink, Emoji, ExpandComment, ExpandThread, FappeTyme, Favicon, FileInfo, Filter, Fourchan, Gallery, Get, GlobalMessage, Header, IDColor, ImageExpand, ImageHover, ImageLoader, Index, InfiniScroll, JSColor, Keybinds, Linkify, Main, MascotTools, Mascots, Menu, Nav, Notice, PSAHiding, Polyfill, Post, PostHiding, QR, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, QuoteStrikeThrough, QuoteThreading, QuoteYou, Quotify, RandomAccessList, Recursive, Redirect, RelativeDates, RemoveSpoilers, Report, ReportLink, RevealSpoilers, Rice, Sauce, Settings, Style, ThemeTools, Themes, Thread, ThreadExcerpt, ThreadHiding, ThreadStats, ThreadUpdater, ThreadWatcher, Time, UI, Unread, c, d, doc, editMascot, editTheme, g, userNavigation, var $, $$, Anonymize, ArchiveLink, AutoGIF, Banner, Board, Build, Callbacks, CatalogLinks, Clone, Color, Conf, Config, CustomCSS, DataBoard, DeleteLink, Dice, DownloadLink, Emoji, ExpandComment, ExpandThread, FappeTyme, Favicon, FileInfo, Filter, Fourchan, Gallery, Get, GlobalMessage, Header, IDColor, ImageExpand, ImageHover, ImageLoader, Index, InfiniScroll, JSColor, Keybinds, Linkify, Main, MascotTools, Mascots, Menu, Nav, Notice, PSAHiding, Polyfill, Post, PostHiding, QR, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, QuoteStrikeThrough, QuoteThreading, QuoteYou, Quotify, RandomAccessList, Recursive, Redirect, RelativeDates, RemoveSpoilers, Report, ReportLink, RevealSpoilers, Rice, Sauce, Settings, Style, ThemeTools, Themes, Thread, ThreadExcerpt, ThreadHiding, ThreadStats, ThreadUpdater, ThreadWatcher, Time, UI, Unread, c, d, doc, editMascot, editTheme, g, userNavigation,
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }, __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
__slice = [].slice, __slice = [].slice,
__hasProp = {}.hasOwnProperty, __hasProp = {}.hasOwnProperty,
@ -3180,6 +3180,55 @@
return __slice.call(root.querySelectorAll(selector)); return __slice.call(root.querySelectorAll(selector));
}; };
Callbacks = (function() {
function Callbacks() {}
Callbacks.prototype.push = function(_arg) {
var cb, name;
name = _arg.name, cb = _arg.cb;
return this[name] = cb;
};
Callbacks.prototype.clean = function() {
var name;
for (name in this) {
if (this.hasOwnProperty(name)) {
this.rm(name);
}
}
};
Callbacks.prototype.rm = function(name) {
return delete this[name];
};
Callbacks.prototype.execute = function(node) {
var err, errors, name;
for (name in this) {
if (this.hasOwnProperty(name)) {
try {
this[name].call(node);
} catch (_error) {
err = _error;
if (!errors) {
errors = [];
}
errors.push({
message: ['"', name, '" crashed on node No.', node, ' (', node.board, ').'].join(''),
error: err
});
}
}
}
if (errors) {
return Main.handleErrors(errors);
}
};
return Callbacks;
})();
Board = (function() { Board = (function() {
Board.prototype.toString = function() { Board.prototype.toString = function() {
return this.ID; return this.ID;
@ -3197,7 +3246,7 @@
})(); })();
Thread = (function() { Thread = (function() {
Thread.callbacks = []; Thread.callbacks = new Callbacks();
Thread.prototype.toString = function() { Thread.prototype.toString = function() {
return this.ID; return this.ID;
@ -3271,7 +3320,7 @@
})(); })();
Post = (function() { Post = (function() {
Post.callbacks = []; Post.callbacks = new Callbacks();
Post.prototype.toString = function() { Post.prototype.toString = function() {
return this.ID; return this.ID;
@ -16724,90 +16773,40 @@
return; return;
} }
try { try {
localStorage.getItem('4chan-settings'); return localStorage.getItem('4chan-settings');
} catch (_error) { } catch (_error) {
err = _error; err = _error;
new Notice('warning', 'Cookies need to be enabled on 4chan for appchan x to operate properly.', 30); return new Notice('warning', 'Cookies need to be enabled on 4chan for appchan x to operate properly.', 30);
} }
return $.event('4chanXInitFinished');
}, },
callbackNodes: function(klass, nodes) { callbackNodes: function(klass, nodes) {
var callback, err, errors, i, len, node, _i, _len, _ref; var cb, i, node;
len = nodes.length; i = 0;
_ref = klass.callbacks; cb = klass.callbacks;
for (_i = 0, _len = _ref.length; _i < _len; _i++) { while (node = nodes[i++]) {
callback = _ref[_i]; cb.execute(node);
i = 0;
while (i < len) {
node = nodes[i++];
try {
callback.cb.call(node);
} catch (_error) {
err = _error;
if (!errors) {
errors = [];
}
errors.push({
message: "\"" + callback.name + "\" crashed on " + klass.name + " No." + node + " (/" + node.board + "/).",
error: err
});
}
}
}
if (errors) {
return Main.handleErrors(errors);
} }
}, },
callbackNodesDB: function(klass, nodes, cb) { callbackNodesDB: function(klass, nodes, cb) {
var errors, func, i, len, node, queue, softTask; var callbacks, errors, i, len, softTask;
queue = [];
errors = null; errors = null;
func = function(node) { len = 0;
var callback, err, _i, _len, _ref; i = 0;
_ref = klass.callbacks; callbacks = klass.callbacks;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
callback = _ref[_i];
try {
callback.cb.call(node);
} catch (_error) {
err = _error;
if (!errors) {
errors = [];
}
errors.push({
message: "\"" + callback.name + "\" crashed on " + klass.name + " No." + node + " (/" + node.board + "/).",
error: err
});
}
}
if (!queue.length) {
if (errors) {
Main.handleErrors(errors);
}
if (cb) {
return cb();
}
}
};
softTask = function() { softTask = function() {
var node; var node;
node = queue.shift(); node = nodes[i++];
func(node); callbacks.execute(node);
if (!queue.length) { if (len === i && cb) {
return; return cb();
} }
if (!(queue.length % 7)) { if (!(i % 7)) {
return setTimeout(softTask, 0); return setTimeout(softTask, 0);
} else { } else {
return softTask(); return softTask();
} }
}; };
len = nodes.length; len = nodes.length;
i = 0;
while (i < len) {
node = nodes[i++];
queue.push(node);
}
return softTask(); return softTask();
}, },
addCallback: function(e) { addCallback: function(e) {

View File

@ -231,61 +231,30 @@ Main =
catch err catch err
new Notice 'warning', 'Cookies need to be enabled on 4chan for <%= meta.name %> to operate properly.', 30 new Notice 'warning', 'Cookies need to be enabled on 4chan for <%= meta.name %> to operate properly.', 30
$.event '4chanXInitFinished'
callbackNodes: (klass, nodes) -> callbackNodes: (klass, nodes) ->
# get the nodes' length only once i = 0
len = nodes.length cb = klass.callbacks
for callback in klass.callbacks while node = nodes[i++]
# c.profile callback.name cb.execute node
i = 0 return
while i < len
node = nodes[i++]
try
callback.cb.call node
catch err
errors = [] unless errors
errors.push
message: "\"#{callback.name}\" crashed on #{klass.name} No.#{node} (/#{node.board}/)."
error: err
# c.profileEnd callback.name
Main.handleErrors errors if errors
callbackNodesDB: (klass, nodes, cb) -> callbackNodesDB: (klass, nodes, cb) ->
queue = []
errors = null errors = null
len = 0
i = 0
func = (node) -> {callbacks} = klass
for callback in klass.callbacks
try
callback.cb.call node
catch err
errors = [] unless errors
errors.push
message: "\"#{callback.name}\" crashed on #{klass.name} No.#{node} (/#{node.board}/)."
error: err
# finish
unless queue.length
Main.handleErrors errors if errors
cb() if cb
softTask = -> softTask = ->
node = queue.shift() node = nodes[i++]
func node callbacks.execute node
return unless queue.length return cb() if len is i and cb
unless queue.length % 7 unless i % 7
setTimeout softTask, 0 setTimeout softTask, 0
else else
softTask() softTask()
# get the nodes' length only once len = nodes.length
len = nodes.length
i = 0
while i < len
node = nodes[i++]
queue.push node
softTask() softTask()
addCallback: (e) -> addCallback: (e) ->

View File

@ -0,0 +1,20 @@
class Callbacks
push: ({name, cb}) -> @[name] = cb
clean: ->
@rm name for name of @ when @hasOwnProperty name
return
rm: (name) -> delete @[name]
execute: (node) ->
for name of @ when @hasOwnProperty name
try
@[name].call node
catch err
errors = [] unless errors
errors.push
message: ['"', name, '" crashed on node No.', node, ' (', node.board, ').'].join('')
error: err
Main.handleErrors errors if errors

View File

@ -1,3 +1,4 @@
<%= grunt.file.read('src/General/lib/callbacks.class') %>
<%= grunt.file.read('src/General/lib/board.class') %> <%= grunt.file.read('src/General/lib/board.class') %>
<%= grunt.file.read('src/General/lib/thread.class') %> <%= grunt.file.read('src/General/lib/thread.class') %>
<%= grunt.file.read('src/General/lib/post.class') %> <%= grunt.file.read('src/General/lib/post.class') %>

View File

@ -1,5 +1,5 @@
class Post class Post
@callbacks = [] @callbacks = new Callbacks()
toString: -> @ID toString: -> @ID
constructor: (root, @thread, @board, that={}) -> constructor: (root, @thread, @board, that={}) ->

View File

@ -1,5 +1,5 @@
class Thread class Thread
@callbacks = [] @callbacks = new Callbacks()
toString: -> @ID toString: -> @ID
constructor: (@ID, @board) -> constructor: (@ID, @board) ->