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';
(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; },
__slice = [].slice,
__hasProp = {}.hasOwnProperty,
@ -3174,6 +3174,55 @@
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.prototype.toString = function() {
return this.ID;
@ -3191,7 +3240,7 @@
})();
Thread = (function() {
Thread.callbacks = [];
Thread.callbacks = new Callbacks();
Thread.prototype.toString = function() {
return this.ID;
@ -3265,7 +3314,7 @@
})();
Post = (function() {
Post.callbacks = [];
Post.callbacks = new Callbacks();
Post.prototype.toString = function() {
return this.ID;
@ -16749,90 +16798,40 @@
break;
}
try {
localStorage.getItem('4chan-settings');
return localStorage.getItem('4chan-settings');
} catch (_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) {
var callback, err, errors, i, len, node, _i, _len, _ref;
len = nodes.length;
_ref = klass.callbacks;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
callback = _ref[_i];
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);
var cb, i, node;
i = 0;
cb = klass.callbacks;
while (node = nodes[i++]) {
cb.execute(node);
}
},
callbackNodesDB: function(klass, nodes, cb) {
var errors, func, i, len, node, queue, softTask;
queue = [];
var callbacks, errors, i, len, softTask;
errors = null;
func = function(node) {
var callback, err, _i, _len, _ref;
_ref = 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();
}
}
};
len = 0;
i = 0;
callbacks = klass.callbacks;
softTask = function() {
var node;
node = queue.shift();
func(node);
if (!queue.length) {
return;
node = nodes[i++];
callbacks.execute(node);
if (len === i && cb) {
return cb();
}
if (!(queue.length % 7)) {
if (!(i % 7)) {
return setTimeout(softTask, 0);
} else {
return softTask();
}
};
len = nodes.length;
i = 0;
while (i < len) {
node = nodes[i++];
queue.push(node);
}
return softTask();
},
addCallback: function(e) {

View File

@ -88,7 +88,7 @@
'use strict';
(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; },
__slice = [].slice,
__hasProp = {}.hasOwnProperty,
@ -3180,6 +3180,55 @@
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.prototype.toString = function() {
return this.ID;
@ -3197,7 +3246,7 @@
})();
Thread = (function() {
Thread.callbacks = [];
Thread.callbacks = new Callbacks();
Thread.prototype.toString = function() {
return this.ID;
@ -3271,7 +3320,7 @@
})();
Post = (function() {
Post.callbacks = [];
Post.callbacks = new Callbacks();
Post.prototype.toString = function() {
return this.ID;
@ -16724,90 +16773,40 @@
return;
}
try {
localStorage.getItem('4chan-settings');
return localStorage.getItem('4chan-settings');
} catch (_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) {
var callback, err, errors, i, len, node, _i, _len, _ref;
len = nodes.length;
_ref = klass.callbacks;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
callback = _ref[_i];
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);
var cb, i, node;
i = 0;
cb = klass.callbacks;
while (node = nodes[i++]) {
cb.execute(node);
}
},
callbackNodesDB: function(klass, nodes, cb) {
var errors, func, i, len, node, queue, softTask;
queue = [];
var callbacks, errors, i, len, softTask;
errors = null;
func = function(node) {
var callback, err, _i, _len, _ref;
_ref = 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();
}
}
};
len = 0;
i = 0;
callbacks = klass.callbacks;
softTask = function() {
var node;
node = queue.shift();
func(node);
if (!queue.length) {
return;
node = nodes[i++];
callbacks.execute(node);
if (len === i && cb) {
return cb();
}
if (!(queue.length % 7)) {
if (!(i % 7)) {
return setTimeout(softTask, 0);
} else {
return softTask();
}
};
len = nodes.length;
i = 0;
while (i < len) {
node = nodes[i++];
queue.push(node);
}
return softTask();
},
addCallback: function(e) {

View File

@ -231,61 +231,30 @@ Main =
catch err
new Notice 'warning', 'Cookies need to be enabled on 4chan for <%= meta.name %> to operate properly.', 30
$.event '4chanXInitFinished'
callbackNodes: (klass, nodes) ->
# get the nodes' length only once
len = nodes.length
for callback in klass.callbacks
# c.profile callback.name
i = 0
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
i = 0
cb = klass.callbacks
while node = nodes[i++]
cb.execute node
return
callbackNodesDB: (klass, nodes, cb) ->
queue = []
errors = null
len = 0
i = 0
func = (node) ->
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
{callbacks} = klass
softTask = ->
node = queue.shift()
func node
return unless queue.length
unless queue.length % 7
softTask = ->
node = nodes[i++]
callbacks.execute node
return cb() if len is i and cb
unless i % 7
setTimeout softTask, 0
else
softTask()
# get the nodes' length only once
len = nodes.length
i = 0
while i < len
node = nodes[i++]
queue.push node
len = nodes.length
softTask()
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/thread.class') %>
<%= grunt.file.read('src/General/lib/post.class') %>

View File

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

View File

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