tieba_faceText

百度贴吧颜文字

当前为 2014-06-18 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name tieba_faceText
  3. // @description 百度贴吧颜文字
  4. // @include http://tieba.baidu.com/*
  5. // @exclude http://tieba.baidu.com/mo/*
  6. // @exclude http://tieba.baidu.com/i/*
  7. // @exclude http://tieba.baidu.com/f/like*
  8. // @exclude http://tieba.baidu.com/club/*
  9. // @exclude http://tieba.baidu.com/shipin/*
  10. // @exclude http://tieba.baidu.com/bakan*
  11. // @exclude http://tieba.baidu.com/daquan*
  12. // @exclude http://tieba.baidu.com/f/tupian*
  13. // @exclude http://tieba.baidu.com/tb/*
  14. // @exclude http://tieba.baidu.com/*postBrowserBakan*
  15. // @icon http://tb.himg.baidu.com/sys/portraitn/item/4e2ed7f8bbb3d4f2c2d2bb21
  16. // @require http://code.jquery.com/jquery-latest.min.js
  17. // @author congxz6688
  18. // @version 2014.6.18.0
  19. // @grant GM_addStyle
  20. // @grant GM_getValue
  21. // @grant GM_setValue
  22. // @grant GM_deleteValue
  23. // @namespace https://greasyfork.org/scripts/150
  24. // ==/UserScript==
  25.  
  26.  
  27. //初始颜文字表情
  28. var defaultFaceText = {
  29. "faceText0" : ["(>_<)", "o(>< )o", "o( ><)o", "(>д<)", "ヽ(#`Д´)ノ", "ヽ(≧Д≦)ノ", ">﹏<", "┌( ಠ_ಠ)┘"],
  30. "faceText1" : ["( ̄︿ ̄)", "(¬д¬。)", "(¬、¬)", "(;¬_¬)", "(;¬_¬)", "(;¬д¬)", "( ;´Д`)", "o( ̄ヘ ̄o#)"],
  31. "faceText2" : ["T_T", "(T_T)", "( TДT)", "(ToT)", "(T▽T)", "(T_T)", "(;へ:)", "(ノД`)・゜・。", "(´_`。)", "(´A`。)", "(´∩`。)", "。・゚゚・(>д<;)・゚゚・。", "(*´;ェ;`*)", "(个_个)", ",,Ծ‸Ծ,,", "〒▽〒"],
  32. "faceText3" : ["(*゚∇゚)", "(*´∀`)", "( ゚∀゚)", "o(ノ゚∀゚)ノ", "( ̄∇ ̄)", "o(*≥▽≤)ツ", "(`・ω・´)", "(。◕∀◕。)", "ノ( ◕‿‿◕ )ノ", "(๑→ܫ←)", "(@ ̄) ̄@)", "(●'‿'●)", "(✿✪‿✪。)ノ♡", "(O ^ ~ ^ O)"],
  33. "faceText4" : ["( ̄(エ) ̄)", "(^(エ)^)", "⊂(・(ェ)・)⊃", "(* ̄(エ) ̄*)", "(=^・ェ・^=)", "(=;ェ;=)", "ヽ(=^・ω・^=)丿", "<(*ΦωΦ*)>", "Uo・ェ・oU", "ヾ(●ω●)ノ", "U・♀・U", "U^ェ^U", "(´(ェ)‘)"],
  34. "faceText5" : ["(*・_・)ノ⌒ ⌒ ⌒╭*", "*★.°*:.☆( ̄▽ ̄)ノ:*.°★* 。", "╭∩╮( ̄︿ ̄)╭∩╮", "(╯`□′)╯~~╧╧", "((((*。_。)_", "⊂彡☆))д`)", "( ̄3 ̄)", "(|||゚д゚)", "( д ) ゚ ゚", "@_@", "-_-!!!", "(`ε´ )", "(→_→)", "(@[]@!!)"],
  35. "faceText6" : ["⊙﹏⊙‖∣°", "(—。—) . z Z", "d(*◕ ‿ -) :|} - - >>—>"],
  36. "faceText7" : ["段落演示"]
  37. };
  38. var EasyInsertTextDemo = {"段落演示" : "坐怀则乱是天然纯洁的,我们都要爱护他。"};
  39.  
  40. //下面这一段CSS,可帮助编辑器工具栏不够用的同学,会CSS的同学可删除它。
  41. var forCss2er = ".cut_screen{display:none!important;}";
  42. forCss2er += ".tb-editor-wrapper{width:720px !important}";
  43. forCss2er += ".recentImgDiv>.tb-editor-overlay{left:28% !important; top:30px !important;}";
  44. GM_addStyle(forCss2er);
  45.  
  46.  
  47.  
  48.  
  49. //脚本双存储相互恢复
  50. if (!localStorage.userFaceText && GM_getValue("userFaceText", "") != "") {
  51. localStorage.userFaceText = GM_getValue("userFaceText");
  52. }
  53. if (GM_getValue("userFaceText", "") == "" && localStorage.userFaceText) {
  54. GM_setValue("userFaceText", localStorage.userFaceText);
  55. }
  56.  
  57. if (!localStorage.EasyInsertText && GM_getValue("EasyInsertText", "") != "") {
  58. localStorage.EasyInsertText = GM_getValue("EasyInsertText");
  59. }
  60. if (GM_getValue("EasyInsertText", "") == "" && localStorage.EasyInsertText) {
  61. GM_setValue("EasyInsertText", localStorage.EasyInsertText);
  62. }
  63.  
  64. //脚本主CSS
  65. var replyCss = "";
  66. replyCss += ".insertFacetxt,.quickInsert{background-color: #E5E5E0; padding:0px 3px; margin:2px 6px; cursor:pointer; display:inline-block;}";
  67. replyCss += "#faceTextDiv{background-color:lightGrey; width:650px; border:4px double gray;}";
  68. replyCss += ".FTLeftDiv{cursor:pointer; display:inline-block; background-color:lightGrey;padding:3px 10px; width:36px;}";
  69. replyCss += ".FTRightDiv{display:inline-block; background-color:lightGrey; padding:3px 6px; width:579px;}";
  70. replyCss += ".closeFTDivbt{cursor:pointer; float:right; margin:0px -2px; width:16px; height:16px;}";
  71. replyCss += "#editorButton{cursor:pointer; margin:0 0 0 16px; display:inline-block; color:#3163B6; padding: 1px 1px 10px 1px; position:relative; top:0px}";
  72. replyCss += "#editorButton_lzl{margin:0 5px 3px 5px; float:right;cursor:pointer; font-size:1.2em; display:inline-block; color:#3163B6;}";
  73. replyCss += ".editFaceTxtTb{width:200px; padding:1px 1px 0 0;} .inputInTdFt{width:199px;} .FTbutton{float:right; padding:0px 10px; margin:15px 10px 0px 0px}";
  74. replyCss += "#defaultDiv{color: red; padding:0px 10px; margin:15px 0px 0px 159px}";
  75. replyCss += "#newEditDiv{border: 1px solid gray; width:612px; z-index:9999; background-color:#EEEEEE; padding:20px; position:fixed; left:200px; bottom:80px;} #newEditDiv *:not(.pageTitle),#faceTextDiv *{font-size:12px !important;}";
  76. replyCss += ".quickEditdiv{margin:1px; border: 1px solid gray; width:200px; display:inline-block;}"
  77. replyCss += ".qdisplayDiv{margin-left:3px; width:137px; display:inline-block;}"
  78. replyCss += ".modifyQuichText{padding-left:3px; background-color:#D0FFD0; cursor:pointer; width:27px; display:inline-block;}"
  79. replyCss += ".deleteQuichText{padding-left:3px; background-color:#FFD0D0; cursor:pointer; width:27px; display:inline-block;}";
  80. replyCss += "#fuuuffs{width:612px;} .margin-top30{padding-top:20px;} .editSbuttom{ display:inline-block; padding:0px 10px; margin-right:9px; margin-top:10px;}"
  81. replyCss += "#titleInput{width:136px;} #lotTextArea{width:454px} #inSertThenSubmit{position:relative; top:1px;} .checkboxDiv{float:right; margin:18px 50px 0px 0px}";
  82. GM_addStyle(replyCss);
  83.  
  84. var Tds = []; //数据修改用列表
  85.  
  86.  
  87. //函数 数组字符串重排序
  88. Array.prototype.reIndex = function () {
  89. var lastStr = this.sort(function (a, b) {
  90. return a.localeCompare(b)
  91. });
  92. return lastStr;
  93. }
  94. //元素精确监听
  95. function addNodeInsertedListener(elCssPath, handler, executeOnce, noStyle) {
  96. var animName = "anilanim",
  97. prefixList = ["-o-", "-ms-", "-khtml-", "-moz-", "-webkit-", ""],
  98. eventTypeList = ["animationstart", "webkitAnimationStart", "MSAnimationStart", "oAnimationStart"],
  99. forEach = function (array, func) {
  100. for (var i = 0, l = array.length; i < l; i++) {
  101. func(array[i]);
  102. }
  103. };
  104. if (!noStyle) {
  105. var css = elCssPath + "{",
  106. css2 = "";
  107. forEach(prefixList, function (prefix) {
  108. css += prefix + "animation-duration:.001s;" + prefix + "animation-name:" + animName + ";";
  109. css2 += "@" + prefix + "keyframes " + animName + "{from{opacity:.9;}to{opacity:1;}}";
  110. });
  111. css += "}" + css2;
  112. GM_addStyle(css);
  113. }
  114. if (handler) {
  115. var bindedFunc = function (e) {
  116. var els = document.querySelectorAll(elCssPath),
  117. tar = e.target,
  118. match = false;
  119. if (els.length !== 0) {
  120. forEach(els, function (el) {
  121. if (tar === el) {
  122. if (executeOnce) {
  123. removeNodeInsertedListener(bindedFunc);
  124. }
  125. handler.call(tar, e);
  126. return;
  127. }
  128. });
  129. }
  130. };
  131. forEach(eventTypeList, function (eventType) {
  132. document.addEventListener(eventType, bindedFunc, false);
  133. });
  134. return bindedFunc;
  135. }
  136. }
  137. //移除精确监听
  138. function removeNodeInsertedListener(bindedFunc) {
  139. var eventTypeList = ["animationstart", "webkitAnimationStart", "MSAnimationStart", "oAnimationStart"],
  140. forEach = function (array, func) {
  141. for (var i = 0, l = array.length; i < l; i++) {
  142. func(array[i]);
  143. }
  144. };
  145. forEach(eventTypeList, function (eventType) {
  146. document.removeEventListener(eventType, bindedFunc, false);
  147. });
  148. }
  149. //提取localStorage的参数
  150. function getLSJS(a){
  151. return JSON.parse(localStorage[a] ? localStorage[a] : "{}");
  152. }
  153. //简化脚本
  154. function crE(a){
  155. return document.createElement(a);
  156. }
  157. function getId(a){
  158. return document.getElementById(a);
  159. }
  160. //函数 载入各名单
  161. function loadThe(ff) {
  162. function ffe(ww) {
  163. $("#tdRightDiv" + ww + ">.insertFacetxt,#tdRightDiv" + ww + ">.quickInsert").remove();
  164. var searchSave = getLSJS("userFaceText");
  165. myFri = (searchSave["faceText" + ww]) ? searchSave["faceText" + ww] : defaultFaceText["faceText" + ww];
  166. if (ww == "7") {
  167. aqq = (localStorage.EasyInsertText) ? JSON.parse(localStorage.EasyInsertText) : EasyInsertTextDemo;
  168. myFri = myFri.reIndex();
  169. }
  170. var parentDiv = $("#tdRightDiv" + ww);
  171. if (myFri.length != 0) {
  172. for (l = 0; l < myFri.length; l++) {
  173. $("<span>", {
  174. html : myFri[l],
  175. title : ((ww == "7") ? ((aqq[myFri[l]].length < 30) ? aqq[myFri[l]] : aqq[myFri[l]].substr(0, 30) + "...") : undefined),
  176. class : ((ww == "7") ? "quickInsert" : "insertFacetxt"),
  177. click : insertEdiror
  178. }).appendTo(parentDiv);
  179. }
  180. }
  181. }
  182. if (ff == "all") {
  183. for (p = 0; p < 8; p++) {
  184. ffe("" + p);
  185. }
  186. } else {
  187. ffe(ff);
  188. }
  189. }
  190. //保存数据
  191. function saveData(a, b) {
  192. if ($.isEmptyObject(a)) {
  193. localStorage.removeItem(b);
  194. GM_deleteValue(b);
  195. } else {
  196. localStorage[b] = JSON.stringify(a);
  197. GM_setValue(b, JSON.stringify(a));
  198. }
  199. }
  200.  
  201. //函数 插入到编辑器
  202. function insertEdiror(e) {
  203. var whh = e.target.innerHTML;
  204. var insertKind = e.target.getAttribute("class");
  205. if (insertKind == "quickInsert") {
  206. var InsertText = ((localStorage.EasyInsertText) ? JSON.parse(localStorage.EasyInsertText) : EasyInsertTextDemo)[whh] + "&nbsp;";
  207. } else {
  208. var InsertText = whh + "&nbsp;";
  209. }
  210. var editor = (localStorage['FT_which_editor']) ? localStorage['FT_which_editor'] : 'editorButton';
  211. if (editor == "editorButton") {
  212. unsafeWindow.test_editor.execCommand("inserthtml", InsertText);
  213. setTimeout(function () {
  214. if (insertKind == "quickInsert" && window.location.href.indexOf("kw=") == -1 && GM_getValue('inSertThenSubmit', false)) {
  215. document.querySelector(".poster_submit").click();
  216. }
  217. }, 1000);
  218. } else if (InsertText.indexOf("<img") == -1 || InsertText.indexOf("http://static.tieba.baidu.com") != -1) {
  219. unsafeWindow.LzlEditor._s_p._se.execCommand("inserthtml", InsertText);
  220. setTimeout(function () {
  221. if (insertKind == "quickInsert" && window.location.href.indexOf("kw=") == -1 && GM_getValue('inSertThenSubmit', false)) {
  222. document.querySelector(".lzl_panel_btn>.lzl_panel_submit").click();
  223. }
  224. }, 500);
  225. }
  226. closeFaceTxttable();
  227. }
  228. //列表创建函数
  229. function creaseTable(UrlLength) {
  230. var tablepp = crE("table");
  231. tablepp.id = "tablepp";
  232. var trs = [];
  233. for (ly = 0; ly <= Math.ceil(UrlLength / 3); ly++) {
  234. var tr = crE("tr");
  235. mmd = trs.push(tr);
  236. tablepp.appendChild(tr);
  237. }
  238. for (ls = 0; ls < trs.length * 3; ls++) {
  239. var td = crE("td");
  240. td.className = "editFaceTxtTb";
  241. td.innerHTML = "<input type='text' class='inputInTdFt' value=''>";
  242. wq = Tds.push(td);
  243. trs[Math.floor(ls / 3)].appendChild(td);
  244. }
  245. return tablepp
  246. }
  247. //函数 编辑我的自定义颜文字
  248. function promptUserFT(ev) {
  249. if (!getId("newEditDiv")) {
  250. var wK = ev.target.id.split("tdLeftDiv")[1];
  251. var ujuy = getLSJS("userFaceText");
  252. var faceText = (ujuy["faceText" + wK]) ? ujuy["faceText" + wK] : defaultFaceText["faceText" + wK];
  253.  
  254. var newEditDiv = crE("div");
  255. newEditDiv.id = "newEditDiv";
  256.  
  257. $("<div>", {
  258. class : "pageTitle",
  259. html : "可直接修改表格内容或添加新表情到表格中:"
  260. }).css({
  261. "font-size" : "16px",
  262. "margin-bottom" : "15px"
  263. }).appendTo(newEditDiv);
  264.  
  265. newTable = creaseTable(faceText.length);
  266. newEditDiv.appendChild(newTable);
  267.  
  268. var yesButton = crE("input");
  269. yesButton.type = "button";
  270. yesButton.className = "FTbutton";
  271. yesButton.value = "确定";
  272. yesButton.addEventListener("click", function () {
  273. var reGetArray = [];
  274. var hht = document.getElementsByClassName("inputInTdFt");
  275. for (hh = 0; hh < hht.length; hh++) {
  276. if (hht[hh].value != "") {
  277. ko = reGetArray.push(hht[hh].value.trim());
  278. }
  279. }
  280. if (reGetArray.length > 0) {
  281. if (reGetArray.toString() != faceText.toString()) {
  282. ujuy["faceText" + wK] = reGetArray;
  283. }
  284. } else {
  285. delete ujuy["faceText" + wK];
  286. }
  287. saveData(ujuy, "userFaceText")
  288. loadThe(wK);
  289.  
  290. $(".inputInTdFt").html("");
  291. $("#tablepp").detach();
  292. $("#newEditDiv").detach();
  293. }, false);
  294. newEditDiv.appendChild(yesButton);
  295.  
  296. var addButton = crE("input");
  297. addButton.type = "button";
  298. addButton.className = "FTbutton";
  299. addButton.value = "加行";
  300. addButton.addEventListener("click", function () {
  301. var tdNum = document.getElementsByClassName("inputInTdFt").length;
  302. var newTr = crE("tr");
  303. getId("tablepp").appendChild(newTr);
  304. for (es = 0; es < 3; es++) {
  305. var newTD = crE("td");
  306. newTD.className = "editFaceTxtTb";
  307. newTD.innerHTML = "<input type='text' class='inputInTdFt' value=''>";
  308. newTr.appendChild(newTD);
  309. }
  310. }, false);
  311. newEditDiv.appendChild(addButton);
  312.  
  313. if (ujuy["faceText" + wK]) {
  314. var addButton = crE("input");
  315. addButton.type = "button";
  316. addButton.className = "FTbutton";
  317. addButton.value = "恢复本类默认";
  318. addButton.addEventListener("click", function () {
  319. var alertMe = confirm("这一动作将删除本类表情的修改和添加,\r\n你确定要这么做吗?");
  320. if (alertMe) {
  321. delete ujuy["faceText" + wK];
  322. saveData(ujuy, "userFaceText");
  323. loadThe(wK);
  324. $(".inputInTdFt").html("");
  325. $("#tablepp").detach();
  326. $("#newEditDiv").detach();
  327. }
  328. }, false);
  329. newEditDiv.appendChild(addButton);
  330. }
  331.  
  332. document.body.appendChild(newEditDiv);
  333.  
  334. for (ss = 0; ss < faceText.length; ss++) {
  335. document.getElementsByClassName("inputInTdFt")[ss].value = faceText[ss];
  336. }
  337. }
  338. }
  339. //函数 编辑我的快速输入文字
  340. function promptEasyInsert() {
  341. if (!getId("newEditDiv")) {
  342. var newEditDiv = crE("div");
  343. newEditDiv.id = "newEditDiv";
  344. document.body.appendChild(newEditDiv);
  345.  
  346. $("<div>", {
  347. html : "段落快速输入功能的设置页",
  348. class : "pageTitle"
  349. }).css({
  350. "font-size" : "16px",
  351. "margin-bottom" : "15px"
  352. }).appendTo(newEditDiv);
  353.  
  354. var tablepp = crE("table");
  355. var tr1 = crE("tr");
  356. var td1 = crE("td");
  357. td1.setAttribute("colspan", "2");
  358. var ffdiv = crE("div");
  359. ffdiv.id = "fuuuffs";
  360. td1.appendChild(ffdiv);
  361. tr1.appendChild(td1);
  362.  
  363. var tr3 = crE("tr");
  364. var td6 = crE("td");
  365. td6.className = "margin-top30";
  366. td6.innerHTML = "这里输入段落名称:";
  367. var td7 = crE("td");
  368. td7.className = "margin-top30";
  369. td7.innerHTML = "这里输入段落内容:";
  370. tr3.appendChild(td6);
  371. tr3.appendChild(td7);
  372.  
  373. var tr2 = crE("tr");
  374. var td2 = crE("td");
  375.  
  376. var inputTit = crE("input");
  377. inputTit.type = "text";
  378. inputTit.id = "titleInput";
  379. inputTit.value = "";
  380. td2.appendChild(inputTit);
  381.  
  382. var saveButton = crE("input");
  383. saveButton.className = "editSbuttom";
  384. saveButton.type = "button";
  385. saveButton.value = "保 存";
  386. saveButton.addEventListener("click", function () {
  387. var titValue = getId("titleInput").value;
  388. var innText = getId("lotTextArea").value.replace(/\n/g, "<br>");
  389. if (innText.indexOf('<img') == -1) {
  390. //自动识别图片并加标签http://imgsrc.baidu.com/forum/pic/item/
  391. innText = innText.replace(/(http:\/\/(?!static\.tieba).*?)([0-9a-z]{40})(\.jpg|\.png|\.gif)/i, '<img class="BDE_Image" unselectable="on" onload="EditorUI.resizeImage(this, 560)" pic_type="1" src="' + 'http://imgsrc.baidu.com/forum/pic/item/' + '$2$3">');
  392. //自动识别表情并加标签
  393. innText = innText.replace(/(http:\/\/static\.tieba\.baidu\.com.*?)(\.jpg|\.png|\.gif)/i, '<img class="BDE_Smiley" unselectable="on" onload="EditorUI.resizeImage(this, 560)" pic_type="1" src="$1$2">');
  394. }
  395. if (titValue != "" && innText != "") {
  396. var userFacee = getLSJS("userFaceText");
  397. var temmm = (userFacee.faceText7) ? userFacee.faceText7 : [];
  398. if (temmm.indexOf(titValue) != -1) {
  399. var coverAlert = confirm("已经有了一个同名的段落,要覆盖吗?");
  400. if (coverAlert) {
  401. var temss = getLSJS("EasyInsertText");
  402. temss[titValue] = innText;
  403. localStorage.EasyInsertText = JSON.stringify(temss);
  404. GM_setValue("EasyInsertText", JSON.stringify(temss));
  405.  
  406. getId("titleInput").value = "";
  407. getId("lotTextArea").value = "";
  408. EditQuickLoad();
  409. }
  410. } else {
  411. sdd = temmm.push(titValue);
  412. userFacee.faceText7 = temmm;
  413. localStorage.userFaceText = JSON.stringify(userFacee);
  414. GM_setValue("userFaceText", JSON.stringify(userFacee));
  415.  
  416. var temss = getLSJS("EasyInsertText");
  417. temss[titValue] = innText;
  418. localStorage.EasyInsertText = JSON.stringify(temss);
  419. GM_setValue("EasyInsertText", JSON.stringify(temss));
  420.  
  421. getId("titleInput").value = "";
  422. getId("lotTextArea").value = "";
  423. EditQuickLoad();
  424. }
  425. } else {
  426. var message = (titValue == "") ? "段落名称" : "段落内容";
  427. alert(message + "不能为空!请填好再按保存。");
  428. }
  429. }, false);
  430. td2.appendChild(saveButton);
  431.  
  432. var clearButton = crE("input");
  433. clearButton.className = "editSbuttom";
  434. clearButton.type = "button";
  435. clearButton.value = "清 除";
  436. clearButton.addEventListener("click", function () {
  437. getId("titleInput").value = "";
  438. getId("lotTextArea").value = "";
  439. }, false);
  440. td2.appendChild(clearButton);
  441.  
  442. var td3 = crE("td");
  443. var inTextArea = crE("textarea");
  444. inTextArea.id = "lotTextArea";
  445. inTextArea.rows = "3";
  446. td3.appendChild(inTextArea);
  447.  
  448. tr2.appendChild(td2);
  449. tr2.appendChild(td3);
  450. tablepp.appendChild(tr1);
  451. tablepp.appendChild(tr3);
  452. tablepp.appendChild(tr2);
  453. newEditDiv.appendChild(tablepp);
  454.  
  455. function EditQuickLoad() {
  456. $(".quickEditdiv").remove();
  457. var ujuy = getLSJS("userFaceText");
  458. var faceText = (ujuy["faceText7"]) ? ujuy["faceText7"] : defaultFaceText["faceText7"];
  459. faceText = faceText.reIndex();
  460. for (ls = 0; ls < faceText.length; ls++) {
  461. var inlineBlock = crE("div");
  462. inlineBlock.className = "quickEditdiv";
  463.  
  464. var newspan = crE("span");
  465. newspan.innerHTML = faceText[ls];
  466. newspan.className = "qdisplayDiv";
  467. inlineBlock.appendChild(newspan);
  468.  
  469. var modifyBu = crE("span");
  470. modifyBu.className = "modifyQuichText";
  471. modifyBu.setAttribute("qval", faceText[ls]);
  472. modifyBu.title = "点击以后到下面修改";
  473. modifyBu.innerHTML = "修改";
  474. modifyBu.addEventListener("click", modifyQuickText, false);
  475. inlineBlock.appendChild(modifyBu);
  476.  
  477. var deleteBu = crE("span");
  478. deleteBu.className = "deleteQuichText";
  479. deleteBu.setAttribute("qval", faceText[ls]);
  480. deleteBu.title = "删除这一条";
  481. deleteBu.innerHTML = "删除";
  482. deleteBu.addEventListener("click", deleteQuickText, false);
  483. inlineBlock.appendChild(deleteBu);
  484.  
  485. ffdiv.appendChild(inlineBlock);
  486. }
  487. }
  488. function modifyQuickText(ee) {
  489. var yaa = ee.target.getAttribute("qval");
  490. getId("titleInput").value = yaa;
  491. getId("lotTextArea").value =((localStorage.EasyInsertText) ? JSON.parse(localStorage.EasyInsertText) : EasyInsertTextDemo)[yaa];
  492. }
  493. function deleteQuickText(ee) {
  494. var yaa = ee.target.getAttribute("qval");
  495. var deleteAlert = confirm("删除段落: " + yaa + "\r\n\r\n你确定吗?");
  496. if (deleteAlert) {
  497. var userFace = getLSJS("userFaceText");
  498. var temm = (userFace.faceText7) ? userFace.faceText7.toString().replace("," + yaa, "").replace(yaa + ",", "").replace(yaa, "") : "";
  499. if (temm == "") {
  500. delete userFace.faceText7;
  501. } else {
  502. userFace.faceText7 = temm.split(",");
  503. }
  504. saveData(userFace, "userFaceText");
  505. var tema = getLSJS("EasyInsertText");
  506. delete tema[yaa];
  507. saveData(tema, "EasyInsertText");
  508. EditQuickLoad();
  509. }
  510. }
  511. EditQuickLoad();
  512.  
  513. //确定按钮
  514. var yesButton = crE("input");
  515. yesButton.type = "button";
  516. yesButton.className = "FTbutton";
  517. yesButton.value = "关 闭 本 页";
  518. yesButton.addEventListener("click", function () {
  519. loadThe("7");
  520. document.body.removeChild(getId("newEditDiv"));
  521. }, false);
  522. newEditDiv.appendChild(yesButton);
  523.  
  524. //福利
  525. var smallDiv = crE("div");
  526. smallDiv.className = "checkboxDiv";
  527. var inSertThenSubmit = crE("input");
  528. inSertThenSubmit.type = "checkbox";
  529. inSertThenSubmit.id = "inSertThenSubmit";
  530. inSertThenSubmit.checked = GM_getValue('inSertThenSubmit', false);
  531. inSertThenSubmit.addEventListener('click', function () {
  532. GM_setValue('inSertThenSubmit', getId("inSertThenSubmit").checked);
  533. }, true);
  534. smallDiv.appendChild(inSertThenSubmit);
  535. var smallSpan = crE("span");
  536. smallSpan.innerHTML = " 插入后自动发表";
  537. smallDiv.appendChild(smallSpan);
  538. newEditDiv.appendChild(smallDiv);
  539.  
  540. //全部恢复默认
  541. var defaultDiv = crE("input");
  542. defaultDiv.type = "button";
  543. defaultDiv.title = "除非保存的数据出现无法恢复的异常,否则最好不要用这个!";
  544. defaultDiv.id = "defaultDiv";
  545. defaultDiv.value = "删 除 所 有 段 落";
  546. defaultDiv.addEventListener('click', function () {
  547. var deleteAlert = confirm("!!!把所有保存的段落全部删除!!!\r\n\r\n数据将无法恢复!你确定吗?");
  548. if (deleteAlert) {
  549. var defaultTemp = getLSJS("userFaceText");
  550. delete defaultTemp.faceText7;
  551. saveData(defaultTemp, "userFaceText");
  552. localStorage.removeItem("EasyInsertText");
  553. GM_deleteValue("EasyInsertText");
  554. EditQuickLoad();
  555. }
  556. }, true);
  557. newEditDiv.appendChild(defaultDiv);
  558. }
  559. }
  560. //函数 绝对定位
  561. function getElementLeft(element) {
  562. var actualLeft = element.offsetLeft;
  563. var current = element.offsetParent;
  564. while (current !== null) {
  565. actualLeft += current.offsetLeft;
  566. current = current.offsetParent;
  567. }
  568. return actualLeft;
  569. }
  570. //函数 绝对定位
  571. function getElementTop(element) {
  572. var actualTop = element.offsetTop;
  573. var current = element.offsetParent;
  574. while (current !== null) {
  575. actualTop += current.offsetTop;
  576. current = current.offsetParent;
  577. }
  578. return actualTop;
  579. }
  580. //主函数 由编辑窗上方的按钮调用,展开主列表
  581. function createFaceTexttable(ete) {
  582. if ($("#faceTextDiv").length == 0) {
  583. var ortt = ete.target;
  584. localStorage.FT_which_editor = (ortt.id == "editorButton") ? 'editorButton' : 'editorButton_lzl';
  585. var getTop = (ortt.id == "editorButton") ? getElementTop(ortt) + 32 : getElementTop(ortt) + 20;
  586. //定位主列表位置
  587. if ($('#tb_rich_poster').css('position')=='fixed' && ortt.id == "editorButton") { //原子的悬浮窗
  588. var faceTextDiv = $("<div>", {
  589. id : "faceTextDiv"
  590. }).css({
  591. "position" : "fixed",
  592. "z-index" : "9999",
  593. "right" : "20px",
  594. "bottom" : "24px"
  595. }).appendTo(document.body);
  596. } else if (ortt.id == "editorButton_lzl") { //楼中楼回复
  597. var faceTextDiv = $("<div>", {
  598. id : "faceTextDiv"
  599. }).css({
  600. "position" : "absolute",
  601. "z-index" : "9999",
  602. "left" : getElementLeft(ortt) - 300,
  603. "top" : getTop - 300
  604. }).appendTo(document.body);
  605. } else { //主窗
  606. content.scrollTo(0, 99999);
  607. var faceTextDiv = $("<div>", {
  608. id : "faceTextDiv"
  609. }).css({
  610. "position" : "absolute",
  611. "z-index" : "9999",
  612. "left" : getElementLeft(ortt) - 300,
  613. "top" : getTop
  614. }).appendTo(document.body);
  615. }
  616. //建表
  617. var atTable = crE("table");
  618. atTable.setAttribute("border", "1");
  619. atTable.setAttribute("bordercolor", "#B8B3FF");
  620. atTable.setAttribute("cellpadding", "6");
  621. getId("faceTextDiv").appendChild(atTable);
  622. //TR
  623. var tdLeftName = ["愤怒啊", "不高兴", "哭、苦", "欢喜悦", "狗熊猫", "其它类", "自定义", "快输入"]
  624. for (lk = 0; lk < 8; lk++) {
  625. var creaFttr = crE("tr");
  626.  
  627. var tdLeft = crE("td");
  628. var tdLeftDiv = crE("div");
  629. tdLeftDiv.className = "FTLeftDiv";
  630. tdLeftDiv.id = "tdLeftDiv" + lk;
  631. tdLeftDiv.innerHTML = tdLeftName[lk];
  632. tdLeftDiv.title = "点击可编辑";
  633. if (lk == 7) {
  634. tdLeftDiv.addEventListener("click", promptEasyInsert, false);
  635. } else {
  636. tdLeftDiv.addEventListener("click", promptUserFT, false);
  637. }
  638. tdLeft.appendChild(tdLeftDiv);
  639.  
  640. var tdRight = crE("td");
  641. var tdRightDiv = crE("div");
  642. tdRightDiv.className = "FTRightDiv";
  643. tdRightDiv.id = "tdRightDiv" + lk;
  644. tdRight.appendChild(tdRightDiv);
  645.  
  646. creaFttr.appendChild(tdLeft);
  647. creaFttr.appendChild(tdRight);
  648. atTable.appendChild(creaFttr);
  649. }
  650.  
  651. //关闭按钮
  652. var closeFTDivbt = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAACXBIWXMAAA7EAAAOxAGVKw4bAAAA8UlEQVR42pWSMQrCQBBFcwPvI3gNKwtvYGVhaStqJYiFjY0IFmIrWEXRFIISiIqohYUYFcTC1gc/BFkSEmGyzMz/f3ZmNlaxMSvU7JQG2eJzdvdEW3j++vgstZ1AsNz6OgHkG6EpCFPe5S2qjHBzfgGZAuLV4TGw952Rg6MMVEKSZEyB7V6BW8NlJlcu1ccUPt0+1e6UkBMIgtkSKUi9iStSsz/H4SQJFD00ALXRZPMV2FxISDJ2S2qMpiVggFhB2BJsjaEB0ES3FO4k7dAqQHmm/F0rISMBRWxJjFQPF8IC9DsYoV42EOAlGtdyWyD4y76WWDtXsJol3gAAAABJRU5ErkJggg==";
  653. $("<span>", {
  654. class : "closeFTDivbt",
  655. click : closeFaceTxttable,
  656. html : "<img src='" + closeFTDivbt + "' alt='X' />"
  657. }).appendTo("#tdRightDiv0");
  658.  
  659. //载入各种颜文字到列表中
  660. loadThe("all");
  661. }
  662. }
  663. //关闭输入窗列表
  664. function closeFaceTxttable() {
  665. $(".insertFacetxt").detach();
  666. $(".FTRightDiv").detach();
  667. $(".FTLeftDiv").detach();
  668. $("#faceTextDiv").detach();
  669. }
  670.  
  671. //主编辑器添加按钮
  672. addNodeInsertedListener('.edui-btn-toolbar', function () {
  673. if (!document.getElementById("editorButton")) {
  674. $("<div>", {
  675. id : "editorButton",
  676. html : "('ェ ' )",
  677. click : createFaceTexttable
  678. }).appendTo(this);
  679. }
  680. })
  681.  
  682.  
  683. //楼中楼加按钮
  684. if (window.location.href.indexOf("/p/") != -1 || window.location.href.indexOf("ct=") != -1 || window.location.href.indexOf("kz=") != -1) {
  685. addNodeInsertedListener('.lzl_panel_wrapper>tbody>tr>td:first-child', function () {
  686. if (!getId("editorButton_lzl")) {
  687. $("<eas>", {
  688. id : "editorButton_lzl",
  689. html : "('ェ ' )",
  690. click : createFaceTexttable
  691. }).appendTo(this);
  692. }
  693. });
  694. }