mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-08-17 11:30:54 +00:00
Merge branch 'master' into fix_initial_setup
Conflicts: README.md
This commit is contained in:
commit
8ed9460319
5 changed files with 40 additions and 153 deletions
27
script.js
27
script.js
|
@ -4589,22 +4589,27 @@ FFZ.get_capitalization = function(name, callback) {
|
|||
// ---------------------
|
||||
|
||||
FFZ.prototype._remove_banned = function(tokens) {
|
||||
var banned_words = _.union(['j.mp', 'bit.ly'], this.settings.banned_words);
|
||||
if ( ! banned_words || ! banned_words.length )
|
||||
var banned_words = this.settings.banned_words,
|
||||
banned_links = ['j.mp', 'bit.ly'],
|
||||
|
||||
has_banned_words = banned_words && banned_words.length;
|
||||
|
||||
if ( !has_banned_words && (! banned_links || ! banned_links.length) )
|
||||
return tokens;
|
||||
|
||||
if ( typeof tokens == "string" )
|
||||
tokens = [tokens];
|
||||
|
||||
var regex = FFZ._words_to_regex(banned_words),
|
||||
link_regex = FFZ._words_to_regex(banned_links),
|
||||
new_tokens = [];
|
||||
|
||||
for(var i=0; i < tokens.length; i++) {
|
||||
var token = tokens[i];
|
||||
if ( ! _.isString(token ) ) {
|
||||
if ( token.emoticonSrc && regex.test(token.altText) )
|
||||
if ( token.emoticonSrc && has_banned_words && regex.test(token.altText) )
|
||||
new_tokens.push(token.altText.replace(regex, "$1***"));
|
||||
else if ( token.isLink && regex.test(token.href) )
|
||||
else if ( token.isLink && has_banned_words && regex.test(token.href) )
|
||||
new_tokens.push({
|
||||
isLink: true,
|
||||
href: token.href,
|
||||
|
@ -4612,10 +4617,18 @@ FFZ.prototype._remove_banned = function(tokens) {
|
|||
isLong: false,
|
||||
censoredHref: token.href.replace(regex, "$1***")
|
||||
});
|
||||
else if ( token.isLink && link_regex.test(token.href) )
|
||||
new_tokens.push({
|
||||
isLink: true,
|
||||
href: token.href,
|
||||
isDeleted: true,
|
||||
isLong: false,
|
||||
censoredHref: token.href.replace(link_regex, "$1***")
|
||||
});
|
||||
else
|
||||
new_tokens.push(token);
|
||||
|
||||
} else
|
||||
} else if ( has_banned_words )
|
||||
new_tokens.push(token.replace(regex, "$1***"));
|
||||
}
|
||||
|
||||
|
@ -7674,8 +7687,6 @@ require('./ember/moderation-card');
|
|||
require('./ember/chat-input');
|
||||
//require('./ember/teams');
|
||||
|
||||
// Analytics: require('./tracking');
|
||||
|
||||
require('./debug');
|
||||
|
||||
require('./ext/betterttv');
|
||||
|
@ -7866,8 +7877,6 @@ FFZ.prototype.init_ember = function(delay) {
|
|||
this.setup_emoticons();
|
||||
this.setup_badges();
|
||||
|
||||
//this.setup_piwik();
|
||||
|
||||
//this.setup_router();
|
||||
this.setup_colors();
|
||||
this.setup_tokenization();
|
||||
|
|
8
script.min.js
vendored
8
script.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -824,22 +824,27 @@ FFZ.get_capitalization = function(name, callback) {
|
|||
// ---------------------
|
||||
|
||||
FFZ.prototype._remove_banned = function(tokens) {
|
||||
var banned_words = _.union(['j.mp', 'bit.ly'], this.settings.banned_words);
|
||||
if ( ! banned_words || ! banned_words.length )
|
||||
var banned_words = this.settings.banned_words,
|
||||
banned_links = ['j.mp', 'bit.ly'],
|
||||
|
||||
has_banned_words = banned_words && banned_words.length;
|
||||
|
||||
if ( !has_banned_words && (! banned_links || ! banned_links.length) )
|
||||
return tokens;
|
||||
|
||||
if ( typeof tokens == "string" )
|
||||
tokens = [tokens];
|
||||
|
||||
var regex = FFZ._words_to_regex(banned_words),
|
||||
link_regex = FFZ._words_to_regex(banned_links),
|
||||
new_tokens = [];
|
||||
|
||||
for(var i=0; i < tokens.length; i++) {
|
||||
var token = tokens[i];
|
||||
if ( ! _.isString(token ) ) {
|
||||
if ( token.emoticonSrc && regex.test(token.altText) )
|
||||
if ( token.emoticonSrc && has_banned_words && regex.test(token.altText) )
|
||||
new_tokens.push(token.altText.replace(regex, "$1***"));
|
||||
else if ( token.isLink && regex.test(token.href) )
|
||||
else if ( token.isLink && has_banned_words && regex.test(token.href) )
|
||||
new_tokens.push({
|
||||
isLink: true,
|
||||
href: token.href,
|
||||
|
@ -847,10 +852,18 @@ FFZ.prototype._remove_banned = function(tokens) {
|
|||
isLong: false,
|
||||
censoredHref: token.href.replace(regex, "$1***")
|
||||
});
|
||||
else if ( token.isLink && link_regex.test(token.href) )
|
||||
new_tokens.push({
|
||||
isLink: true,
|
||||
href: token.href,
|
||||
isDeleted: true,
|
||||
isLong: false,
|
||||
censoredHref: token.href.replace(link_regex, "$1***")
|
||||
});
|
||||
else
|
||||
new_tokens.push(token);
|
||||
|
||||
} else
|
||||
} else if ( has_banned_words )
|
||||
new_tokens.push(token.replace(regex, "$1***"));
|
||||
}
|
||||
|
||||
|
|
|
@ -125,8 +125,6 @@ require('./ember/moderation-card');
|
|||
require('./ember/chat-input');
|
||||
//require('./ember/teams');
|
||||
|
||||
// Analytics: require('./tracking');
|
||||
|
||||
require('./debug');
|
||||
|
||||
require('./ext/betterttv');
|
||||
|
@ -317,8 +315,6 @@ FFZ.prototype.init_ember = function(delay) {
|
|||
this.setup_emoticons();
|
||||
this.setup_badges();
|
||||
|
||||
//this.setup_piwik();
|
||||
|
||||
//this.setup_router();
|
||||
this.setup_colors();
|
||||
this.setup_tokenization();
|
||||
|
|
131
src/tracking.js
131
src/tracking.js
|
@ -1,131 +0,0 @@
|
|||
var FFZ = window.FrankerFaceZ,
|
||||
constants = require('./constants'),
|
||||
PIWIK = ("https:" == document.location.protocol ? 'https:' : 'http:') + '//sir.stendec.me/ffz_piwik/';
|
||||
|
||||
|
||||
// --------------------
|
||||
// Initialization
|
||||
// --------------------
|
||||
|
||||
FFZ.prototype.setup_piwik = function() {
|
||||
if ( window._paq != undefined ) {
|
||||
this.log("Piwik is already present. Disabling analytics.");
|
||||
this._tracking = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if ( localStorage['ffzTracking'] == "false" ) {
|
||||
this.log("The user has opted out of tracking. Disabling analytics.");
|
||||
this._tracking = false;
|
||||
return;
|
||||
}
|
||||
|
||||
this.log("Initializing Piwik.");
|
||||
this._tracking = true;
|
||||
var _paq = window._paq = [];
|
||||
|
||||
_paq.push(['setSiteId', 1]);
|
||||
_paq.push(['setTrackerUrl', PIWIK + 'piwik.php']);
|
||||
|
||||
if ( this.has_bttv )
|
||||
_paq.push(['setCustomVariable', '3', 'BetterTTV', BetterTTV.info.versionString()]);
|
||||
|
||||
var user = this.get_user(), f = this;
|
||||
if ( user ) {
|
||||
_paq.push(['setCustomVariable', '1', 'Partnered', user.is_partner ? "Yes" : "No"])
|
||||
_paq.push(['setCustomVariable', '2', 'User Type', user.is_staff ? "Staff" : (user.is_admin ? "Admin" : "User")]);
|
||||
_paq.push(['setUserId', user.login]);
|
||||
|
||||
Twitch.api.get("channels/" + user.login)
|
||||
.done(function(data) {
|
||||
if ( data.logo )
|
||||
f.track('setCustomVariable', '4', 'Avatar', data.logo);
|
||||
}).always(function() { f.track_page(); });
|
||||
|
||||
} else
|
||||
this.track_page();
|
||||
|
||||
// If someone turned analytics back ON, track that.
|
||||
if ( localStorage['ffzTracking'] == "true" ) {
|
||||
this.track('trackEvent', 'Analytics', 'Enable');
|
||||
localStorage.removeItem('ffzTracking');
|
||||
}
|
||||
|
||||
var script = document.createElement('script');
|
||||
script.type = 'text/javascript';
|
||||
script.defer = true;
|
||||
script.async = true;
|
||||
script.src = PIWIK + 'piwik.js';
|
||||
document.head.appendChild(script);
|
||||
}
|
||||
|
||||
|
||||
// --------------------
|
||||
// Command
|
||||
// --------------------
|
||||
|
||||
FFZ.chat_commands.analytics = function(room, args) {
|
||||
var enabled, args = args && args.length ? args[0].toLowerCase() : null;
|
||||
if ( args == "y" || args == "yes" || args == "true" || args == "on" )
|
||||
enabled = true;
|
||||
else if ( args == "n" || args == "no" || args == "false" || args == "off" )
|
||||
enabled = false;
|
||||
|
||||
if ( enabled === undefined )
|
||||
return "Analytics are currently " + (localStorage.ffzTracking != "false" ? "enabled." : "disabled.");
|
||||
|
||||
// Track that someone turned off analytics.
|
||||
if ( this._tracking && ! enabled && localStorage.ffzTracking != "false" )
|
||||
this.track('trackEvent', 'Analytics', 'Disable');
|
||||
|
||||
localStorage.ffzTracking = enabled;
|
||||
|
||||
return "Analytics are now " + (enabled ? "enabled" : "disabled") + ". Please refresh your browser.";
|
||||
}
|
||||
|
||||
FFZ.chat_commands.analytics.help = "Usage: /ffz analytics <on|off>\nEnable or disable FrankerFaceZ analytics. We collect some data about your browser and how you use FrankerFaceZ to help us improve the script. Turn off analytics if you'd rather we not.";
|
||||
|
||||
|
||||
|
||||
// --------------------
|
||||
// Tracking Helpers
|
||||
// --------------------
|
||||
|
||||
FFZ.prototype.track = function() {
|
||||
if ( ! this._tracking )
|
||||
return;
|
||||
|
||||
window._paq && _paq.push(Array.prototype.slice.call(arguments));
|
||||
}
|
||||
|
||||
|
||||
FFZ.prototype.track_page = function() {
|
||||
if ( ! this._tracking )
|
||||
return;
|
||||
|
||||
if ( this._old_url )
|
||||
this.track('setReferrerUrl', this._old_url);
|
||||
|
||||
this._old_url = document.location.toString();
|
||||
this.track('setCustomUrl', this._old_url);
|
||||
|
||||
this.track('deleteCustomVariable', '1', 'page');
|
||||
this.track('deleteCustomVariable', '3', 'page');
|
||||
|
||||
var routes = App.__container__.resolve('router:main').router.currentHandlerInfos;
|
||||
if ( ! routes || routes.length == 0 )
|
||||
return;
|
||||
|
||||
var last = routes[routes.length - 1];
|
||||
if ( last.name == "channel.index" && last.context ) {
|
||||
var following = last.context.get("isFollowing.isFollowing");
|
||||
if ( following !== undefined && following !== null )
|
||||
this.track('setCustomVariable', '1', 'Following', (following ? "Yes" : "No"), 'page');
|
||||
|
||||
var game = last.context.get("game");
|
||||
if ( game )
|
||||
this.track("setCustomVariable", "3", "Game", game, "page");
|
||||
|
||||
this.track("trackPageView", document.title);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue