2017-11-13 01:23:39 -05:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// Badge Handling
|
|
|
|
// ============================================================================
|
|
|
|
|
2018-02-02 16:00:01 -05:00
|
|
|
import {API_SERVER, IS_WEBKIT, WEBKIT_CSS as WEBKIT} from 'utilities/constants';
|
2017-11-28 02:03:59 -05:00
|
|
|
|
|
|
|
import {createElement as e, ManagedStyle} from 'utilities/dom';
|
|
|
|
import {has} from 'utilities/object';
|
2017-11-13 01:23:39 -05:00
|
|
|
import Module from 'utilities/module';
|
|
|
|
|
|
|
|
export const CSS_BADGES = {
|
2017-11-28 02:03:59 -05:00
|
|
|
staff: { 1: { color: '#200f33', svg: true, trans: { color: '#6441a5' } } },
|
|
|
|
admin: { 1: { color: '#faaf19', svg: true } },
|
|
|
|
global_mod: { 1: { color: '#0c6f20', svg: true } },
|
|
|
|
broadcaster: { 1: { color: '#e71818', svg: true } },
|
|
|
|
moderator: { 1: { color: '#34ae0a', svg: true } },
|
2017-11-13 01:23:39 -05:00
|
|
|
twitchbot: { 1: { color: '#34ae0a' } },
|
2017-11-28 02:03:59 -05:00
|
|
|
partner: { 1: { color: 'transparent', trans: { image: true, color: '#6441a5' } } },
|
2017-11-13 01:23:39 -05:00
|
|
|
|
2017-11-28 02:03:59 -05:00
|
|
|
turbo: { 1: { color: '#6441a5', svg: true } },
|
2017-11-13 01:23:39 -05:00
|
|
|
premium: { 1: { color: '#009cdc' } },
|
|
|
|
|
|
|
|
subscriber: { 0: { color: '#6441a4' }, 1: { color: '#6441a4' }},
|
|
|
|
}
|
|
|
|
|
2018-01-16 17:36:56 -05:00
|
|
|
export const BADGE_POSITIONS = {
|
|
|
|
broadcaster: 0,
|
|
|
|
staff: 0,
|
|
|
|
admin: 0,
|
|
|
|
global_mod: 0,
|
|
|
|
mod: 1,
|
|
|
|
moderator: 1,
|
|
|
|
twitchbot: 1,
|
|
|
|
subscriber: 25
|
|
|
|
};
|
|
|
|
|
2017-11-13 01:23:39 -05:00
|
|
|
|
2017-11-28 02:03:59 -05:00
|
|
|
const NO_REPEAT = 'background-repeat:no-repeat;background-position:center;',
|
|
|
|
BASE_IMAGE = 'https://cdn.frankerfacez.com/badges/twitch/',
|
2018-02-02 16:00:01 -05:00
|
|
|
CSS_MASK_IMAGE = IS_WEBKIT ? 'webkitMaskImage' : 'maskImage',
|
|
|
|
|
2017-11-28 02:03:59 -05:00
|
|
|
CSS_TEMPLATES = {
|
2018-01-16 17:36:56 -05:00
|
|
|
0: data => `background:${data.image} ${data.color};background-size:${data.scale*1.8}rem;${data.svg ? '' : `background-image:${data.image_set};`}${NO_REPEAT}`,
|
|
|
|
1: data => `${CSS_TEMPLATES[0](data)}border-radius:${data.scale*.2}rem;`,
|
|
|
|
2: data => `${CSS_TEMPLATES[0](data)}border-radius:${data.scale*.9}rem;background-size:${data.scale*1.6}rem;`,
|
|
|
|
3: data => `background:${data.color};border-radius:${data.scale*.9}rem;`,
|
|
|
|
4: data => `${CSS_TEMPLATES[3](data)}height:${data.scale}rem;min-width:${data.scale}rem;`,
|
|
|
|
5: data => `background:${data.image};background-size:${data.scale*1.8}rem;${data.svg ? `` : `background-image:${data.image_set};`}${NO_REPEAT}`,
|
|
|
|
6: data => `background:linear-gradient(${data.color},${data.color});${WEBKIT}mask-image:${data.image};${WEBKIT}mask-size:${data.scale*1.8}rem ${data.scale*1.8}rem;${data.svg ? `` : `${WEBKIT}mask-image:${data.image_set};`}`
|
2017-11-28 02:03:59 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-01-16 17:36:56 -05:00
|
|
|
export function generateOverrideCSS(data, style, is_dark) {
|
|
|
|
let image = `url("${data.urls[1]}")`,
|
|
|
|
image_set = `${WEBKIT}image-set(${image} 1x${data.urls[2] ? `, url("${data.urls[2]}") 2x` : ''}${data.urls[4] ? `, url("${data.urls[4]}") 4x` : ''})`;
|
|
|
|
|
|
|
|
if ( style === 3 || style === 4 )
|
|
|
|
return '';
|
|
|
|
|
|
|
|
if ( style === 6 )
|
|
|
|
return `${WEBKIT}mask-image:${image} !important;${WEBKIT}mask-image:${image_set} !important;`;
|
|
|
|
else
|
|
|
|
return `background-image:${image} !important;background-image:${image_set} !important;`;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-28 02:03:59 -05:00
|
|
|
export function generateBadgeCSS(badge, version, data, style, is_dark, scale = 1) {
|
|
|
|
let color = data.color || 'transparent',
|
|
|
|
base_image = data.image || `${BASE_IMAGE}${badge}${data.svg ? '.svg' : `/${version}/`}`,
|
|
|
|
trans = false,
|
|
|
|
invert = false,
|
|
|
|
svg, image, image_set;
|
|
|
|
|
|
|
|
if ( style > 4 ) {
|
|
|
|
const td = data.trans || {};
|
|
|
|
color = td.color || color;
|
|
|
|
|
|
|
|
if ( td.image ) {
|
|
|
|
trans = true;
|
|
|
|
if ( td.image !== true )
|
|
|
|
base_image = td.image;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( has(td, 'invert') )
|
|
|
|
invert = td.invert && ! is_dark;
|
|
|
|
else
|
|
|
|
invert = style === 5 && ! is_dark;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( style === 3 || style === 4 ) {
|
|
|
|
if ( color === 'transparent' && data.trans )
|
|
|
|
color = data.trans.color || color;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if ( style < 5 && color === 'transparent' )
|
|
|
|
style = 0;
|
|
|
|
|
|
|
|
svg = base_image.endsWith('.svg');
|
2018-01-16 17:36:56 -05:00
|
|
|
if ( data.urls )
|
|
|
|
image = `url("${data.urls[1]}")`;
|
|
|
|
else
|
|
|
|
image = `url("${svg ? base_image : `${base_image}${scale}${trans ? '_trans' : ''}.png`}")`;
|
|
|
|
|
|
|
|
if ( data.urls ) {
|
2018-02-02 16:00:01 -05:00
|
|
|
image_set = `${WEBKIT}image-set(${image} 1x${data.urls[2] ? `, url("${data.urls[2]}") 2x` : ''}${data.urls[4] ? `, url("${data.urls[4]}") 4x` : ''})`
|
2017-11-28 02:03:59 -05:00
|
|
|
|
2018-01-16 17:36:56 -05:00
|
|
|
} else if ( ! svg && scale < 4 ) {
|
2017-11-28 02:03:59 -05:00
|
|
|
if ( scale === 1 )
|
|
|
|
image_set = `${WEBKIT}image-set(${image} 1x, url("${base_image}2${trans ? '_trans' : ''}.png") 2x, url("${base_image}4${trans ? '_trans' : ''}.png") 4x)`;
|
|
|
|
|
|
|
|
else if ( scale === 2 )
|
|
|
|
image_set = `${WEBKIT}image-set(${image} 1x, url("${base_image}4${trans ? '_trans' : ''}.png") 2x)`;
|
|
|
|
|
|
|
|
} else
|
|
|
|
image_set = svg;
|
|
|
|
}
|
|
|
|
|
2018-01-16 17:36:56 -05:00
|
|
|
// TODO: Fix the click_url name once we actually support badge clicking.
|
|
|
|
return `${data.__click_url ? 'cursor:pointer;' : ''}${invert ? 'filter:invert(100%);' : ''}${CSS_TEMPLATES[style]({
|
2017-11-28 02:03:59 -05:00
|
|
|
scale,
|
|
|
|
color,
|
|
|
|
image,
|
|
|
|
image_set,
|
|
|
|
svg
|
|
|
|
})}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-13 01:23:39 -05:00
|
|
|
export default class Badges extends Module {
|
2017-11-28 02:03:59 -05:00
|
|
|
constructor(...args) {
|
|
|
|
super(...args);
|
|
|
|
|
|
|
|
this.inject('i18n');
|
|
|
|
this.inject('settings');
|
|
|
|
this.inject('socket');
|
|
|
|
this.inject('tooltips');
|
|
|
|
|
|
|
|
this.style = new ManagedStyle('badges');
|
|
|
|
this.badges = {};
|
|
|
|
|
|
|
|
this.twitch_badges = new Map;
|
|
|
|
|
|
|
|
this.settings.add('chat.badges.style', {
|
|
|
|
default: 0,
|
|
|
|
ui: {
|
|
|
|
path: 'Chat > Badges >> Appearance',
|
|
|
|
title: 'Style',
|
|
|
|
component: 'setting-select-box',
|
|
|
|
data: [
|
|
|
|
{value: 0, title: 'Default'},
|
|
|
|
{value: 1, title: 'Rounded'},
|
|
|
|
{value: 2, title: 'Circular'},
|
|
|
|
{value: 3, title: 'Circular (Color Only)'},
|
|
|
|
{value: 4, title: 'Circular (Color Only, Small)'},
|
|
|
|
{value: 5, title: 'Transparent'},
|
|
|
|
{value: 6, title: 'Transparent (Colored)'}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
onEnable() {
|
|
|
|
this.parent.context.on('changed:chat.badges.style', this.rebuildAllCSS, this);
|
|
|
|
this.parent.context.on('changed:theme.is-dark', this.rebuildAllCSS, this);
|
|
|
|
this.parent.context.on('changed:theme.tooltips-dark', this.rebuildAllCSS, this);
|
|
|
|
|
|
|
|
this.rebuildAllCSS();
|
|
|
|
this.loadGlobalBadges();
|
|
|
|
|
|
|
|
this.tooltips.types.badge = (target, tip) => {
|
2018-02-02 16:00:01 -05:00
|
|
|
const show_previews = this.parent.context.get('tooltip.badge-images'),
|
|
|
|
container = target.parentElement.parentElement,
|
2017-11-28 02:03:59 -05:00
|
|
|
room_id = container.dataset.roomId,
|
2018-01-16 17:36:56 -05:00
|
|
|
room_login = container.dataset.room,
|
2018-02-02 16:00:01 -05:00
|
|
|
data = JSON.parse(target.dataset.badgeData),
|
|
|
|
out = [];
|
|
|
|
|
|
|
|
for(const d of data) {
|
|
|
|
const p = d.provider;
|
|
|
|
if ( p === 'twitch' ) {
|
|
|
|
const bd = this.getTwitchBadge(d.badge, d.version, room_id, room_login);
|
|
|
|
if ( ! bd )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
out.push(e('div', {className: 'ffz-badge-tip'}, [
|
|
|
|
show_previews && e('img', {
|
2017-11-28 02:03:59 -05:00
|
|
|
className: 'preview-image ffz-badge',
|
2018-02-02 16:00:01 -05:00
|
|
|
src: bd.image4x
|
|
|
|
}),
|
|
|
|
bd.title
|
|
|
|
]));
|
|
|
|
|
|
|
|
} else if ( p === 'ffz' ) {
|
|
|
|
out.push(e('div', {className: 'ffz-badge-tip'}, [
|
|
|
|
show_previews && e('img', {
|
|
|
|
className: 'preview-image ffz-badge',
|
|
|
|
style: {
|
|
|
|
height: '7.2rem',
|
|
|
|
width: '7.2rem',
|
|
|
|
backgroundSize: '7.2rem',
|
|
|
|
backgroundColor: d.color,
|
|
|
|
backgroundImage: `url("${d.image}")`
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
d.title
|
|
|
|
]));
|
|
|
|
}
|
|
|
|
}
|
2017-11-28 02:03:59 -05:00
|
|
|
|
2018-02-02 16:00:01 -05:00
|
|
|
return out;
|
|
|
|
}
|
2017-11-28 02:03:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
render(msg, e) { // eslint-disable-line class-methods-use-this
|
2018-01-16 17:36:56 -05:00
|
|
|
const hidden_badges = this.parent.context.get('chat.badges.hidden') || [],
|
2018-02-02 16:00:01 -05:00
|
|
|
badge_style = this.parent.context.get('chat.badges.style'),
|
|
|
|
is_mask = badge_style >= 5,
|
|
|
|
is_colored = badge_style !== 5,
|
|
|
|
has_image = badge_style !== 3 && badge_style !== 4,
|
|
|
|
|
2018-01-16 17:36:56 -05:00
|
|
|
out = [],
|
|
|
|
slotted = {},
|
|
|
|
twitch_badges = msg.badges || {},
|
2017-11-28 02:03:59 -05:00
|
|
|
|
2018-01-16 17:36:56 -05:00
|
|
|
user = msg.user || {},
|
2017-11-28 02:03:59 -05:00
|
|
|
user_id = user.userID,
|
|
|
|
user_login = user.userLogin,
|
|
|
|
room_id = msg.roomID,
|
|
|
|
room_login = msg.roomLogin,
|
|
|
|
|
2018-01-16 17:36:56 -05:00
|
|
|
badges = this.getBadges(user_id, user_login, room_id, room_login);
|
|
|
|
|
|
|
|
let last_slot = 50, slot;
|
2017-11-28 02:03:59 -05:00
|
|
|
|
|
|
|
for(const badge_id in twitch_badges)
|
|
|
|
if ( has(twitch_badges, badge_id) ) {
|
2018-01-16 17:36:56 -05:00
|
|
|
const version = twitch_badges[badge_id],
|
|
|
|
is_game = badge_id.endsWith('_1');
|
|
|
|
|
|
|
|
if ( hidden_badges.includes(badge_id) || (is_game && hidden_badges.includes('game')) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ( has(BADGE_POSITIONS, badge_id) )
|
|
|
|
slot = BADGE_POSITIONS[badge_id];
|
|
|
|
else
|
|
|
|
slot = last_slot++;
|
|
|
|
|
2018-02-02 16:00:01 -05:00
|
|
|
const badges = [{
|
|
|
|
provider: 'twitch',
|
|
|
|
badge: badge_id,
|
|
|
|
version
|
|
|
|
}];
|
|
|
|
|
2018-01-16 17:36:56 -05:00
|
|
|
slotted[slot] = {
|
|
|
|
id: badge_id,
|
|
|
|
props: {
|
|
|
|
'data-provider': 'twitch',
|
|
|
|
'data-badge': badge_id,
|
|
|
|
'data-version': version
|
2018-02-02 16:00:01 -05:00
|
|
|
},
|
|
|
|
badges
|
2018-01-16 17:36:56 -05:00
|
|
|
};
|
2017-11-28 02:03:59 -05:00
|
|
|
}
|
|
|
|
|
2018-01-16 17:36:56 -05:00
|
|
|
for(const badge of badges)
|
2017-11-28 02:03:59 -05:00
|
|
|
if ( badge && badge.id ) {
|
2018-01-16 17:36:56 -05:00
|
|
|
if ( hidden_badges.includes(badge.id) )
|
|
|
|
continue;
|
|
|
|
|
2017-11-28 02:03:59 -05:00
|
|
|
const full_badge = this.badges[badge.id],
|
2018-01-16 17:36:56 -05:00
|
|
|
slot = has(badge, 'slot') ? badge.slot : full_badge.slot,
|
2018-02-02 16:00:01 -05:00
|
|
|
old_badge = slotted[slot],
|
|
|
|
urls = badge.urls || (badge.image ? {1: badge.image} : null),
|
|
|
|
|
|
|
|
bu = (urls || full_badge.urls || {1: full_badge.image}),
|
|
|
|
bd = {
|
|
|
|
provider: 'ffz',
|
|
|
|
image: bu[4] || bu[2] || bu[1],
|
|
|
|
color: badge.color || full_badge.color,
|
|
|
|
title: badge.title || full_badge.title
|
|
|
|
};
|
2018-01-16 17:36:56 -05:00
|
|
|
|
|
|
|
if ( old_badge ) {
|
|
|
|
const replaces = has(badge, 'replaces') ? badge.replaces : full_badge.replaces,
|
|
|
|
replaces_type = badge.replaces_type || full_badge.replaces_type;
|
|
|
|
if ( replaces && (!replaces_type || replaces_type === old_badge.id) )
|
|
|
|
old_badge.replaced = badge.id;
|
|
|
|
|
2018-02-02 16:00:01 -05:00
|
|
|
old_badge.badges.push(bd);
|
2018-01-16 17:36:56 -05:00
|
|
|
continue;
|
|
|
|
|
|
|
|
} else if ( ! slot )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const style = {},
|
2017-11-28 02:03:59 -05:00
|
|
|
props = {
|
|
|
|
className: 'ffz-tooltip ffz-badge',
|
|
|
|
'data-tooltip-type': 'badge',
|
|
|
|
'data-provider': 'ffz',
|
|
|
|
'data-badge': badge.id,
|
|
|
|
style
|
|
|
|
};
|
|
|
|
|
2018-02-02 16:00:01 -05:00
|
|
|
if ( has_image && urls ) {
|
|
|
|
let image_set, image = `url("${urls[1]}")`;
|
|
|
|
if ( urls[2] || urls[4] )
|
|
|
|
image_set = `${WEBKIT}image-set(${image} 1x${urls[2] ? `, url("${urls[2]}") 2x` : ''}${urls[4] ? `, url("${urls[4]}") 4x` : ''})`;
|
|
|
|
|
|
|
|
style[is_mask ? CSS_MASK_IMAGE : 'backgroundImage'] = image;
|
|
|
|
if ( image_set )
|
|
|
|
style[is_mask ? CSS_MASK_IMAGE : 'backgroundImage'] = image_set;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( is_colored && badge.color ) {
|
|
|
|
if ( is_mask )
|
|
|
|
style.backgroundImage = `linear-gradient(${badge.color},${badge.color})`;
|
|
|
|
else
|
|
|
|
style.backgroundColor = badge.color;
|
|
|
|
}
|
2018-01-29 22:25:39 -05:00
|
|
|
|
2018-02-02 16:00:01 -05:00
|
|
|
slotted[slot] = { id: badge.id, props, badges: [bd] };
|
2018-01-16 17:36:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
for(const slot in slotted)
|
|
|
|
if ( has(slotted, slot) ) {
|
|
|
|
const data = slotted[slot],
|
|
|
|
props = data.props;
|
|
|
|
|
|
|
|
props.className = 'ffz-tooltip ffz-badge';
|
|
|
|
props['data-tooltip-type'] = 'badge';
|
2018-02-02 16:00:01 -05:00
|
|
|
props['data-badge-data'] = JSON.stringify(data.badges);
|
2017-11-28 02:03:59 -05:00
|
|
|
|
2018-01-16 17:36:56 -05:00
|
|
|
if ( data.replaced )
|
|
|
|
props['data-replaced'] = data.replaced;
|
2017-11-28 02:03:59 -05:00
|
|
|
|
|
|
|
out.push(e('span', props));
|
2018-01-16 17:36:56 -05:00
|
|
|
}
|
2017-11-28 02:03:59 -05:00
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
rebuildAllCSS() {
|
|
|
|
for(const room of this.parent.iterateRooms())
|
|
|
|
room.buildBadgeCSS();
|
|
|
|
|
2018-01-16 17:36:56 -05:00
|
|
|
this.buildBadgeCSS();
|
2017-11-28 02:03:59 -05:00
|
|
|
this.buildTwitchBadgeCSS();
|
|
|
|
this.buildTwitchCSSBadgeCSS();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ========================================================================
|
|
|
|
// Extension Badges
|
|
|
|
// ========================================================================
|
|
|
|
|
|
|
|
getBadges(user_id, user_login, room_id, room_login) {
|
|
|
|
const room = this.parent.getRoom(room_id, room_login, true),
|
|
|
|
global_user = this.parent.getUser(user_id, user_login, true),
|
|
|
|
room_user = room && room.getUser(user_id, user_login, true);
|
|
|
|
|
|
|
|
return (global_user ? global_user.badges._cache : []).concat(
|
|
|
|
room_user ? room_user.badges._cache : []);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async loadGlobalBadges(tries = 0) {
|
|
|
|
let response, data;
|
|
|
|
try {
|
|
|
|
response = await fetch(`${API_SERVER}/v1/badges`);
|
|
|
|
} catch(err) {
|
|
|
|
tries++;
|
|
|
|
if ( tries < 10 )
|
|
|
|
return setTimeout(() => this.loadGlobalBadges(tries), 500 * tries);
|
|
|
|
|
|
|
|
this.log.error('Error loading global badge data.', err);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! response.ok )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
try {
|
|
|
|
data = await response.json();
|
|
|
|
} catch(err) {
|
|
|
|
this.log.error('Error parsing global badge data.', err);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
let badges = 0, users = 0;
|
|
|
|
|
|
|
|
if ( data.badges )
|
|
|
|
for(const badge of data.badges)
|
|
|
|
if ( badge && badge.id ) {
|
2018-02-02 16:00:01 -05:00
|
|
|
this.loadBadgeData(badge.id, badge, false);
|
2017-11-28 02:03:59 -05:00
|
|
|
badges++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( data.users )
|
|
|
|
for(const badge_id in data.users)
|
|
|
|
if ( has(data.users, badge_id) ) {
|
|
|
|
const badge = this.badges[badge_id];
|
|
|
|
let c = 0;
|
|
|
|
for(const user_login of data.users[badge_id]) {
|
|
|
|
const user = this.parent.getUser(undefined, user_login);
|
|
|
|
if ( user.addBadge('ffz-global', badge_id) ) {
|
|
|
|
c++;
|
|
|
|
users++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( c > 0 )
|
|
|
|
this.log.info(`Added "${badge ? badge.name : `#${badge_id}`}" to ${c} users.`);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.log.info(`Loaded ${badges} badges and assigned them to ${users} users.`);
|
2018-01-16 17:36:56 -05:00
|
|
|
this.buildBadgeCSS();
|
2017-11-28 02:03:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-02 16:00:01 -05:00
|
|
|
loadBadgeData(badge_id, data, generate_css = true) {
|
2017-11-28 02:03:59 -05:00
|
|
|
this.badges[badge_id] = data;
|
|
|
|
|
|
|
|
if ( data.replaces && ! data.replaces_type ) {
|
|
|
|
data.replaces_type = data.replaces;
|
|
|
|
data.replaces = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( data.name === 'developer' || data.name === 'supporter' )
|
|
|
|
data.click_url = 'https://www.frankerfacez.com/donate';
|
2018-02-02 16:00:01 -05:00
|
|
|
|
|
|
|
if ( generate_css )
|
|
|
|
this.buildBadgeCSS();
|
2017-11-28 02:03:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-16 17:36:56 -05:00
|
|
|
buildBadgeCSS() {
|
|
|
|
const style = this.parent.context.get('chat.badges.style'),
|
|
|
|
is_dark = this.parent.context.get('theme.is-dark');
|
|
|
|
|
|
|
|
const out = [];
|
|
|
|
for(const key in this.badges)
|
|
|
|
if ( has(this.badges, key) ) {
|
|
|
|
const data = this.badges[key],
|
|
|
|
selector = `.ffz-badge[data-badge="${key}"]`;
|
|
|
|
|
|
|
|
out.push(`${selector}{${generateBadgeCSS(key, 0, data, style, is_dark)}}`);
|
|
|
|
out.push(`.ffz-badge[data-replaced="${key}"]{${generateOverrideCSS(data, style, is_dark)}}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.style.set('ext-badges', out.join('\n'));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-28 02:03:59 -05:00
|
|
|
// ========================================================================
|
|
|
|
// Twitch Badges
|
|
|
|
// ========================================================================
|
|
|
|
|
|
|
|
getTwitchBadge(badge, version, room_id, room_login) {
|
|
|
|
const room = this.parent.getRoom(room_id, room_login, true);
|
|
|
|
let b;
|
|
|
|
|
|
|
|
if ( room ) {
|
2018-01-19 17:17:16 -05:00
|
|
|
const versions = room.badges && room.badges[badge];
|
|
|
|
b = versions && versions[version];
|
2017-11-28 02:03:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! b ) {
|
2018-01-19 17:17:16 -05:00
|
|
|
const versions = this.twitch_badges && this.twitch_badges[badge];
|
|
|
|
b = versions && versions[version];
|
2017-11-28 02:03:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
|
|
|
updateTwitchBadges(badges) {
|
2018-01-19 17:17:16 -05:00
|
|
|
if ( ! badges )
|
|
|
|
this.twitch_badges = badges;
|
|
|
|
else {
|
|
|
|
const b = {};
|
|
|
|
for(const data of badges) {
|
|
|
|
const sid = data.setID,
|
|
|
|
bs = b[sid] = b[sid] || {};
|
|
|
|
|
|
|
|
bs[data.version] = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.twitch_badges = b;
|
|
|
|
}
|
|
|
|
|
2017-11-28 02:03:59 -05:00
|
|
|
this.buildTwitchBadgeCSS();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
buildTwitchCSSBadgeCSS() {
|
|
|
|
const style = this.parent.context.get('chat.badges.style'),
|
|
|
|
is_dark = this.parent.context.get('theme.is-dark');
|
|
|
|
|
|
|
|
const out = [];
|
|
|
|
for(const key in CSS_BADGES)
|
|
|
|
if ( has(CSS_BADGES, key) ) {
|
|
|
|
const data = CSS_BADGES[key];
|
|
|
|
for(const version in data)
|
|
|
|
if ( has(data, version) ) {
|
|
|
|
const d = data[version],
|
|
|
|
selector = `.ffz-badge[data-badge="${key}"][data-version="${version}"]`;
|
|
|
|
|
|
|
|
out.push(`${selector}{${generateBadgeCSS(key, version, d, style, is_dark)}}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.style.set('css-badges', out.join('\n'));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
buildTwitchBadgeCSS() {
|
|
|
|
if ( ! this.twitch_badges )
|
|
|
|
this.style.delete('twitch-badges');
|
|
|
|
|
|
|
|
const out = [];
|
2018-01-19 17:17:16 -05:00
|
|
|
for(const key in this.twitch_badges)
|
|
|
|
if ( has(this.twitch_badges, key) ) {
|
|
|
|
if ( has(CSS_BADGES, key) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const versions = this.twitch_badges[key];
|
|
|
|
for(const version in versions)
|
|
|
|
if ( has(versions, version) ) {
|
|
|
|
const data = versions[version];
|
|
|
|
|
|
|
|
out.push(`.ffz-badge[data-badge="${key}"][data-version="${version}"] {
|
|
|
|
background-color: transparent;
|
|
|
|
filter: none;
|
|
|
|
${WEBKIT}mask-image: none;
|
|
|
|
background-size: 1.8rem;
|
|
|
|
background-image: url("${data.image1x}");
|
|
|
|
background-image: ${WEBKIT}image-set(
|
|
|
|
url("${data.image1x}") 1x,
|
|
|
|
url("${data.image2x}") 2x,
|
|
|
|
url("${data.image4x}") 4x
|
|
|
|
);
|
|
|
|
}`)
|
|
|
|
}
|
2017-11-28 02:03:59 -05:00
|
|
|
}
|
2017-11-13 01:23:39 -05:00
|
|
|
|
2017-11-28 02:03:59 -05:00
|
|
|
if ( out.length )
|
|
|
|
this.style.set('twitch-badges', out.join('\n'));
|
|
|
|
else
|
|
|
|
this.style.delete('twitch-badges');
|
|
|
|
}
|
2017-11-13 01:23:39 -05:00
|
|
|
}
|