(function () {
var $banner;
function queue_roll(bit) {
var n = this.allRolls.sent++;
var info = this.allRolls[n];
if (!info)
info = this.allRolls[n] = {};
info.bit = bit;
info.$tag = $(this.callback(safe('')));
this.strong = true;
var audio = undefined;
if(bit =='#loli' && info.dice) {
this.callback(safe(""));
}
else if (info.dice && (audio = readable_audio(bit, info.dice))) {
this.callback(safe(""+bit+""));
this.callback(safe(""));
}
else this.callback(info.dice ? readable_dice(bit, info.dice) : bit);
this.strong = false;
this.callback(safe(''));
}
oneeSama.hook('imouto', function (imouto) {
imouto.dice = GAME_BOARDS.indexOf(BOARD) >= 0;
imouto.queueRoll = queue_roll;
imouto.allRolls = {sent: 0, seen: 0};
});
oneeSama.hook('insertOwnPost', function (extra) {
if (!postForm || !postForm.imouto || !extra || !extra.dice)
return;
var rolls = postForm.imouto.allRolls;
for (var i = 0; i < extra.dice.length; i++) {
var n = rolls.seen++;
var info = rolls[n];
if (!info)
info = rolls[n] = {};
info.dice = extra.dice[i];
if (info.$tag) {
var audio = readable_audio(info.bit, info.dice);
if (audio)
{
var $audio = $(""+info.bit+"");
var $aaudio = $("");
info.$tag.text('');
info.$tag.append($audio);
info.$tag.append($aaudio);
if(info.$tag.children && info.$tag.children[0]) //wha? works for chakai
info.$tag.children[0].text(info.bit);
}
else if(info.bit == "#loli")
info.$tag.html("");
else info.$tag.text(readable_dice(info.bit, info.dice));
}
}
});
var bannerExtra = null; //$.parseHTML('Other stream info');
dispatcher[UPDATE_BANNER] = function (msg, op) {
msg = msg[0];
if (!$banner) {
var dest;
if (THREAD == op)
dest = '#lock';
else {
var $s = $('#' + op);
if ($s.is('section'))
dest = $s.children('header');
}
if (dest)
$banner = $('').insertAfter(dest);
}
if ($banner) {
if (Array.isArray(msg)) {
construct_banner(msg);
if (bannerExtra)
$banner.append(' / ', bannerExtra);
}
else if (msg) {
$banner.text(msg);
if (bannerExtra)
$banner.append(' / ', bannerExtra);
}
else if (bannerExtra) {
$banner.empty().append(bannerExtra);
}
else {
$banner.remove();
$banner = null;
}
}
};
function construct_banner(parts) {
$banner.empty();
parts.forEach(function (part) {
if (part.href)
$('', _.extend({target: '_blank', rel: 'noopener noreferrer'}, part)
).appendTo($banner);
else
$banner.append(document.createTextNode(part));
});
}
dispatcher[EXECUTE_JS] = function (msg, op) {
if (THREAD != op)
return;
try {
eval(msg[0]);
}
catch (e) {
/* fgsfds */
}
};
window.flash_bg = function (color) {
var $b = $('body');
var back = $b.css('background');
$b.css('background', color);
setTimeout(function () { $b.css('background', back); }, 200);
};
})();