Move if statement into init

This commit is contained in:
Jordan Bates 2013-05-01 20:11:08 -07:00
parent 73aaf9e27d
commit e33deabf57
5 changed files with 184 additions and 55 deletions

View File

@ -4,6 +4,9 @@ seaweedchan
ihavenoface:
- 4chan Pass link by the style selector
zixaphir:
- Make Allow False Positives option more efficient
### 1.1.8 - 2013-05-01
seaweedchan:
- Fix QR not clearing on submit with Posting Success Notifications disabled

View File

@ -107,7 +107,7 @@
*
*/
(function() {
var $, $$, Anonymize, ArchiveLink, Board, Build, CatalogLinks, Clone, Conf, Config, CustomCSS, DataBoard, DataBoards, DeleteLink, DownloadLink, Emoji, ExpandComment, ExpandThread, FappeTyme, Favicon, FileInfo, Filter, Fourchan, Get, Header, IDColor, ImageExpand, ImageHover, ImageReplace, Keybinds, Linkify, Main, Menu, Nav, Notification, PSAHiding, Polyfill, Post, PostHiding, QR, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, QuoteStrikeThrough, QuoteThreading, QuoteYou, Quotify, Recursive, Redirect, RelativeDates, RemoveSpoilers, Report, ReportLink, RevealSpoilers, Sauce, Settings, Thread, ThreadExcerpt, ThreadHiding, ThreadStats, ThreadUpdater, ThreadWatcher, Time, UI, Unread, c, d, doc, g,
var $, $$, Anonymize, ArchiveLink, BanChecker, Board, Build, CatalogLinks, Clone, Conf, Config, CustomCSS, DataBoard, DataBoards, DeleteLink, DownloadLink, Emoji, ExpandComment, ExpandThread, FappeTyme, Favicon, FileInfo, Filter, Fourchan, Get, Header, IDColor, ImageExpand, ImageHover, ImageReplace, Keybinds, Linkify, Main, Menu, Nav, Notification, PSAHiding, Polyfill, Post, PostHiding, QR, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, QuoteStrikeThrough, QuoteThreading, QuoteYou, Quotify, Recursive, Redirect, RelativeDates, RemoveSpoilers, Report, ReportLink, RevealSpoilers, Sauce, Settings, Thread, ThreadExcerpt, ThreadHiding, ThreadStats, ThreadUpdater, ThreadWatcher, Time, UI, Unread, c, d, doc, g,
__slice = [].slice,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
@ -4107,6 +4107,7 @@
if (g.VIEW === 'catalog' || !Conf['Linkify']) {
return;
}
this.regString = Conf['Allow False Positives'] ? this.regLooseString : this.regStrictString;
if (Conf['Comment Expansion']) {
ExpandComment.callbacks.push(this.node);
}
@ -4115,8 +4116,8 @@
cb: this.node
});
},
regString: /(\b([a-z]+:\/\/|[a-z]{3,}\.[-a-z0-9]+\.[a-z]+|[-a-z0-9]+\.[a-z]|[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|[a-z]{3,}:[a-z0-9?]|[a-z0-9._%+-:]+@[a-z0-9.-]+\.[a-z0-9])[^\s'"]+)/gi,
regAltString: /(((magnet|mailto)\:|(www\.)|(news|(ht|f)tp(s?))\:\/\/){1}\S+)/gi,
regLooseString: /(\b([a-z]+:\/\/|[a-z]{3,}\.[-a-z0-9]+\.[a-z]+|[-a-z0-9]+\.[a-z]|[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|[a-z]{3,}:[a-z0-9?]|[a-z0-9._%+-:]+@[a-z0-9.-]+\.[a-z0-9])[^\s'"]+)/gi,
regStrictString: /(((magnet|mailto)\:|(www\.)|(news|(ht|f)tp(s?))\:\/\/){1}\S+)/gi,
cypher: $.el('div'),
node: function() {
var a, child, cypher, cypherText, data, embed, embedder, embeds, i, index, len, link, links, lookahead, name, next, node, nodes, snapshot, spoiler, text, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _m, _ref, _ref1, _ref2;
@ -4137,17 +4138,10 @@
nodes = $.frag();
node = snapshot.snapshotItem(i);
data = node.data;
if (Conf['Allow False Positives']) {
if (!(node.parentNode && Linkify.regString.test(data))) {
continue;
}
Linkify.regString.lastIndex = 0;
} else {
if (!(node.parentNode && Linkify.regAltString.test(data))) {
continue;
}
Linkify.regAltString.lastIndex = 0;
if (!(node.parentNode && Linkify.regString.test(data))) {
continue;
}
Linkify.regString.lastIndex = 0;
cypherText = [];
if (next = node.nextSibling) {
cypher.textContent = node.textContent;
@ -4169,7 +4163,7 @@
if (cypherText.length) {
data = cypherText.join('');
}
links = Conf['Allow False Positives'] ? data.match(Linkify.regString) : data.match(Linkify.regAltString);
links = data.match(Linkify.regString);
for (_j = 0, _len1 = links.length; _j < _len1; _j++) {
link = links[_j];
index = data.indexOf(link);
@ -7821,6 +7815,56 @@
}
};
BanChecker = {
init: function() {
var _this = this;
if (!Conf['Check for Bans']) {
return;
}
return $.ready(function() {
return _this.load();
});
},
load: function() {
this.url = 'https://www.4chan.org/banned';
return $.ajax(this.url, {
onloadend: function() {
var ban, board, err, tmpDoc;
if (this.status === 200 || 304) {
tmpDoc = d.implementation.createHTMLDocument('');
tmpDoc.documentElement.innerHTML = this.response;
if (ban = $('.banType', tmpDoc)) {
board = $('.board', tmpDoc).innerHTML;
err = $.el('span', {
innerHTML: ban.textContent.toLowerCase() === 'banned' ? ("You are banned on " + board + "! ;_;<br>") + "Click <a href=//www.4chan.org/banned target=_blank>here</a> to see the reason." : ("You were issued a warning on " + board + " as " + ($('.nameBlock', tmpDoc).innerHTML) + ".<br>") + ("Reason: " + ($('.reason', tmpDoc).innerHTML))
});
}
if (err) {
BanChecker.error(err);
}
}
}
});
},
error: function(err) {
var el;
if (typeof err === 'string') {
el = $.tn(err);
} else {
el = err;
el.removeAttribute('style');
}
if (d.hidden) {
alert(el.textContent);
}
return BanChecker.notifications.push(new Notification('warning', el));
},
notifications: []
};
CatalogLinks = {
init: function() {
var el, input;

View File

@ -107,7 +107,7 @@
*
*/
(function() {
var $, $$, Anonymize, ArchiveLink, Board, Build, CatalogLinks, Clone, Conf, Config, CustomCSS, DataBoard, DataBoards, DeleteLink, DownloadLink, Emoji, ExpandComment, ExpandThread, FappeTyme, Favicon, FileInfo, Filter, Fourchan, Get, Header, IDColor, ImageExpand, ImageHover, ImageReplace, Keybinds, Linkify, Main, Menu, Nav, Notification, PSAHiding, Polyfill, Post, PostHiding, QR, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, QuoteStrikeThrough, QuoteThreading, QuoteYou, Quotify, Recursive, Redirect, RelativeDates, RemoveSpoilers, Report, ReportLink, RevealSpoilers, Sauce, Settings, Thread, ThreadExcerpt, ThreadHiding, ThreadStats, ThreadUpdater, ThreadWatcher, Time, UI, Unread, c, d, doc, g,
var $, $$, Anonymize, ArchiveLink, BanChecker, Board, Build, CatalogLinks, Clone, Conf, Config, CustomCSS, DataBoard, DataBoards, DeleteLink, DownloadLink, Emoji, ExpandComment, ExpandThread, FappeTyme, Favicon, FileInfo, Filter, Fourchan, Get, Header, IDColor, ImageExpand, ImageHover, ImageReplace, Keybinds, Linkify, Main, Menu, Nav, Notification, PSAHiding, Polyfill, Post, PostHiding, QR, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, QuoteStrikeThrough, QuoteThreading, QuoteYou, Quotify, Recursive, Redirect, RelativeDates, RemoveSpoilers, Report, ReportLink, RevealSpoilers, Sauce, Settings, Thread, ThreadExcerpt, ThreadHiding, ThreadStats, ThreadUpdater, ThreadWatcher, Time, UI, Unread, c, d, doc, g,
__slice = [].slice,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
@ -4103,6 +4103,7 @@
if (g.VIEW === 'catalog' || !Conf['Linkify']) {
return;
}
this.regString = Conf['Allow False Positives'] ? this.regLooseString : this.regStrictString;
if (Conf['Comment Expansion']) {
ExpandComment.callbacks.push(this.node);
}
@ -4111,8 +4112,8 @@
cb: this.node
});
},
regString: /(\b([a-z]+:\/\/|[a-z]{3,}\.[-a-z0-9]+\.[a-z]+|[-a-z0-9]+\.[a-z]|[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|[a-z]{3,}:[a-z0-9?]|[a-z0-9._%+-:]+@[a-z0-9.-]+\.[a-z0-9])[^\s'"]+)/gi,
regAltString: /(((magnet|mailto)\:|(www\.)|(news|(ht|f)tp(s?))\:\/\/){1}\S+)/gi,
regLooseString: /(\b([a-z]+:\/\/|[a-z]{3,}\.[-a-z0-9]+\.[a-z]+|[-a-z0-9]+\.[a-z]|[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|[a-z]{3,}:[a-z0-9?]|[a-z0-9._%+-:]+@[a-z0-9.-]+\.[a-z0-9])[^\s'"]+)/gi,
regStrictString: /(((magnet|mailto)\:|(www\.)|(news|(ht|f)tp(s?))\:\/\/){1}\S+)/gi,
cypher: $.el('div'),
node: function() {
var a, child, cypher, cypherText, data, embed, embedder, embeds, i, index, len, link, links, lookahead, name, next, node, nodes, snapshot, spoiler, text, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _m, _ref, _ref1, _ref2;
@ -4133,17 +4134,10 @@
nodes = $.frag();
node = snapshot.snapshotItem(i);
data = node.data;
if (Conf['Allow False Positives']) {
if (!(node.parentNode && Linkify.regString.test(data))) {
continue;
}
Linkify.regString.lastIndex = 0;
} else {
if (!(node.parentNode && Linkify.regAltString.test(data))) {
continue;
}
Linkify.regAltString.lastIndex = 0;
if (!(node.parentNode && Linkify.regString.test(data))) {
continue;
}
Linkify.regString.lastIndex = 0;
cypherText = [];
if (next = node.nextSibling) {
cypher.textContent = node.textContent;
@ -4165,7 +4159,7 @@
if (cypherText.length) {
data = cypherText.join('');
}
links = Conf['Allow False Positives'] ? data.match(Linkify.regString) : data.match(Linkify.regAltString);
links = data.match(Linkify.regString);
for (_j = 0, _len1 = links.length; _j < _len1; _j++) {
link = links[_j];
index = data.indexOf(link);
@ -7842,6 +7836,56 @@
}
};
BanChecker = {
init: function() {
var _this = this;
if (!Conf['Check for Bans']) {
return;
}
return $.ready(function() {
return _this.load();
});
},
load: function() {
this.url = 'https://www.4chan.org/banned';
return $.ajax(this.url, {
onloadend: function() {
var ban, board, err, tmpDoc;
if (this.status === 200 || 304) {
tmpDoc = d.implementation.createHTMLDocument('');
tmpDoc.documentElement.innerHTML = this.response;
if (ban = $('.banType', tmpDoc)) {
board = $('.board', tmpDoc).innerHTML;
err = $.el('span', {
innerHTML: ban.textContent.toLowerCase() === 'banned' ? ("You are banned on " + board + "! ;_;<br>") + "Click <a href=//www.4chan.org/banned target=_blank>here</a> to see the reason." : ("You were issued a warning on " + board + " as " + ($('.nameBlock', tmpDoc).innerHTML) + ".<br>") + ("Reason: " + ($('.reason', tmpDoc).innerHTML))
});
}
if (err) {
BanChecker.error(err);
}
}
}
});
},
error: function(err) {
var el;
if (typeof err === 'string') {
el = $.tn(err);
} else {
el = err;
el.removeAttribute('style');
}
if (d.hidden) {
alert(el.textContent);
}
return BanChecker.notifications.push(new Notification('warning', el));
},
notifications: []
};
CatalogLinks = {
init: function() {
var el, input;

View File

@ -88,7 +88,7 @@
*
*/
(function() {
var $, $$, Anonymize, ArchiveLink, Board, Build, CatalogLinks, Clone, Conf, Config, CustomCSS, DataBoard, DataBoards, DeleteLink, DownloadLink, Emoji, ExpandComment, ExpandThread, FappeTyme, Favicon, FileInfo, Filter, Fourchan, Get, Header, IDColor, ImageExpand, ImageHover, ImageReplace, Keybinds, Linkify, Main, Menu, Nav, Notification, PSAHiding, Polyfill, Post, PostHiding, QR, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, QuoteStrikeThrough, QuoteThreading, QuoteYou, Quotify, Recursive, Redirect, RelativeDates, RemoveSpoilers, Report, ReportLink, RevealSpoilers, Sauce, Settings, Thread, ThreadExcerpt, ThreadHiding, ThreadStats, ThreadUpdater, ThreadWatcher, Time, UI, Unread, c, d, doc, g,
var $, $$, Anonymize, ArchiveLink, BanChecker, Board, Build, CatalogLinks, Clone, Conf, Config, CustomCSS, DataBoard, DataBoards, DeleteLink, DownloadLink, Emoji, ExpandComment, ExpandThread, FappeTyme, Favicon, FileInfo, Filter, Fourchan, Get, Header, IDColor, ImageExpand, ImageHover, ImageReplace, Keybinds, Linkify, Main, Menu, Nav, Notification, PSAHiding, Polyfill, Post, PostHiding, QR, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, QuoteStrikeThrough, QuoteThreading, QuoteYou, Quotify, Recursive, Redirect, RelativeDates, RemoveSpoilers, Report, ReportLink, RevealSpoilers, Sauce, Settings, Thread, ThreadExcerpt, ThreadHiding, ThreadStats, ThreadUpdater, ThreadWatcher, Time, UI, Unread, c, d, doc, g,
__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,
@ -4105,6 +4105,7 @@
if (g.VIEW === 'catalog' || !Conf['Linkify']) {
return;
}
this.regString = Conf['Allow False Positives'] ? this.regLooseString : this.regStrictString;
if (Conf['Comment Expansion']) {
ExpandComment.callbacks.push(this.node);
}
@ -4113,8 +4114,8 @@
cb: this.node
});
},
regString: /(\b([a-z]+:\/\/|[a-z]{3,}\.[-a-z0-9]+\.[a-z]+|[-a-z0-9]+\.[a-z]|[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|[a-z]{3,}:[a-z0-9?]|[a-z0-9._%+-:]+@[a-z0-9.-]+\.[a-z0-9])[^\s'"]+)/gi,
regAltString: /(((magnet|mailto)\:|(www\.)|(news|(ht|f)tp(s?))\:\/\/){1}\S+)/gi,
regLooseString: /(\b([a-z]+:\/\/|[a-z]{3,}\.[-a-z0-9]+\.[a-z]+|[-a-z0-9]+\.[a-z]|[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|[a-z]{3,}:[a-z0-9?]|[a-z0-9._%+-:]+@[a-z0-9.-]+\.[a-z0-9])[^\s'"]+)/gi,
regStrictString: /(((magnet|mailto)\:|(www\.)|(news|(ht|f)tp(s?))\:\/\/){1}\S+)/gi,
cypher: $.el('div'),
node: function() {
var a, child, cypher, cypherText, data, embed, embedder, embeds, i, index, len, link, links, lookahead, name, next, node, nodes, snapshot, spoiler, text, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _m, _ref, _ref1, _ref2;
@ -4135,17 +4136,10 @@
nodes = $.frag();
node = snapshot.snapshotItem(i);
data = node.data;
if (Conf['Allow False Positives']) {
if (!(node.parentNode && Linkify.regString.test(data))) {
continue;
}
Linkify.regString.lastIndex = 0;
} else {
if (!(node.parentNode && Linkify.regAltString.test(data))) {
continue;
}
Linkify.regAltString.lastIndex = 0;
if (!(node.parentNode && Linkify.regString.test(data))) {
continue;
}
Linkify.regString.lastIndex = 0;
cypherText = [];
if (next = node.nextSibling) {
cypher.textContent = node.textContent;
@ -4167,7 +4161,7 @@
if (cypherText.length) {
data = cypherText.join('');
}
links = Conf['Allow False Positives'] ? data.match(Linkify.regString) : data.match(Linkify.regAltString);
links = data.match(Linkify.regString);
for (_j = 0, _len1 = links.length; _j < _len1; _j++) {
link = links[_j];
index = data.indexOf(link);
@ -7825,6 +7819,56 @@
}
};
BanChecker = {
init: function() {
var _this = this;
if (!Conf['Check for Bans']) {
return;
}
return $.ready(function() {
return _this.load();
});
},
load: function() {
this.url = 'https://www.4chan.org/banned';
return $.ajax(this.url, {
onloadend: function() {
var ban, board, err, tmpDoc;
if (this.status === 200 || 304) {
tmpDoc = d.implementation.createHTMLDocument('');
tmpDoc.documentElement.innerHTML = this.response;
if (ban = $('.banType', tmpDoc)) {
board = $('.board', tmpDoc).innerHTML;
err = $.el('span', {
innerHTML: ban.textContent.toLowerCase() === 'banned' ? ("You are banned on " + board + "! ;_;<br>") + "Click <a href=//www.4chan.org/banned target=_blank>here</a> to see the reason." : ("You were issued a warning on " + board + " as " + ($('.nameBlock', tmpDoc).innerHTML) + ".<br>") + ("Reason: " + ($('.reason', tmpDoc).innerHTML))
});
}
if (err) {
BanChecker.error(err);
}
}
}
});
},
error: function(err) {
var el;
if (typeof err === 'string') {
el = $.tn(err);
} else {
el = err;
el.removeAttribute('style');
}
if (d.hidden) {
alert(el.textContent);
}
return BanChecker.notifications.push(new Notification('warning', el));
},
notifications: []
};
CatalogLinks = {
init: function() {
var el, input;

View File

@ -2,6 +2,8 @@ Linkify =
init: ->
return if g.VIEW is 'catalog' or not Conf['Linkify']
@regString = if Conf['Allow False Positives'] then @regLooseString else @regStrictString
if Conf['Comment Expansion']
ExpandComment.callbacks.push @node
@ -9,7 +11,7 @@ Linkify =
name: 'Linkify'
cb: @node
regString: ///(
regLooseString: ///(
\b(
[a-z]+://
|
@ -26,7 +28,7 @@ Linkify =
[^\s'"]+
)///gi
regAltString: ///(((magnet|mailto)\:|(www\.)|(news|(ht|f)tp(s?))\://){1}\S+)///gi
regStrictString: ///(((magnet|mailto)\:|(www\.)|(news|(ht|f)tp(s?))\://){1}\S+)///gi
cypher: $.el 'div'
@ -46,15 +48,10 @@ Linkify =
data = node.data
# Test for valid links
if Conf['Allow False Positives']
continue unless node.parentNode and Linkify.regString.test data
Linkify.regString.lastIndex = 0
continue unless node.parentNode and Linkify.regString.test data
else
continue unless node.parentNode and Linkify.regAltString.test data
Linkify.regAltString.lastIndex = 0
Linkify.regString.lastIndex = 0
cypherText = []
@ -78,10 +75,7 @@ Linkify =
if cypherText.length
data = cypherText.join ''
links = if Conf['Allow False Positives']
data.match Linkify.regString
else
data.match Linkify.regAltString
links = data.match Linkify.regString
for link in links
index = data.indexOf link