Greasy Fork 支持简体中文。

tieba_At_Ta

百度贴吧@它

目前為 2014-07-30 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name tieba_At_Ta
  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://libs.baidu.com/jquery/2.0.0/jquery.min.js
  17. // @author congxz6688
  18. // @version 2014.7.30.0
  19. // @grant GM_getValue
  20. // @grant GM_setValue
  21. // @grant GM_deleteValue
  22. // @namespace https://greasyfork.org/scripts/153
  23. // ==/UserScript==
  24.  
  25.  
  26. function addStyle(css){
  27. document.head.appendChild(document.createElement("style")).textContent = css;
  28. }
  29.  
  30. //下面这一段CSS,可帮助编辑器工具栏不够用的同学,没有这个需要的同学可删除它。
  31. var forCss2er = ".cut_screen{display:none!important;}";
  32. forCss2er += ".tb-editor-wrapper{width:720px !important}";
  33. forCss2er += ".recentImgDiv>.tb-editor-overlay{left:28% !important; top:30px !important;} .arrow.down{left: 218px !important;}";
  34. addStyle(forCss2er);
  35.  
  36. //脚本主css
  37. var replyCss = "";
  38. replyCss += ".tb_icon_author, .tb_icon_author_rely{background:none !important;background-position:none !important; white-space:nowrap !important;}";
  39. replyCss += ".insertAt{padding:0px 0px 0px 0px; margin:1px 1px; cursor:pointer; background-color:lightGrey; display:inline-block;}";
  40. replyCss += "#attaDiv{background-color:lightGrey; width:450px; border:4px double gray;} #ATTAnewEditDiv *:not(.pageTitle){font-size:12px !important;}";
  41. replyCss += ".leftDiv{display:inline-block; background-color:lightGrey;padding:5px 6px; width:48px;}";
  42. replyCss += ".rightDiv{display:inline-block; background-color:lightGrey; padding:4px 6px; width:375px;}";
  43. replyCss += ".addPlus{cursor:pointer; margin:0px 2px 0px 0px; width:20px; color:blue;}";
  44. replyCss += ".addPlusBack{cursor:pointer; margin:0px 2px 0px 0px; width:20px; color:red;}";
  45. replyCss += ".picFrd{cursor:pointer; margin:0px 2px 0px -1px; width:20px; color:#A0522D; font-size:13px} .bbaa{cursor:pointer; margin:0px 2px 0px -1px; width:20px; color:green; font-size:13px} .bbaaB{cursor:pointer; margin:0px 2px 0px -1px; width:20px; color:#1E90FF; font-size:13px}";
  46. replyCss += ".picFrdTab{cursor:pointer; margin:0px 2px 0px 2px; width:20px; color:#A0522D;} .bbaaTab{cursor:pointer; margin:0px 2px 0px 2px; width:20px; color:green;} .bbaaTabB{cursor:pointer; margin:0px 2px 0px 2px; width:20px; color:#1E90FF;}";
  47. replyCss += ".addPlusTab{cursor:pointer; margin:0px 2px 0px 2px; width:20px; color:blue;}";
  48. replyCss += ".addPlusTabBack{cursor:pointer; margin:0px 2px 0px 2px; width:20px; color:red;}";
  49. replyCss += ".closeDivbt{cursor:pointer; float:right; margin:0px -2px; width:16px; height:16px;}";
  50. replyCss += "#atta{cursor:pointer; margin:0 0 0 12px; display:inline-block; color:#3163B6; padding: 1px 1px 10px 1px; position:relative; top:0px}";
  51. replyCss += "#atta_lzl{margin:0 5px 3px 5px; float:right;cursor:pointer; font-size:1.2em; display:inline-block; color:#3163B6;}";
  52. replyCss += ".thread_alt>td:nth-child(4){width:110px} .thread_alt>td:nth-child(5){width:160px}";
  53. replyCss += ".ATeditFaceTxtTb{width:150px; padding:1px 1px 0 0;} .inputInTd{width:149px;} .FTbutton{margin:10px 10px 0px 0px}";
  54. replyCss += "#ATTAnewEditDiv{border: 1px solid gray; z-index:10002; background-color:#EEEEEE; padding:20px; position:fixed; left:300px; bottom:80px;}";
  55. replyCss += ".pageTitle{font-size : 16px; margin-bottom : 15px;}";
  56. replyCss += ".no_icon_author{padding-left:21px !important;}";
  57. addStyle(replyCss);
  58.  
  59. unsafeWindow.PageData.user.is_login =1;
  60. var Tds = []; //数据修改用列表
  61. var thisPageTitle = document.getElementById("wd1").value + "吧";
  62.  
  63. //脚本双存储数据相互恢复
  64. if (!localStorage.myBaFriends && GM_getValue("myBaFriends", "") != "") {
  65. localStorage.myBaFriends = GM_getValue("myBaFriends");
  66. }
  67. if (GM_getValue("myBaFriends", "") == "" && localStorage.myBaFriends) {
  68. GM_setValue("myBaFriends", localStorage.myBaFriends);
  69. }
  70. if (!localStorage.publicFriends && GM_getValue("publicFriends", "") != "") {
  71. localStorage.publicFriends = GM_getValue("publicFriends");
  72. }
  73. if (GM_getValue("publicFriends", "") == "" && localStorage.publicFriends) {
  74. GM_setValue("publicFriends", localStorage.publicFriends);
  75. }
  76.  
  77. //函数 数组字符串重排序
  78. String.prototype.reIndexStr = function () {
  79. var lastSt = this.split(",");
  80. var lastStr = lastSt.sort(function (a, b) {
  81. return a.localeCompare(b)
  82. });
  83. return lastStr;
  84. }
  85.  
  86. //长ID缩略显示
  87. String.prototype.reComLength = function () {
  88. var yn = 0;
  89. var kuu = "";
  90. for (w in this) {
  91. if (w < this.length) {
  92. if (/[a-zA-Z0-9]/.exec(this[w])) {
  93. yn += 1;
  94. } else {
  95. yn += 2;
  96. }
  97. if (yn < 13) {
  98. kuu += this[w];
  99. }
  100. }
  101. }
  102. var uui = yn > 14 ? kuu + "..." : this;
  103. return uui;
  104. }
  105. //元素精确监听
  106. function addNodeInsertedListener(elCssPath, handler, executeOnce, noStyle) {
  107. var animName = "anilanim",
  108. prefixList = ["-o-", "-ms-", "-khtml-", "-moz-", "-webkit-", ""],
  109. eventTypeList = ["animationstart", "webkitAnimationStart", "MSAnimationStart", "oAnimationStart"],
  110. forEach = function (array, func) {
  111. for (var i = 0, l = array.length; i < l; i++) {
  112. func(array[i]);
  113. }
  114. };
  115. if (!noStyle) {
  116. var css = elCssPath + "{",
  117. css2 = "";
  118. forEach(prefixList, function (prefix) {
  119. css += prefix + "animation-duration:.001s;" + prefix + "animation-name:" + animName + ";";
  120. css2 += "@" + prefix + "keyframes " + animName + "{from{opacity:.9;}to{opacity:1;}}";
  121. });
  122. css += "}" + css2;
  123. addStyle(css);
  124. }
  125. if (handler) {
  126. var bindedFunc = function (e) {
  127. var els = document.querySelectorAll(elCssPath),
  128. tar = e.target,
  129. match = false;
  130. if (els.length !== 0) {
  131. forEach(els, function (el) {
  132. if (tar === el) {
  133. if (executeOnce) {
  134. removeNodeInsertedListener(bindedFunc);
  135. }
  136. handler.call(tar, e);
  137. return;
  138. }
  139. });
  140. }
  141. };
  142. forEach(eventTypeList, function (eventType) {
  143. document.addEventListener(eventType, bindedFunc, false);
  144. });
  145. return bindedFunc;
  146. }
  147. }
  148. //移除精确监听
  149. function removeNodeInsertedListener(bindedFunc) {
  150. var eventTypeList = ["animationstart", "webkitAnimationStart", "MSAnimationStart", "oAnimationStart"],
  151. forEach = function (array, func) {
  152. for (var i = 0, l = array.length; i < l; i++) {
  153. func(array[i]);
  154. }
  155. };
  156. forEach(eventTypeList, function (eventType) {
  157. document.removeEventListener(eventType, bindedFunc, false);
  158. });
  159. }
  160. //获取本吧各数组
  161. function thisBaArray(ww) {
  162. if (ww == "publicFriends") {
  163. var bbarray = (localStorage.publicFriends) ? localStorage.publicFriends.split(",") : [];
  164. } else {
  165. var getBazhu = JSON.parse((localStorage[ww]) ? localStorage[ww] : "{}");
  166. var bbarray = getBazhu[thisPageTitle] ? getBazhu[thisPageTitle] : [];
  167. }
  168. return bbarray
  169. }
  170. //函数 载入各名单
  171. function loadThe(ww) {
  172. switch (ww) {
  173. case "myBaFriends":
  174. $("#td22div").empty();
  175. var parentDiv = document.getElementById("td22div");
  176. break;
  177. case "bigBaToday":
  178. var parentDiv = document.getElementById("td12div");
  179. break;
  180. case "smallBaToday":
  181. var parentDiv = document.getElementById("td42div");
  182. break;
  183. case "publicFriends":
  184. $("#td32div").empty();
  185. var parentDiv = document.getElementById("td32div");
  186. break;
  187. }
  188. if (thisBaArray(ww).length != 0) {
  189. myFri = thisBaArray(ww).toString().reIndexStr();
  190. for (l = 0; l < myFri.length; l++) {
  191. var ddoi = document.createElement("span");
  192. ddoi.innerHTML = "&nbsp;@" + myFri[l] + "&nbsp;";
  193. ddoi.className = "insertAt";
  194. ddoi.addEventListener("click", insertEdiror, false);
  195. parentDiv.appendChild(ddoi);
  196. }
  197. }
  198. }
  199.  
  200. //函数 插入到编辑器
  201. function insertEdiror(e) {
  202. var InsertText = e.target.innerHTML;
  203. var editor = (localStorage['which_editor']) ? localStorage['which_editor'] : 'atta';
  204. (editor == "atta") ? unsafeWindow.test_editor.execCommand("inserthtml", InsertText) : unsafeWindow.LzlEditor._s_p._se.execCommand("inserthtml", InsertText);
  205. closeAttable();
  206. }
  207. //函数 这是隐藏的福利,我会说吗?
  208. function insertAll(e) {
  209. var idd = e.target.id;
  210. which_ed = (localStorage['which_editor']) ? localStorage['which_editor'] : 'atta';
  211. var bazhuST = "";
  212. switch (idd) {
  213. case "td42div":
  214. var lmo = thisBaArray("smallBaToday");
  215. break;
  216. case "td12div":
  217. var lmo = thisBaArray("bigBaToday");
  218. break;
  219. case "td22div":
  220. var lmo = thisBaArray("myBaFriends");
  221. break;
  222. case "td32div":
  223. var lmo = thisBaArray("publicFriends");
  224. break;
  225. }
  226. if (lmo.length != 0) {
  227. for (p = 0; p < lmo.length; p++) {
  228. bazhuST += "@" + lmo[p] + "&nbsp;";
  229. }
  230. }
  231. (which_ed == "atta") ? unsafeWindow.test_editor.execCommand("inserthtml", bazhuST) : unsafeWindow.LzlEditor._s_p._se.execCommand("inserthtml", bazhuST);
  232. closeAttable();
  233. }
  234. //列表创建函数
  235. function creaseTable(UrlLength) {
  236. var tablepp = document.createElement("table");
  237. tablepp.id = "ATTAtablepp";
  238. var trs = [];
  239. for (ly = 0; ly <= Math.ceil(UrlLength / 3); ly++) {
  240. var tr = document.createElement("tr");
  241. mmd = trs.push(tr);
  242. tablepp.appendChild(tr);
  243. }
  244. for (ls = 0; ls < trs.length * 3; ls++) {
  245. var td = document.createElement("td");
  246. td.className = "ATeditFaceTxtTb";
  247. td.innerHTML = "<input type='text' class='inputInTd' value=''>";
  248. wq = Tds.push(td);
  249. trs[Math.floor(ls / 3)].appendChild(td);
  250. }
  251. return tablepp
  252. }
  253. //函数 编辑我的本吧吧友名单
  254. function promptMyfriend(el) {
  255. if (!document.getElementById("ATTAnewEditDiv")) {
  256. kpp = el.target.getAttribute("eclass");
  257. if (kpp == "promptMyfriend") {
  258. var ujuy = JSON.parse((localStorage["myBaFriends"]) ? localStorage["myBaFriends"] : "{}");
  259. var myfris = ujuy[thisPageTitle] ? ujuy[thisPageTitle] : [];
  260. } else {
  261. var myfris = ((localStorage["publicFriends"]) ? localStorage["publicFriends"] : "").split(",");
  262. }
  263. var ATTAnewEditDiv = document.createElement("div");
  264. ATTAnewEditDiv.id = "ATTAnewEditDiv";
  265.  
  266. var pageTitle = document.createElement("div");
  267. pageTitle.className = "pageTitle";
  268. pageTitle.innerHTML = "可直接修改或添加:";
  269. ATTAnewEditDiv.appendChild(pageTitle);
  270.  
  271. newTable = creaseTable(myfris.length);
  272. ATTAnewEditDiv.appendChild(newTable);
  273.  
  274. var yesButton = document.createElement("input");
  275. yesButton.type = "button";
  276. yesButton.className = "FTbutton";
  277. yesButton.value = "确定";
  278. yesButton.addEventListener("click", function () {
  279. var reGetArray = [];
  280. var hht = document.getElementsByClassName("inputInTd");
  281. for (hh = 0; hh < hht.length; hh++) {
  282. if (hht[hh].value != "") {
  283. ko = reGetArray.push(hht[hh].value.trim());
  284. }
  285. }
  286. if (reGetArray.length > 0) {
  287. if (kpp == "promptMyfriend") {
  288. ujuy[thisPageTitle] = reGetArray;
  289. } else {
  290. localStorage["publicFriends"] = reGetArray.toString();
  291. GM_setValue("publicFriends", reGetArray.toString());
  292. }
  293. } else {
  294. if (kpp == "promptMyfriend") {
  295. delete ujuy[thisPageTitle];
  296. } else {
  297. localStorage.removeItem("publicFriends");
  298. GM_deleteValue("publicFriends");
  299. }
  300. }
  301. if (kpp == "promptMyfriend") {
  302. localStorage["myBaFriends"] = JSON.stringify(ujuy);
  303. GM_setValue("myBaFriends", JSON.stringify(ujuy));
  304. loadThe("myBaFriends");
  305. } else {
  306. loadThe("publicFriends");
  307. }
  308. $(".inputInTd").html("");
  309. $("#ATTAtablepp").remove();
  310. $("#ATTAnewEditDiv").remove();
  311. }, false);
  312. ATTAnewEditDiv.appendChild(yesButton);
  313.  
  314. var addButton = document.createElement("input");
  315. addButton.type = "button";
  316. addButton.className = "FTbutton";
  317. addButton.value = "加行";
  318. addButton.addEventListener("click", function () {
  319. var tdNum = document.getElementsByClassName("inputInTd").length;
  320. var newTr = document.createElement("tr");
  321. document.getElementById("ATTAtablepp").appendChild(newTr);
  322. for (es = 0; es < 3; es++) {
  323. var newTD = document.createElement("td");
  324. newTD.className = "ATeditFaceTxtTb";
  325. newTD.innerHTML = "<input type='text' class='inputInTd' value=''>";
  326. newTr.appendChild(newTD);
  327. }
  328. }, false);
  329. ATTAnewEditDiv.appendChild(addButton);
  330. document.body.appendChild(ATTAnewEditDiv);
  331.  
  332. for (ss = 0; ss < myfris.length; ss++) {
  333. document.getElementsByClassName("inputInTd")[ss].value = myfris[ss];
  334. }
  335. }
  336. }
  337. //函数 绝对定位
  338. function getElementLeft(element) {
  339. var actualLeft = element.offsetLeft;
  340. var current = element.offsetParent;
  341. while (current !== null) {
  342. actualLeft += current.offsetLeft;
  343. current = current.offsetParent;
  344. }
  345. return actualLeft;
  346. }
  347. //函数 绝对定位
  348. function getElementTop(element) {
  349. var actualTop = element.offsetTop;
  350. var current = element.offsetParent;
  351. while (current !== null) {
  352. actualTop += current.offsetTop;
  353. current = current.offsetParent;
  354. }
  355. return actualTop;
  356. }
  357. //主函数 由编辑窗上方的@@@调用,展开主列表
  358. function createAttable(ete) {
  359. if (!document.getElementById("attaDiv")) {
  360. var ortt = ete.target;
  361. localStorage.which_editor = (ortt.id == "atta") ? 'atta' : 'atta_lzl';
  362. var getTop = (ortt.id == "atta") ? getElementTop(ortt) + 32 : getElementTop(ortt) + 20;
  363. //定位主列表位置
  364. if ($('#tb_rich_poster').css('position')=='fixed' && ortt.id == "atta") { //原子的悬浮窗
  365. var attaDiv = $("<div>", {
  366. id : "attaDiv"
  367. }).css({
  368. "position" : "fixed",
  369. "z-index" : "10002",
  370. "left" : getElementLeft(ortt) - 200,
  371. "bottom" : "0"
  372. }).appendTo(document.body);
  373. } else if (ortt.id == "atta_lzl") { //楼中楼回复
  374. var attaDiv = $("<div>", {
  375. id : "attaDiv"
  376. }).css({
  377. "position" : "absolute",
  378. "z-index" : "9999",
  379. "left" : getElementLeft(ortt) - 200,
  380. "top" : getTop - 120
  381. }).appendTo(document.body);
  382. } else { //主窗
  383. var attaDiv = $("<div>", {
  384. id : "attaDiv"
  385. }).css({
  386. "position" : "absolute",
  387. "z-index" : "9999",
  388. "left" : getElementLeft(ortt) - 200,
  389. "top" : getTop
  390. }).appendTo(document.body);
  391. }
  392. //建表
  393. var atTable = $("<table>", {
  394. "border" : "1",
  395. "bordercolor" : "#B8B3FF",
  396. "cellpadding" : "6"
  397. }).appendTo(attaDiv);
  398. //TR
  399. var attr1 = $("<tr>").appendTo(atTable);
  400. var attr4 = $("<tr>").appendTo(atTable);
  401. var attr2 = $("<tr>").appendTo(atTable);
  402. var attr3 = $("<tr>").appendTo(atTable);
  403.  
  404. //左TD
  405. var td11 = $("<td>").appendTo(attr1);
  406. $("<div>", {
  407. html : "伟大吧主",
  408. class : "leftDiv"
  409. }).appendTo(td11);
  410. var td41 = $("<td>").appendTo(attr4);
  411. $("<div>", {
  412. html : "各位小吧",
  413. class : "leftDiv"
  414. }).appendTo(td41);
  415. var td21 = $("<td>", {
  416. "eclass" : "promptMyfriend",
  417. click : promptMyfriend
  418. }).appendTo(attr2);
  419. $("<div>", {
  420. "eclass" : "promptMyfriend",
  421. html : "本吧吧友",
  422. class : "leftDiv",
  423. title : "点击这里,可编辑本吧吧友名单"
  424. }).appendTo(td21);
  425. var td31 = $("<td>", {
  426. "eclass" : "promptPubfriend",
  427. click : promptMyfriend
  428. }).appendTo(attr3);
  429. $("<div>", {
  430. "eclass" : "promptPubfriend",
  431. html : "通用吧友",
  432. class : "leftDiv",
  433. title : "点击这里,可编辑通用吧友名单"
  434. }).appendTo(td31);
  435.  
  436. //右TD
  437. var td12 = $("<td>").appendTo(attr1);
  438. $("<div>", {
  439. id : "td12div",
  440. class : "rightDiv",
  441. dblclick : insertAll
  442. }).appendTo(td12);
  443. var td42 = $("<td>").appendTo(attr4);
  444. $("<div>", {
  445. id : "td42div",
  446. class : "rightDiv",
  447. dblclick : insertAll
  448. }).appendTo(td42);
  449. var td22 = $("<td>").appendTo(attr2);
  450. $("<div>", {
  451. id : "td22div",
  452. class : "rightDiv",
  453. dblclick : insertAll
  454. }).appendTo(td22);
  455. var td32 = $("<td>").appendTo(attr3);
  456. $("<div>", {
  457. id : "td32div",
  458. class : "rightDiv",
  459. dblclick : insertAll
  460. }).appendTo(td32);
  461.  
  462. //关闭按钮
  463. var closeDivbt = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAACXBIWXMAAA7EAAAOxAGVKw4bAAAA8UlEQVR42pWSMQrCQBBFcwPvI3gNKwtvYGVhaStqJYiFjY0IFmIrWEXRFIISiIqohYUYFcTC1gc/BFkSEmGyzMz/f3ZmNlaxMSvU7JQG2eJzdvdEW3j++vgstZ1AsNz6OgHkG6EpCFPe5S2qjHBzfgGZAuLV4TGw952Rg6MMVEKSZEyB7V6BW8NlJlcu1ccUPt0+1e6UkBMIgtkSKUi9iStSsz/H4SQJFD00ALXRZPMV2FxISDJ2S2qMpiVggFhB2BJsjaEB0ES3FO4k7dAqQHmm/F0rISMBRWxJjFQPF8IC9DsYoV42EOAlGtdyWyD4y76WWDtXsJol3gAAAABJRU5ErkJggg==";
  464. $("<span>", {
  465. class : "closeDivbt",
  466. click : closeAttable,
  467. html : "<img src='" + closeDivbt + "' alt='X' />"
  468. }).appendTo("#td12div");
  469.  
  470. //载入吧主到列表中
  471. loadThe("bigBaToday");
  472. //载入小吧到列表中
  473. loadThe("smallBaToday");
  474. //载入我的吧友
  475. loadThe("myBaFriends");
  476. //载入通用吧友
  477. loadThe("publicFriends");
  478. }
  479. }
  480. //关闭@@@列表
  481. function closeAttable() {
  482. $(".insertAt").detach();
  483. $(".rightDiv").detach();
  484. $(".leftDiv").detach();
  485. $("#attaDiv").detach();
  486. }
  487.  
  488. //函数 加入到我的吧友
  489. function addTomyFriend(elk) {
  490. var iopo = elk.target;
  491. var Ta = iopo.getAttribute("value");
  492. var r = confirm("把 " + Ta + " 添加到我的吧友?");
  493. if (r == true) {
  494. var ujuyu = JSON.parse((localStorage["myBaFriends"]) ? localStorage["myBaFriends"] : "{}");
  495. if (thisBaArray("bigBaToday").indexOf(Ta) == -1 && thisBaArray("smallBaToday").indexOf(Ta) == -1 && thisBaArray("publicFriends").indexOf(Ta) == -1) {
  496. if (ujuyu[thisPageTitle]) {
  497. if (ujuyu[thisPageTitle].indexOf(Ta) == -1) {
  498. ioii = ujuyu[thisPageTitle].push(Ta);
  499. }
  500. } else {
  501. ujuyu[thisPageTitle] = Ta.split(",");
  502. }
  503. localStorage["myBaFriends"] = JSON.stringify(ujuyu);
  504. setTimeout(function () {
  505. GM_setValue("myBaFriends", JSON.stringify(ujuyu));
  506. }, 0);
  507. } else {
  508. window.location = window.location.href;
  509. }
  510. temppp = "." + iopo.getAttribute("class") + "[value='" + Ta + "']";
  511. temppq = "." + iopo.getAttribute("class") + "[value='@" + Ta + "']";
  512. $(temppp + "," + temppq).each(function () {
  513. $(this).replaceWith($("<spam>", {
  514. title : "从我的@吧友中删除",
  515. value : Ta,
  516. html : "㈠",
  517. class : iopo.getAttribute("class") + "Back",
  518. click : removeFriend
  519. }));
  520. });
  521. }
  522. }
  523. //函数 从我的吧友中删除
  524. function removeFriend(bad) {
  525. var iopo = bad.target;
  526. var Ta = iopo.getAttribute("value");
  527. var r = confirm("把 " + Ta + " 从我的吧友中删除?");
  528. if (r == true) {
  529. var ujuyu = JSON.parse((localStorage["myBaFriends"]) ? localStorage["myBaFriends"] : "{}");
  530. var BaList = ujuyu[thisPageTitle] ? ujuyu[thisPageTitle].toString() : ""; //此判断仅用于A页已执行过删除,B页中尚未知觉的情况
  531. if (BaList != "") {
  532. if (BaList == Ta) {
  533. delete ujuyu[thisPageTitle];
  534. } else {
  535. BaList = BaList.replace(Ta + ',', '').replace(',' + Ta, '');
  536. ujuyu[thisPageTitle] = BaList.split(",");
  537. }
  538. }
  539. localStorage["myBaFriends"] = JSON.stringify(ujuyu);
  540. setTimeout(function () {
  541. GM_setValue("myBaFriends", JSON.stringify(ujuyu));
  542. }, 0);
  543. temppp = "." + iopo.getAttribute("class") + "[value='" + Ta + "']";
  544. temppq = "." + iopo.getAttribute("class") + "[value='@" + Ta + "']";
  545. $(temppp + "," + temppq).each(function () {
  546. $(this).replaceWith($("<spam>", {
  547. title : "添加到我的@吧友",
  548. value : Ta,
  549. html : "㈩",
  550. class : iopo.getAttribute("class").replace("Back", ""),
  551. click : addTomyFriend
  552. }));
  553. });
  554. }
  555. }
  556. //直接@它
  557. function justAtta(T) {
  558. var iopo = T.target;
  559. var Ta = iopo.innerHTML.replace("@", "");
  560. temp = '&nbsp;<span class="at">@' + Ta + '</span>&nbsp;';
  561. if (document.getElementById("Mark1") || document.getElementById("cMark")) { //兼容小脸
  562. smallFaceEnble();
  563. }
  564. if ($("#btUnminify").css("display") == "block") {//兼容原子的悬浮窗
  565. unsafeWindow.unminifyShare();
  566. }
  567. unsafeWindow.test_editor.execCommand("inserthtml", temp);
  568. }
  569. //大吧小吧来召唤
  570. function bbsbCall(ba) {
  571. var iopo = ba.target;
  572. var Ta = iopo.getAttribute("value");
  573. temp = '&nbsp;<span class="at">@' + Ta + '</span>&nbsp;';
  574. if (document.getElementById("Mark1") || document.getElementById("cMark")) { //兼容小脸
  575. smallFaceEnble();
  576. }
  577. if ($("#btUnminify").css("display") == "block") {//兼容原子的悬浮窗
  578. unsafeWindow.unminifyShare();
  579. }
  580. unsafeWindow.test_editor.execCommand("inserthtml", temp);
  581. }
  582.  
  583. //兼容小脸
  584. function smallFaceEnble() {
  585. $('#cLinkContent1').css({
  586. "display" : 'table-cell'
  587. }); //兼容旧版小脸,打开编辑窗
  588. $('#cLinkContent').css({
  589. "display" : 'table-cell'
  590. }); //兼容新版小脸,打开编辑窗
  591. $('#menuSwitch').html('>>'); //兼容小脸,打开编辑窗
  592. }
  593.  
  594.  
  595. /***************************华丽的分割线,以上为函数,以下为运行程序********************************/
  596.  
  597. //帖子内启动其功能函数
  598. if (window.location.href.indexOf("/p/") != -1 || window.location.href.indexOf("ct=") != -1 || window.location.href.indexOf("kz=") != -1) {
  599. //各ID加+
  600. addNodeInsertedListener('.p_author_name,a.at', function () {
  601. var Lhtml = this.innerHTML.replace("@", "");
  602. if (thisBaArray("bigBaToday").indexOf(Lhtml) != -1) {
  603. var ttitle = "这是大吧,可围观不可酱油,轻易别@它";
  604. var hhtml = "⑨";
  605. var cclass = "bbaaTabB";
  606. var cclick = bbsbCall;
  607. } else if (thisBaArray("smallBaToday").indexOf(Lhtml) != -1) {
  608. var ttitle = "这是小吧,想@就@吧~~";
  609. var hhtml = "②";
  610. var cclass = "bbaaTab";
  611. var cclick = bbsbCall;
  612. } else if (thisBaArray("publicFriends").indexOf(Lhtml) != -1) {
  613. var ttitle = "这是通用吧友,就是用来@的~~";
  614. var hhtml = "@";
  615. var cclass = "picFrdTab";
  616. var cclick = bbsbCall;
  617. } else if (thisBaArray("myBaFriends").indexOf(Lhtml) != -1) {
  618. var ttitle = "从我的@吧友中删除";
  619. var hhtml = "㈠";
  620. var cclass = "addPlusTabBack";
  621. var cclick = removeFriend;
  622. } else {
  623. var ttitle = "添加到我的@吧友";
  624. var hhtml = "㈩";
  625. var cclass = "addPlusTab";
  626. var cclick = addTomyFriend;
  627. }
  628. if ($(this).siblings("spam[value='" + Lhtml + "']").length == 0) {
  629. $("<spam>", {
  630. title : ttitle,
  631. html : hhtml,
  632. value : Lhtml,
  633. class : cclass,
  634. click : cclick
  635. }).insertAfter(this);
  636. }
  637. //帖子内点击直接@它 删除下面4行即可去掉这一功能,要想彻底删干净,就把函数justAtta也删掉
  638. this.title += " 点击直接@它";
  639. this.href = "javascript:void(0);";
  640. this.removeAttribute("target");
  641. this.removeAttribute("onmouseover");
  642. this.removeAttribute("onmouseout");
  643. this.addEventListener("click", justAtta, false);
  644. });
  645. //楼中楼加@@@
  646. addNodeInsertedListener('.lzl_panel_wrapper>tbody>tr>td:first-child', function () {
  647. if (!document.getElementById("atta_lzl")) {
  648. $("<eas>", {
  649. id : "atta_lzl",
  650. html : "@@@",
  651. click : createAttable
  652. }).appendTo(this);
  653. }
  654. });
  655. }
  656.  
  657. //主编辑器添加@@@
  658. addNodeInsertedListener('.edui-btn-toolbar', function () {
  659. if (!document.getElementById("atta")) {
  660. $("<div>", {
  661. id : "atta",
  662. html : "@@@",
  663. click : createAttable
  664. }).appendTo(this);
  665. }
  666. })
  667.  
  668.  
  669. //主题列表
  670. if (window.location.href.indexOf("kw=") != -1) {
  671. //最后一页
  672. addNodeInsertedListener('#thread_list_table tr>td:nth-child(2),.threadlist_rep_num', function () {
  673. if (this.nodeName == "DIV") { //新版
  674. var getThisUrl = $(this.parentNode.parentNode).find("a").attr("href");
  675. } else { //旧版
  676. var getThisUrl = $(this.parentNode).find("a").attr("href");
  677. }
  678. var klii = this.innerHTML;
  679. if (klii > 30) {
  680. this.innerHTML = "";
  681. $("<a>", {
  682. href : "javascript:void(0);",
  683. title : "直达最后一页",
  684. html : klii
  685. }).click(function () {
  686. var jih = getThisUrl.split("/p/")[1];
  687. var rtt = "http://tieba.baidu.com/mo/m?kz=" + jih;
  688. var getStartPage=new XMLHttpRequest();
  689. getStartPage.open("GET", rtt, true);
  690. getStartPage.send(null);
  691. getStartPage.onreadystatechange = function () {
  692. if (getStartPage.readyState == 4) {
  693. if (getStartPage.status == 200) {
  694. var pn = $(getStartPage.responseText).find('[name="pnum"]').attr('value');
  695. if (pn == undefined) {
  696. var lastRes = getStartPage.responseText.match(/<a[ ]href[^>]+?pid=\d+/g);
  697. var lastRe = lastRes[lastRes.length - 1].replace(/<a[ ]href[^>]+?pid=/, "");
  698. window.location = 'http://tieba.baidu.com/f?ct=335675392&tn=baiduPostBrowser&sc=' + lastRe + "&z=" + jih + "#" + lastRe;
  699. } else {
  700. var lastUrl = "http://tieba.baidu.com" + getStartPage.responseText.match(/<\/a>&#160;<a[ ]href=".*last=1.*?(?=">)/)[0].replace('</a>&#160;<a href="', "").replace(/&amp;/g, "&");
  701. var directGo = new XMLHttpRequest();
  702. directGo.open("GET", lastUrl, true);
  703. directGo.send(null);
  704. directGo.onreadystatechange = function () {
  705. if (directGo.readyState == 4) {
  706. if (directGo.status == 200) {
  707. var lastRe = directGo.responseText.match(/flr\?pid=\d+(?=&)/)[0].replace('flr?pid=', '');
  708. window.location = 'http://tieba.baidu.com/f?ct=335675392&tn=baiduPostBrowser&sc=' + lastRe + "&z=" + jih + "#" + lastRe;
  709. }
  710. }
  711. }
  712. }
  713. }
  714. }
  715. }
  716. }).appendTo(this);
  717. }
  718. });
  719.  
  720. //今天的日期和本吧名
  721. var yuy = new Date();
  722. var fulltime = yuy.toLocaleDateString();
  723.  
  724. //收集每日各贴吧吧主信息
  725. var bigBaToday = JSON.parse((localStorage["bigBaToday"]) ? localStorage["bigBaToday"] : "{}");
  726. var getSmallbas = JSON.parse((localStorage["smallBaToday"]) ? localStorage["smallBaToday"] : "{}");
  727. if ($(".manager_btn").length > 0 && (bigBaToday.date != fulltime || !bigBaToday[thisPageTitle])) {
  728. console.log(thisPageTitle + " " + fulltime + " " + "吧主信息收集,每天只一次。");
  729. var smallbaUrl = window.location.href.replace("f?", "f/bawu/admin_group?");
  730. var xmlHttp=new XMLHttpRequest();
  731. xmlHttp.open("GET", smallbaUrl, true);
  732. xmlHttp.send(null);
  733. xmlHttp.onreadystatechange = function () {
  734. if (xmlHttp.readyState == 4) {
  735. if (xmlHttp.status == 200) {
  736. var retxt1 = xmlHttp.responseText.replace(/\r/gi, "").replace(/\n/gi, "");
  737. //以下是大吧获取
  738. var bigbass = retxt1.replace(/.*本吧吧主:<\/td[ ]><td[ ]style="padding-bottom:20px;"[ ]>&nbsp;/, "").replace(/&nbsp;<\/td[ ]><\/tr[ ]><tr[ ]valign="top"[ ]><td[ ]width="70"[ ]align="right"[ ]>小吧主:.*/, "");
  739. var bigtxt = bigbass.match(/<a[ ].*?"[ ]>.*?</g);
  740. if (bigtxt.length > 0) {
  741. bigbarrs = "";
  742. for (w = 0; w < bigtxt.length; w++) {
  743. bigbarrs += ((bigbarrs == "") ? "" : ",") + bigtxt[w].match(/>(.*)</)[1];
  744. }
  745. if (bigBaToday.date != fulltime) {
  746. bigBaToday = {};
  747. bigBaToday.date = fulltime;
  748. bigBaToday[thisPageTitle] = bigbarrs.split(",");
  749. } else {
  750. bigBaToday[thisPageTitle] = bigbarrs.split(",");
  751. }
  752. localStorage['bigBaToday'] = JSON.stringify(bigBaToday);
  753. }
  754. //以下是小吧获取
  755. var retxt2 = retxt1.replace(/.*小吧主:<\/td[ ]><td[ ]style="padding-bottom:20px;"[ ]>&nbsp;/, "").replace(/&nbsp;<\/td[ ]><\/tr[ ]><tr[ ]valign="top"[ ]><td[ ]width="70"[ ]align="right"[ ]>图片小编:.*/, "");
  756. var retxt = retxt2.match(/" >.*?</g);
  757. if (retxt.length > 0) {
  758. smallbar = "";
  759. for (w = 0; w < retxt.length; w++) {
  760. smallbar += ((smallbar == "") ? "" : ",") + retxt[w].replace(/[" ><]/g, "");
  761. }
  762. if (getSmallbas.date != fulltime) {
  763. getSmallbas = {};
  764. getSmallbas.date = fulltime;
  765. getSmallbas[thisPageTitle] = smallbar.split(",");
  766. } else {
  767. getSmallbas[thisPageTitle] = smallbar.split(",");
  768. }
  769. localStorage['smallBaToday'] = JSON.stringify(getSmallbas);
  770. }
  771. }
  772. }
  773. }
  774. }
  775.  
  776. //各ID加+
  777. addNodeInsertedListener('.tb_icon_author>a,.tb_icon_author_rely>a', function () {
  778. if (this.parentNode.title) {
  779. Lhtml = this.parentNode.title.match(/.*[::]\s?(.*)/)[1];
  780. } else if (this.parentNode.parentNode.title) {
  781. Lhtml = this.parentNode.parentNode.title.match(/.*[::]\s?(.*)/)[1];
  782. }
  783. this.innerHTML = Lhtml.reComLength();
  784. if (thisBaArray("bigBaToday").indexOf(Lhtml) != -1) {
  785. var ttitle = "这是大吧,可围观不可酱油,轻易别@它";
  786. var hhtml = "⑨";
  787. var cclass = "bbaaB";
  788. var cclick = bbsbCall;
  789. } else if (thisBaArray("smallBaToday").indexOf(Lhtml) != -1) {
  790. var ttitle = "这是小吧,想@就@吧~~";
  791. var hhtml = "②";
  792. var cclass = "bbaa";
  793. var cclick = bbsbCall;
  794. } else if (thisBaArray("publicFriends").indexOf(Lhtml) != -1) {
  795. var ttitle = "这是通用吧友,就是用来@的~~";
  796. var hhtml = "@";
  797. var cclass = "picFrd";
  798. var cclick = bbsbCall;
  799. } else if (thisBaArray("myBaFriends").indexOf(Lhtml) != -1) {
  800. var ttitle = "从我的@吧友中删除";
  801. var hhtml = "㈠";
  802. var cclass = "addPlusBack";
  803. var cclick = removeFriend;
  804. } else {
  805. var ttitle = "添加到我的@吧友";
  806. var hhtml = "㈩";
  807. var cclass = "addPlus";
  808. var cclick = addTomyFriend;
  809. }
  810. if ($(this).siblings("spam").length == 0) {
  811. $("<spam>", {
  812. title : ttitle,
  813. html : hhtml,
  814. value : Lhtml,
  815. class : cclass,
  816. click : cclick
  817. }).insertBefore(this);
  818. }
  819. });
  820. }
  821.  
  822. //上传图片默认不选中“加本吧水印”的复选框
  823. addNodeInsertedListener('.i_checkbox', function () {
  824. this.checked = false;
  825. });