FURSTREAM chat expander

Make the chat more compact on stream pages

目前为 2014-07-01 提交的版本。查看 最新版本

// ==UserScript==
// @name        FURSTREAM chat expander
// @namespace   furstre.am
// @description Make the chat more compact on stream pages
// @include     https://furstre.am/stream/*
// @version     8
// @grant       none
// ==/UserScript==

function addGlobalStyle(css, id) {
	var style = $(document.createElement("style")).attr("type", "text/css").html(css);
	if(id) style.attr("id", id);
	$("head").append(style);
}

var insertListener = function(e){
	if (e.animationName == "nodeInserted") {
		var avatar = $(e.target).children(".av").detach();
		var details = $(e.target).children(".content").children(".details").detach();
		$(e.target).children(".content").prepend(details);
		$(e.target).children(".content").prepend(avatar);
	}
}

function toggleChatPosition() {
	var chat = $("#chat");
	if(chat.hasClass("pull-right")) {
		chat.removeClass("pull-right");
		$("#chat .comunica .comunica-top .fa-arrow-left").removeClass("fa-arrow-left").addClass("fa-arrow-right");
	}
	else {
		chat.addClass("pull-right");
		$("#chat .comunica .comunica-top .fa-arrow-right").removeClass("fa-arrow-right").addClass("fa-arrow-left");
	}
}

function toggleBoldNames() {
	var style = $("#boldnames");
	if(style.length) {
		style.remove();
	}
	else {
		addGlobalStyle("#comunica-chat-pane .msg .content .details { font-weight: 700; opacity:1 !important; }", "boldnames");
	}
}

$(window).load(function(){
	addGlobalStyle("body { overflow-y: hidden; }")
	addGlobalStyle(".body { overflow-y: scroll !important; height: 100% !important; margin: 0 !important; }")
	addGlobalStyle("#flex__1 { position: static !important; float: left; }")
	addGlobalStyle("#chat { position: static !important; float: left; }")
	addGlobalStyle(".comunica #comunica-chat-pane .msg { margin: 0 !important; }")
	addGlobalStyle(".comunica #comunica-chat-pane .msg .content { margin: 0 !important; float: none !important; width: 100% !important; }")
	addGlobalStyle(".comunica #comunica-chat-pane .msg .content p { margin: 0 0 8px !important; }")
	addGlobalStyle(".comunica #comunica-chat-pane .msg .content .details { margin: 0 !important; }")
	addGlobalStyle(".comunica #comunica-chat-pane .msg .content:after { display: none; !important }")
	addGlobalStyle(".comunica #comunica-chat-pane .msg .content.pull-right:after { display: none !important; }")
	addGlobalStyle(".comunica #comunica-chat-pane .msg .av { position: static !important; float: left !important; }")
	addGlobalStyle("@-webkit-keyframes nodeInserted {  from { opacity: 0.99; } to { opacity: 1; }  }")
	addGlobalStyle("@-moz-keyframes nodeInserted {  from { opacity: 0.99; } to { opacity: 1; }  }")
	addGlobalStyle("@-ms-keyframes nodeInserted {  from { opacity: 0.99; } to { opacity: 1; }  }")
	addGlobalStyle("@-o-keyframes nodeInserted {  from { opacity: 0.99; } to { opacity: 1; }  }")
	addGlobalStyle("@keyframes nodeInserted {  from { opacity: 0.99; } to { opacity: 1; }  }")
	addGlobalStyle(".comunica #comunica-chat-pane .msg { " +
				"-webkit-animation: nodeInserted 0.001s;" +
				"-moz-animation: nodeInserted 0.001s;" +
				"-ms-animation: nodeInserted 0.001s;" +
				"-o-animation: nodeInserted 0.001s;" +
				"animation: nodeInserted 0.001s;" +
			"}")
	document.addEventListener("webkitAnimationStart", insertListener, false)
	document.addEventListener("MSAnimationStart", insertListener, false)
	document.addEventListener("oanimationstart", insertListener, false)
	document.addEventListener("animationstart", insertListener, false)
	var chat = $("#chat").addClass("pull-right").detach()
	$("#flex__1").after(chat)
	$('.body div[style="position:absolute;width:100%;height:20px;bottom:0;background-color:#222"]').css({ "position" : "static" })
	$("body").contents().first().remove()
	$("#chat .comunica .comunica-top").append($(document.createElement("i")).addClass("fa fa-arrow-left fa-2x fa-fw button").click(toggleChatPosition))
	$("#chat .comunica .comunica-top").append($(document.createElement("i")).addClass("fa fa-bold fa-2x fa-fw button").click(toggleBoldNames))
})