Tieba Float Movable

贴吧可移动悬浮窗

目前為 2014-12-16 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name	Tieba Float Movable
// @namespace	http://gera2ld.blog.163.com/
// @author	Gerald <[email protected]>
// @icon	http://ww2.sinaimg.cn/small/a56031a1gw1emwlbe1c8gj2097097wfa.jpg
// @version	1.2.12.1
// @description	贴吧可移动悬浮窗
// @homepageURL	http://geraldl.net/userjs/TiebaFloatMovable
// @include	http://tieba.baidu.com/*
// @exclude	http://tieba.baidu.com/tb/*
// @require	https://greasyfork.org/scripts/144/code.user.js
// @grant	none
// ==/UserScript==

function locate(m,css) {
	var c={};
	args.forEach(function(i){c[i]=/^-?\d+px/.test(css[i])?css[i]:'20px';});
	m.css(c);
}
function movable(o,name) {
	var m=$(o);
	if(!m.mousedown) return;
	o.moving=false;args=['right','bottom'];
	m.mousedown(function(e) {
		if(['DIV','TD'].indexOf(e.target.tagName)<0||e.target.contentEditable=='true') return;
		e.preventDefault();e.stopPropagation();
		o.x=e.pageX;
		if(args.indexOf('left')>=0) o.x-=parseInt(m.css('left'));
		else o.x+=parseInt(m.css('right'));
		o.y=e.pageY;
		if(args.indexOf('top')>=0) o.y-=parseInt(m.css('top'));
		else o.y+=parseInt(m.css('bottom'));
		if(!o.moving) $(document).mousemove(function(e) {
			if(o.moving) {
				var css={};
				for(var i in args) {
					var arg=args[i];
					if(arg=='left') css[arg]=e.pageX-o.x;
					else if(arg=='right') css[arg]=o.x-e.pageX;
					else if(arg=='top') css[arg]=e.pageY-o.y;
					else if(arg=='bottom') css[arg]=o.y-e.pageY;
					else continue;
					css[arg]+='px';
				}
				locate(m,css);
			}
			e.preventDefault();
		}).mouseup(function(e) {
			if(o.moving) {
				o.moving=false;
				var css={};
				for(var i in args) {
					var arg=args[i];
					css[arg]=m.css(arg);
				}
				utils.setObj('mcss_'+name,css);
				$(document).unbind('mousemove').unbind('mouseup');
			}
		});
		o.moving=true;
	});
	locate(m,utils.getObj('mcss_'+name,{}));
}
function unmovable(o) {$(o).unbind('mousedown').css({left:'',right:'',top:'',bottom:''});}
function main(editor) {
	function unminify(){
		if(utils.unminify) {
			mn.hide();ep.show();editor.focus();delete utils.unminify;
		}
	}
	function minify(){
		ep.hide();mn.show();utils.unminify=unminify;
		unsafeWindow.unminifyShare=unminify;	// 献给大花猫
	}
	function floatUp(){
		if(sta=='normal'||!allowUp) styleUp.html('');
		else styleUp.html('\
.edui-popup{bottom:44px;top:auto !important;}\
.edui-popup-caret{bottom:-8px;top:auto !important;transform:scale(1,-1);-webkit-transform:scale(1,-1);}\
');
	}
	function updateMinifyButton() {
		if(sta=='open'&&allowMinify&&!allowMinifyOnBlur) mx.show();
		else mx.hide();
	}
	function showFloat() {
		if(sta=='open') {
			styleFloat.html('\
.editor_title{width:610px !important;}\
#ueditor_replace{min-height:50px !important;}\
.poster_success{top:50px !important}\
.old_style_wrapper{width:600px !important;}\
.j_floating{margin-left:.5em;}\
');
			if(allowSimple) ep.attr('title','双击精简');
		} else {
			styleFloat.html('\
.editor_title{width:360px !important;}\
#ueditor_replace{min-height:24px !important;width:310px !important;}\
.poster_success{top:0 !important;left:40px !important;}\
.poster_signature,.editor_bottom_panel,.edui-toolbar{display:none !important;}\
.editor_textfield{padding:0 !important;}\
.old_style_wrapper{width:330px !important;}\
');
			ep.attr('title','双击展开');
		}
		updateMinifyButton();
	}
	function bindShortcut(){
		if(shortcut) utils.shortcut(shortcut,unminify);
	}
	function showSettings(e){
		e.stopPropagation();
		utils.popup.show({
			html:'\
<div class="ge_sbtn" style="cursor:default">悬浮设置</div>\
<label><input type=checkbox id=allowUp>向上弹出窗口</label><br>\
<label><input type=checkbox id=allowSimple>双击精简或展开</label><br>\
<label><input type=checkbox id=allowMinify>允许窗口隐藏</label><br>\
<div style="margin-left:20px">\
<label><input type=checkbox id=allowMinifyOnBlur>失去焦点时自动隐藏</label><br>\
<label>呼出的快捷键:'+utils.getLink('hotkey',{title:'帮助',html:'(?)'})+'<input id=shortcut style="width:60px"></label><br>\
</div>\
<button id=btReset>重置悬浮窗位置</button>\
',
			className:'ge_opt',
			init:function(d){
				utils.bindProp($('#allowUp',d),'checked','allowUp',0,function(e){
					allowUp=this.checked;floatUp();
				});
				utils.bindProp($('#allowMinify',d),'checked','allowMinify',0,function(e){
					allowMinify=this.checked;showFloat();
				});
				utils.bindProp($('#allowMinifyOnBlur',d),'checked','allowMinifyOnBlur',0,function(e){
					allowMinifyOnBlur=this.checked;updateMinifyButton();
				});
				utils.bindProp($('#shortcut',d),'value','hk-float',0,function(e){
					if(shortcut) utils.shortcut(shortcut);
					shortcut=this.value;bindShortcut();
				});
				utils.bindProp($('#allowSimple',d),'checked','allowSimple',0,function(e){
					allowSimple=this.checked;showFloat();
				});
				$('#btReset',d).click(function(){locate(ep,{});});
			},
		});
	}
	utils.addStyle('\
#tb_rich_poster{box-shadow:1px 1px 1px 3px rgba(0,0,0,.6);position:fixed !important;z-index:10001;background-color:#E7EAEB;}\
#tb_rich_poster .editor_wrapper{margin-left:0;}\
.poster_head,#bdInputObjWrapper,.tb_poster_placeholder,.poster_draft_status,.poster_reply{display:none !important;}\
.editor_bottom_panel{margin-bottom:0 !important;}\
.poster_body .poster_component{padding-bottom:0 !important;}\
.float-button{position:absolute;bottom:0;right:0;cursor:pointer;line-height:2em;color:white;}\
.float-button>div{display:none;background:brown;float:right;}\
.float-button>div>*{display:inline-block;margin:0 .5em;}\
.float-button>div>*:hover{text-shadow:2px 1px 2px black;}\
.float-button:hover>div{display:block;}\
.float-button::before{content:"...";position:absolute;right:.2em;bottom:0;}\
.float-button:hover::before{content:"";}\
.float-button::after{content:"";border-bottom:2em solid brown;border-left:2em solid transparent;float:right;}\
#btUnminify{position:fixed;bottom:0;right:0;background:brown;color:white;font-weight:bold;padding:.5em;z-index:10;}\
#btUnminify::before{content:"+";}\
');
	var styleFloat=utils.addStyle(),styleUp=utils.addStyle(),
	args,shortcut=utils.getObj('hk-float',''),
	sta=utils.getObj('float','open'),
	allowUp=utils.getObj('allowUp',true),
	allowMinify=utils.getObj('allowMinify',true),
	allowSimple=utils.getObj('allowSimple',true),
	allowMinifyOnBlur=utils.getObj('allowMinifyOnBlur',true),
	ep=$('#tb_rich_poster').dblclick(function(){
		if(allowSimple) {
			sta=sta=='open'?'close':'open';
			utils.setObj('float',sta);
			showFloat();
		}
	}).click(function(e){justClicked=e.target;}),justClicked=null,
	buttonFloat=$('<div>').appendTo($('<div class=float-button title="">').appendTo('#tb_rich_poster')),
	mn=$('<div id=btUnminify></div>').appendTo(document.body).mouseover(unminify).hide(),
	mx=$('<div>隐藏</div>').appendTo(buttonFloat).click(minify).hide();
	$('<div>悬浮设置</div>').prependTo(buttonFloat).click(showSettings);
	movable(ep[0],'float');
	editor.$container.attr('style','');
	showFloat();floatUp();bindShortcut();
	if(allowMinify) minify();
	$(document).click(function(e){
		if(justClicked) justClicked=null;
		else if(allowMinify&&allowMinifyOnBlur) minify();
	});
	$('.j_quick_reply').click(unminify);
}

if(unsafeWindow.PosterContext&&unsafeWindow.PosterContext.isPostAllowed()) {
	if(unsafeWindow.test_editor) main(test_editor);
	else _.Module.use("common/widget/RichPoster",{prefix:{}},function(t){t.init();t.unbindScrollEvent();main(unsafeWindow.test_editor);});
}