Tieba Float Movable

贴吧可移动悬浮窗

  1. // ==UserScript==
  2. // @name Tieba Float Movable
  3. // @namespace http://gera2ld.blog.163.com/
  4. // @author Gerald <gera2ld@163.com>
  5. // @icon http://cn.gravatar.com/avatar/a0ad718d86d21262ccd6ff271ece08a3?s=80
  6. // @version 1.2.14
  7. // @description 贴吧可移动悬浮窗
  8. // @homepageURL http://gerald.top/code/TiebaFloatMovable
  9. // @include http://tieba.baidu.com/*
  10. // @exclude http://tieba.baidu.com/tb/*
  11. // @require https://gf.qytechs.cn/scripts/144/code.user.js
  12. // @grant none
  13. // ==/UserScript==
  14.  
  15. function locate(m,css) {
  16. var c={};
  17. args.forEach(function(i){c[i]=/^-?\d+px/.test(css[i])?css[i]:'20px';});
  18. m.css(c);
  19. var ensureVisible=function(keys,max,min){
  20. keys.some(function(key){
  21. var v=parseInt(m.css(key));
  22. if(isNaN(v)) return false;
  23. if(v<min) {nc=nc||{};nc[key]=min;}
  24. else if(v>max) {nc=nc||{};nc[key]=max;}
  25. return true;
  26. });
  27. };
  28. var mw=$(window).width(),mh=$(window).height(),pw=m.width(),ph=m.height(),nc=null;
  29. ensureVisible(['top','bottom'],mh-10,10-ph);
  30. ensureVisible(['left','right'],mw-10,10-pw);
  31. if(nc) m.css(nc);
  32. }
  33. function movable(o,name) {
  34. var m=$(o);
  35. if(!m.mousedown) return;
  36. o={};args=['right','bottom'];
  37. m.mousedown(function(e) {
  38. if(['DIV','TD'].indexOf(e.target.tagName)<0||e.target.contentEditable=='true') return;
  39. e.preventDefault();e.stopPropagation();
  40. o.x=e.pageX;
  41. if(args.indexOf('left')>=0) o.x-=parseInt(m.css('left'));
  42. else o.x+=parseInt(m.css('right'));
  43. o.y=e.pageY;
  44. if(args.indexOf('top')>=0) o.y-=parseInt(m.css('top'));
  45. else o.y+=parseInt(m.css('bottom'));
  46. if(!o.moving) $(document).mousemove(function(e) {
  47. if(o.moving) {
  48. var css={};
  49. for(var i in args) {
  50. var arg=args[i];
  51. if(arg=='left') css[arg]=e.pageX-o.x;
  52. else if(arg=='right') css[arg]=o.x-e.pageX;
  53. else if(arg=='top') css[arg]=e.pageY-o.y;
  54. else if(arg=='bottom') css[arg]=o.y-e.pageY;
  55. else continue;
  56. css[arg]+='px';
  57. }
  58. locate(m,css);
  59. }
  60. e.preventDefault();
  61. }).mouseup(function(e) {
  62. if(o.moving) {
  63. o.moving=false;
  64. var css={};
  65. for(var i in args) {
  66. var arg=args[i];
  67. css[arg]=m.css(arg);
  68. }
  69. utils.setObj('mcss_'+name,css);
  70. $(document).unbind('mousemove').unbind('mouseup');
  71. }
  72. });
  73. o.moving=true;
  74. });
  75. locate(m,utils.getObj('mcss_'+name,{}));
  76. }
  77. function unmovable(o) {$(o).unbind('mousedown').css({left:'',right:'',top:'',bottom:''});}
  78. function main(editor) {
  79. function unminify(){
  80. if(utils.unminify) {
  81. mn.hide();ep.show();editor.focus();delete utils.unminify;
  82. }
  83. }
  84. function minify(){
  85. ep.hide();mn.show();utils.unminify=unminify;
  86. // 献给大花猫
  87. // 在事件中调用的时候最好加上event.stopPropagation(),
  88. // 不然可能因为失去焦点导致窗口又重新被隐藏
  89. unsafeWindow.unminifyShare=unminify;
  90. }
  91. function floatUp(){
  92. if(sta=='normal'||!allowUp) styleUp.html('');
  93. else styleUp.html('\
  94. .edui-popup{bottom:44px;top:auto !important;}\
  95. .edui-popup-caret{bottom:-8px;top:auto !important;transform:scale(1,-1);-webkit-transform:scale(1,-1);}\
  96. ');
  97. }
  98. function updateMinifyButton() {
  99. if(sta=='open'&&allowMinify&&!allowMinifyOnBlur) mx.show();
  100. else mx.hide();
  101. }
  102. function showFloat() {
  103. if(sta=='open') {
  104. styleFloat.html('\
  105. .editor_title{width:610px !important;}\
  106. #ueditor_replace{min-height:50px !important;}\
  107. .poster_success{top:50px !important}\
  108. .old_style_wrapper{width:600px !important;}\
  109. .j_floating{margin-left:.5em;}\
  110. ');
  111. if(allowSimple) ep.attr('title','双击精简');
  112. } else {
  113. styleFloat.html('\
  114. .editor_title{width:360px !important;}\
  115. #ueditor_replace{min-height:24px !important;width:310px !important;}\
  116. .poster_success{top:0 !important;left:40px !important;}\
  117. .poster_signature,.editor_bottom_panel,.edui-toolbar{display:none !important;}\
  118. .editor_textfield{padding:0 !important;}\
  119. .old_style_wrapper{width:330px !important;}\
  120. ');
  121. ep.attr('title','双击展开');
  122. }
  123. updateMinifyButton();
  124. }
  125. function bindShortcut(){
  126. if(shortcut) utils.shortcut(shortcut,unminify);
  127. }
  128. function showSettings(e){
  129. e.stopPropagation();
  130. utils.popup.show({
  131. html:'\
  132. <div class="ge_sbtn" style="cursor:default">悬浮设置</div>\
  133. <label><input type=checkbox id=allowUp>向上弹出窗口</label><br>\
  134. <label><input type=checkbox id=allowSimple>双击精简或展开</label><br>\
  135. <label><input type=checkbox id=allowMinify>允许窗口隐藏</label><br>\
  136. <div style="margin-left:20px">\
  137. <label><input type=checkbox id=allowMinifyOnBlur>失去焦点时自动隐藏</label><br>\
  138. <label>呼出的快捷键:'+utils.getLink('hotkey',{title:'帮助',html:'(?)'})+'<input id=shortcut style="width:60px"></label><br>\
  139. </div>\
  140. ',
  141. className:'ge_opt',
  142. init:function(d){
  143. utils.bindProp($('#allowUp',d),'checked','allowUp',0,function(e){
  144. allowUp=this.checked;floatUp();
  145. });
  146. utils.bindProp($('#allowMinify',d),'checked','allowMinify',0,function(e){
  147. allowMinify=this.checked;showFloat();
  148. });
  149. utils.bindProp($('#allowMinifyOnBlur',d),'checked','allowMinifyOnBlur',0,function(e){
  150. allowMinifyOnBlur=this.checked;updateMinifyButton();
  151. });
  152. utils.bindProp($('#shortcut',d),'value','hk-float',0,function(e){
  153. if(shortcut) utils.shortcut(shortcut);
  154. shortcut=this.value;bindShortcut();
  155. });
  156. utils.bindProp($('#allowSimple',d),'checked','allowSimple',0,function(e){
  157. allowSimple=this.checked;showFloat();
  158. });
  159. },
  160. });
  161. }
  162. utils.addStyle('\
  163. #tb_rich_poster{box-shadow:2px 2px 8px;position:fixed !important;z-index:10001;background-color:#E7EAEB;}\
  164. #tb_rich_poster .editor_wrapper{margin-left:0;}\
  165. .poster_head,#bdInputObjWrapper,.tb_poster_placeholder,.poster_draft_status,.poster_reply{display:none !important;}\
  166. .editor_bottom_panel{margin-bottom:0 !important;}\
  167. .poster_body .poster_component{padding-bottom:0 !important;}\
  168. .float-button{position:absolute;bottom:0;right:0;cursor:pointer;line-height:2em;color:white;}\
  169. .float-button>div{display:none;background:brown;float:right;}\
  170. .float-button>div>*{display:inline-block;margin:0 .5em;}\
  171. .float-button>div>*:hover{text-shadow:2px 1px 2px black;}\
  172. .float-button:hover>div{display:block;}\
  173. .float-button::before{content:"...";position:absolute;right:.2em;bottom:0;}\
  174. .float-button:hover::before{content:"";}\
  175. .float-button::after{content:"";border-bottom:2em solid brown;border-left:2em solid transparent;float:right;}\
  176. #btUnminify{position:fixed;bottom:0;right:0;background:brown;color:white;font-weight:bold;padding:.5em;z-index:10;}\
  177. #btUnminify::before{content:"+";}\
  178. ');
  179. var styleFloat=utils.addStyle(),styleUp=utils.addStyle(),
  180. args,shortcut=utils.getObj('hk-float',''),
  181. sta=utils.getObj('float','open'),
  182. allowUp=utils.getObj('allowUp',true),
  183. allowMinify=utils.getObj('allowMinify',true),
  184. allowSimple=utils.getObj('allowSimple',true),
  185. allowMinifyOnBlur=utils.getObj('allowMinifyOnBlur',true),
  186. ep=$('#tb_rich_poster').dblclick(function(){
  187. if(allowSimple) {
  188. sta=sta=='open'?'close':'open';
  189. utils.setObj('float',sta);
  190. showFloat();
  191. }
  192. }).click(function(e){justClicked=e.target;}),justClicked=null,
  193. buttonFloat=$('<div>').appendTo($('<div class=float-button title="">').appendTo('#tb_rich_poster')),
  194. mn=$('<div id=btUnminify></div>').appendTo(document.body).mouseover(unminify).hide(),
  195. mx=$('<div>隐藏</div>').appendTo(buttonFloat).click(minify).hide();
  196. $('<div>悬浮设置</div>').prependTo(buttonFloat).click(showSettings);
  197. movable(ep[0],'float');
  198. editor.$container.attr('style','');
  199. showFloat();floatUp();bindShortcut();
  200. if(allowMinify) minify();
  201. $(document).click(function(e){
  202. if(justClicked) justClicked=null;
  203. else if(allowMinify&&allowMinifyOnBlur) minify();
  204. });
  205. $('.j_quick_reply').click(unminify);
  206. var o=$('#j_p_postlist');
  207. if(o.length) utils.find('.p_reply_first',o[0],function(o){o.click(unminify);});
  208. }
  209.  
  210. function initEditor(t) {
  211. t.init();t.unbindScrollEvent();main(unsafeWindow.test_editor);
  212. }
  213.  
  214. if(unsafeWindow.PosterContext&&unsafeWindow.PosterContext.isPostAllowed()) {
  215. if(unsafeWindow.test_editor) main(test_editor);
  216. else if(/"poster\/widget\/rich_poster"/.test(document.body.innerHTML))
  217. _.Module.use("poster/widget/rich_poster",{},initEditor);
  218. else _.Module.use("common/widget/RichPoster",{prefix:{}},initEditor);
  219. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址