MCBBS Emoticon Add

愉快的和朋友在论坛斗图吧!

当前为 2020-12-07 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name MCBBS Emoticon Add
  3. // @namespace http://fang.blog.miri.site
  4. // @version Gamma 4.0
  5. // @description 愉快的和朋友在论坛斗图吧!
  6. // @author Mr_Fang
  7. // @match https://*.mcbbs.net/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. var storage = window.localStorage;
  13.  
  14. if(jq('.user_info_menu_btn').length>0) {
  15. jq('.user_info_menu_btn').append('<li><a id="mbea_setting">Emoticon Add 设置</a></li>');
  16.  
  17. document.getElementById('mbea_setting').addEventListener('click',function(){
  18. showDialog('<style>.alert_right {background-image: none;padding-right: 0px;padding-left: 0px;}</style><div class=""><p><b>默认窗口位置</b> - 请输入1或0 <span style="color: gray; margin-left: 5px;" title="1 - 打开页面窗口默认最大化\n0 - 打开页面窗口默认最小化\n输入其它值则默认为0">[?]</span></p><input id="input_windowmode" style="width: 340px;" value="' + storage.getItem('mbea_windowmode') + '"><br><br><p><b>按规定格式添加即可</b> - 点击确定保存 <span style="color: gray; margin-left: 5px;" title="语法与Markdown相同:\n![描述](图片URL)">[?]</span> <span id="mbea_BatchImport" style="color: gray; margin-left: 5px;" title="点击进入批量导入GUI">[+]</span></p><textarea id="input_setting" style="width: 340px;" rows="20">' + storage.getItem('mbea_setting') + '</textarea>保存后刷新即可生效</div>',
  19. 'right',
  20. '<div style="line-height:30px;"><img src="https://s2.ax1x.com/2020/02/25/3twNzq.png" width="20px"> 设置 - MCBBS Emoticon Add</div>',
  21. function() {
  22. storage["mbea_setting"] = document.getElementById("input_setting").value;
  23. storage["mbea_windowmode"] = document.getElementById("input_windowmode").value;
  24. }
  25. );
  26.  
  27. document.getElementById('mbea_BatchImport').addEventListener('click',function(){
  28. showDialog('<style>.alert_right {background-image: none;padding-right: 0px;padding-left: 0px;}</style><div class=""><p><b>EShare链接</b> - 请输入URL <span style="color: gray; margin-left: 5px;" title="请输入在Emall或EATool处获取的EShare链接">[?]</span></p><input id="mbea_piurl" style="width: 340px;" value=""></div>',
  29. 'right',
  30. '<div style="line-height:30px;"><img src="https://s2.ax1x.com/2020/02/25/3twNzq.png" width="20px"> 批量导入表情 - MCBBS Emoticon Add</div>',
  31. function() {
  32. console.log("批量导入:" + document.getElementById("mbea_piurl").value);
  33. if(document.getElementById("mbea_piurl").value == ""){
  34. console.log("piurl是空值!");
  35. return false;
  36. }
  37. jq.ajax({
  38. type:'get',
  39. url:document.getElementById("mbea_piurl").value,
  40. success:function(body,heads,status){
  41. var piJSON = body;
  42. var piStr = JSON.parse(piJSON);
  43. piStr = Object.values(piStr);
  44.  
  45. console.log("成功导入JSON:\n包名:" + piStr[0]["PackName"] + "("+ piStr[0]["Version"] +")\n作者:" + piStr[0]["Author"]);
  46. for(var i=0;i<piStr[1].length;i++){
  47. storage["mbea_setting"] = storage["mbea_setting"] + "\n" + piStr[1][i];
  48. }
  49. }
  50. });
  51. }
  52. );
  53. })
  54. })
  55.  
  56. }
  57.  
  58.  
  59. var list = "";
  60. var setting = "";
  61.  
  62. setting = "[" + storage.getItem('mbea_setting') + "]";
  63.  
  64.  
  65. //阿方很菜的,不会批量替换,预计下个版本直接批量替换
  66. //console.log(setting);
  67. console.log(setting.split('\n').length);
  68. for(var l=0;l<setting.split('\n').length;l++){
  69. setting = setting.replace('![',"['");
  70. setting = setting.replace('](',"','");
  71. setting = setting.replace(')\n',"'],\n");
  72. //console.log(setting);
  73. }
  74. setting = setting.replace(')',"']");
  75.  
  76. var arrayList = eval("(" + setting + ")");
  77. console.log(arrayList);
  78.  
  79. for(var i=0;i<arrayList.length;i++){
  80. list = list + '<div class="mbea_img"><img id="imgbutton" onclick="setCopy(\'[img]' + arrayList[i][1] + '[/img]\');" src="' + arrayList[i][1] + '" width="100%" title="' + arrayList[i][0] + '" ></div>';
  81. };
  82.  
  83.  
  84. var display = false;
  85. var mbea_window_top = "95%";
  86. var window_mode = storage.getItem('mbea_windowmode');
  87. if(window_mode == "1"){
  88. display = true;
  89. mbea_window_top = "100px";
  90. }else{
  91. display = false;
  92. mbea_window_top = "95%";
  93. }
  94.  
  95. jq("head").append(`
  96. <style type="text/css" >
  97. .dialog
  98. {
  99. width:250px;
  100. height:250px;
  101. background-color: rgba(0,0,0,0.3);
  102. -webkit-box-shadow:1px 1px 3px #292929;
  103. -moz-box-shadow:1px 1px 3px #292929;
  104. box-shadow:1px 1px 3px #292929;
  105. margin:10px;
  106. z-index: 899;
  107. position: fixed;
  108. left: 100px;
  109. top: ` + mbea_window_top + `;
  110. overflow:auto;
  111. user-select: none;
  112. }
  113.  
  114. .dialog::-webkit-scrollbar
  115. {
  116. width: 4px;
  117. width: 4px;
  118. }
  119.  
  120. .dialog::-webkit-scrollbar-thumb
  121. {
  122. background: rgba(0,0,0,0.5);
  123. }
  124.  
  125. .dialog-title
  126. {
  127. color:#fff;
  128. background-color: rgba(0,0,0,0.5);
  129. font-size:12pt;
  130. font-weight:bold;
  131. padding:4px 6px;
  132. cursor:move;
  133. }
  134.  
  135. .dialog-content
  136. {
  137. padding:4px;
  138. color:#fff;
  139. }
  140. div.mbea_img{
  141. width: 35px;
  142. height: 35px;
  143. display: inline-block;
  144. padding:5px;
  145. }
  146. </style>
  147. <script type="text/javascript">
  148. var Dragging=function(validateHandler){ //参数为验证点击区域是否为可移动区域,如果是返回欲移动元素,负责返回null
  149. var draggingObj=null; //dragging Dialog
  150. var diffX=0;
  151. var diffY=0;
  152.  
  153. function mouseHandler(e){
  154. switch(e.type){
  155. case 'mousedown':
  156. draggingObj=validateHandler(e);//验证是否为可点击移动区域
  157. if(draggingObj!=null){
  158. diffX=e.clientX-draggingObj.offsetLeft;
  159. diffY=e.clientY-draggingObj.offsetTop;
  160. }
  161. break;
  162.  
  163. case 'mousemove':
  164. if(draggingObj){
  165. draggingObj.style.left=(e.clientX-diffX)+'px';
  166. draggingObj.style.top=(e.clientY-diffY)+'px';
  167. }
  168. break;
  169.  
  170. case 'mouseup':
  171. draggingObj =null;
  172. diffX=0;
  173. diffY=0;
  174. break;
  175. }
  176. };
  177.  
  178. return {
  179. enable:function(){
  180. document.addEventListener('mousedown',mouseHandler);
  181. document.addEventListener('mousemove',mouseHandler);
  182. document.addEventListener('mouseup',mouseHandler);
  183. },
  184. disable:function(){
  185. document.removeEventListener('mousedown',mouseHandler);
  186. document.removeEventListener('mousemove',mouseHandler);
  187. document.removeEventListener('mouseup',mouseHandler);
  188. }
  189. }
  190. }
  191.  
  192. function getDraggingDialog(e){
  193. var target=e.target;
  194. while(target && target.className.indexOf('dialog-title')==-1){
  195. target=target.offsetParent;
  196. }
  197. if(target!=null){
  198. return target.offsetParent;
  199. }else{
  200. return null;
  201. }
  202. }
  203.  
  204. Dragging(getDraggingDialog).enable();
  205. </script>`);
  206. jq("body").prepend(`<div id="dlgTest" class="dialog">
  207. <div class="dialog-title">自定义表情<span style="float: right;cursor: pointer;" onclick="jq('div.dialog').css('top','100px');" title="最大化">[↑]</span><span style="float: right;cursor: pointer;" onclick="jq('div.dialog').css('top','95%');" title="最小化">\[↓]</span></div>
  208. <div class="dialog-content">
  209. ` + list + `
  210. </div>
  211. </div>`);
  212.  
  213. document.getElementById('imgbutton').addEventListener('click',function(){
  214. seditor_insertunit('fastpost', '111');
  215. })
  216.  
  217. document.onkeydown = function(e) {
  218. var keyCode = e.keyCode;
  219. var shiftKey = e.shiftKey;
  220. var ctrlKey = e.ctrlKey;
  221. if(ctrlKey && shiftKey && keyCode == 69) {
  222. if(display == true){
  223. jq('div.dialog').css('top','95%')
  224. display = false;
  225. mbea_input(1111);
  226. }else{
  227. jq('div.dialog').css('top','100px')
  228. display = true;
  229. mbea_input(1111);
  230. }
  231. }
  232. };
  233. })();