sg farmkit

SG伐木助手

目前为 2015-06-30 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name sg farmkit
  3. // @namespace com.sgamer.bbs.farmkit
  4. // @description SG伐木助手
  5. // @include http://bbs.sgamer.com/thread-*.html
  6. // @include http://bbs.sgamer.com/*mod=viewthread*
  7. // @version 2.1.0
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. var devmode = false;
  12. if (devmode) {
  13. var timestamp = new Date();
  14. }
  15.  
  16. var pcrr = {
  17. "枪": "枪",
  18. "弹": "弹",
  19. "性": "性",
  20. "毒": "毒",
  21. "裸": "裸",
  22. "仇": "仇",
  23. "奸": "奸",
  24. "淫": "淫"
  25. }
  26.  
  27. var rrr = {
  28. "(不共戴天之|复|报)\\*": "$1仇",
  29. "(显示器)\\*\\*": "$1杀手",
  30. "\\*(幕)": "弹$1",
  31. "(躺|火)\\*": "$1枪",
  32. "(核|炸)\\*": "$1弹",
  33. "(剧|为什么这么)\\*": "$1毒",
  34. "(意)\\*": "$1淫",
  35. "(汉)\\*": "$1奸",
  36. "\\*(情|格|感|别|取向|质)": "性$1",
  37. "\\*(龙|镖|瘤|奶|狗|素)": "毒$1",
  38. "\\*(恨)": "仇$1",
  39. "\\*(照)": "裸$1",
  40. "\\*(妇|荡)": "淫$1",
  41. "\\*(臣)": "奸$1",
  42. "(任|可能|世界|历史|人|个|男|女|属|理|局限|专业|进攻|本|选择|关键|重要|习惯|灵|观赏|记|惰|理|品|惯|秉)\\*": "$1性"
  43. }
  44.  
  45. var fastFormNames = ["fastpostform", "vfastpostform"];
  46.  
  47. function createCommentButtonByReplyButton(fastre)
  48. {
  49. var a = document.createElement("a");
  50. a.className = "cmmnt";
  51. a.onclick = function () {
  52. showWindow('comment', this.href, 'get', 1);
  53. setTimeout(function () {
  54. var commentform = document.getElementById("commentform");
  55. var action = commentform.action;
  56. action = action.replace(/tid=[0-9]+/, fastre.href.match(/tid=[0-9]+/));
  57. action = action.replace(/pid=[0-9]+/, fastre.href.match(/repquote=[0-9]+/)[0].replace("repquote","pid"));
  58. commentform.action = action;
  59. }, 500);
  60. };
  61. a.href = "forum.php?mod=misc&action=comment&tid=12360082&pid=30553315&extra=page%3D1&page=1";
  62. a.appendChild(document.createTextNode("点评"));
  63. return a;
  64. }
  65.  
  66. function createFastReplyBox() {
  67. var box = document.createElement("div");
  68. box.style.cssText = "width: 150px; display: none";
  69. box.appendChild(createFastReplyItem("油菜花"));
  70. box.appendChild(createFastReplyItem("+1"));
  71. box.appendChild(createFastReplyItem("就是这样"));
  72. box.appendChild(createFastReplyItem("道理是这么个道理"));
  73. box.appendChild(createFastReplyItem("卜是卜可以"));
  74. box.appendChild(createFastReplyItem("妮说是就是"));
  75. box.appendChild(createFastReplyItem("抽根烟,压压惊"));
  76. box.appendChild(createFastReplyItem("关我pis"));
  77. box.appendChild(createFastReplyItem("这个投票我就不参与了"));
  78. box.appendChild(createFastReplyItem("我选择死亡"));
  79. box.appendChild(createFastReplyItem("半天说不出一句话"));
  80. box.appendChild(createFastReplyItem("XNMBYY"));
  81. box.appendChild(createFastReplyItem("脏是妮脏"));
  82. box.appendChild(createFastReplyItem("妮为什么这么毒"));
  83. box.appendChild(createFastReplyItem("这件事窝已经报警"));
  84. box.appendChild(createFastReplyItem("建议永丰"));
  85. box.appendChild(createFastReplyItem("ZZWDJS!!!"));
  86. box.appendChild(createFastReplyItem("什么节奏"));
  87. box.onmouseout = function (e) {
  88. if (isParent(e.relatedTarget, this.parentNode.parentNode)) {
  89. return false;
  90. }
  91. this.style.display = "none";
  92. }
  93. return box;
  94. }
  95.  
  96. function createFastReplyItem(str) {
  97. var item = document.createElement("div");
  98. item.appendChild(document.createTextNode(str));
  99. item.style.cursor = "pointer";
  100. item.style.color = "gray";
  101. item.onclick = function () {
  102. this.parentNode.style.display = "none";
  103. replyFarm(this.parentNode.parentNode.fastre.href, this.innerHTML);
  104. }
  105. item.onmouseover = function () {item.style.color = "green"}
  106. item.onmouseout = function () {item.style.color = "gray"}
  107. return item;
  108. }
  109.  
  110. // 回复主题
  111. function fastfarm(replyStr) {
  112. if (getCookie("SG_farmkit_ifPostTimeLimit")) {
  113. onNeedMoreTime();
  114. return;
  115. }
  116. document.getElementById("fastpostmessage").value = precensore(recoverText(replyStr));
  117. setTimeLimit();
  118. document.getElementById("fastpostform").submit();
  119. }
  120.  
  121. function getCookie(c_name) {
  122. if (document.cookie.length > 0) {
  123. c_start = document.cookie.indexOf(c_name + "=");
  124. if (c_start != -1) {
  125. c_start = c_start + c_name.length + 1 ;
  126. c_end = document.cookie.indexOf(";", c_start);
  127. if (c_end == -1) {
  128. c_end = document.cookie.length;
  129. }
  130. return unescape(document.cookie.substring(c_start, c_end));
  131. }
  132. }
  133. return "";
  134. }
  135.  
  136. function isParent(obj, parentObj){
  137. while (obj != undefined && obj != null && obj.tagName.toUpperCase() != 'BODY') {
  138. if (obj == parentObj){
  139. return true;
  140. }
  141. obj = obj.parentNode;
  142. }
  143. return false;
  144. }
  145.  
  146. function onNeedMoreTime() {
  147. if (document.getElementById('ntcwin')) {
  148. var ntcwin = document.getElementById('ntcwin');
  149. } else {
  150. var ntcwin = document.createElement('div');
  151. ntcwin.id = "ntcwin";
  152. ntcwin.className = "popuptext";
  153. ntcwin.style.cssText = "position: fixed; z-index: 501; left: 466.5px; top: 30px; display: none;";
  154. document.getElementById("append_parent").appendChild(ntcwin);
  155. var table = document.createElement("table");
  156. table.className = "popupcredit";
  157. table.cellspacing = "0";
  158. table.cellpadding = "0";
  159. ntcwin.appendChild(table);
  160. var tr = document.createElement("tr");
  161. table.appendChild(tr);
  162. var tdl = document.createElement("td");
  163. tdl.className = "pc_l";
  164. tr.appendChild(tdl);
  165. var tdc = document.createElement("td");
  166. tdc.className = "pc_c";
  167. tr.appendChild(tdc);
  168. var tdr = document.createElement("td");
  169. tdr.className = "pc_r";
  170. tr.appendChild(tdr);
  171. var div_inner = document.createElement("div");
  172. div_inner.className = "pc_inner";
  173. tdc.appendChild(div_inner);
  174. var i_text = document.createElement("i");
  175. i_text.innerHTML = "抱歉,您两次发表间隔少于 15 秒,请稍候再发表";
  176. div_inner.appendChild(i_text);
  177. }
  178. document.getElementById('ntcwin').style.display = "block";
  179. setTimeout(function () {
  180. document.getElementById('ntcwin').style.display = "none";
  181. }, 2500);
  182. }
  183.  
  184. function precensore (str) {
  185. if (str) {
  186. for (var ch in pcrr) {
  187. str = str.replace(new RegExp(ch, "ig"), pcrr[ch]);
  188. }
  189. }
  190. if (str.length < 10) {
  191. str = str + " ";
  192. }
  193. return str;
  194. }
  195.  
  196. function precensoreFastForm(formName) {
  197. var form = document.getElementById(formName);
  198. if (form) {
  199. form.onsubmit = function (e) {
  200. this.message.value = parseurl(precensore(this.message.value));
  201. setTimeLimit();
  202. ajaxpost(formName, 'return_reply', 'return_reply', 'onerror');
  203. return false;
  204. }
  205. }
  206. }
  207.  
  208. function recoverText (str) {
  209. if (str) {
  210. for (var ch in rrr) {
  211. str = str.replace(new RegExp(ch, "ig"), rrr[ch]);
  212. }
  213. }
  214. return str;
  215. }
  216.  
  217. function replaceFace(e) {
  218. var nodes = e.childNodes;
  219. for (var i = 0; i < nodes.length; i++) {
  220. if (nodes[i].nodeName && nodes[i].nodeName.toLowerCase() == "img") {
  221. var smilieid = nodes[i].getAttribute("smilieid");
  222. if (smilieid >= 85 && smilieid <= 137) {
  223. e.replaceChild(document.createTextNode("{:" + smilieid + ":}"), nodes[i]);
  224. } else if (smilieid >= 343 && smilieid <= 419) {
  225. e.replaceChild(document.createTextNode("{:6_" + smilieid + ":}"), nodes[i]);
  226. } else if (smilieid == 169 || smilieid == 177 || smilieid == 170 || smilieid == 178) {
  227. e.replaceChild(document.createTextNode("{:3_" + smilieid + ":}"), nodes[i]);
  228. } else if (smilieid >= 171 && smilieid <= 176 || smilieid >= 179 && smilieid <= 181) {
  229. e.replaceChild(document.createTextNode("{:7_" + smilieid + ":}"), nodes[i]);
  230. } else if (smilieid >= 168 && smilieid <= 276) {
  231. e.replaceChild(document.createTextNode("{:5_" + smilieid + ":}"), nodes[i]);
  232. } else {
  233. e.replaceChild(document.createTextNode("[img=" + nodes[i].width + "," + nodes[i].height + "]" + nodes[i].src + "[/img]"), nodes[i]);
  234. }
  235. }
  236. }
  237. }
  238.  
  239. function replyFarm(url, str) {
  240. if (getCookie("SG_farmkit_ifPostTimeLimit")) {
  241. onNeedMoreTime();
  242. return;
  243. }
  244. var reply_box = document.createElement("div");
  245. var xmlhttp = new XMLHttpRequest();
  246. xmlhttp.open("GET", url + "&infloat=yes&handlekey=reply&inajax=1&ajaxtarget=fwin_content_reply",true);
  247. xmlhttp.onreadystatechange = function() {
  248. if (xmlhttp.readyState==4 && xmlhttp.status==200) {
  249. reply_box.innerHTML = xmlhttp.responseXML.documentElement.childNodes[0].data;
  250. document.getElementById("postform").message.value = precensore(recoverText(str));
  251. setTimeLimit();
  252. document.getElementById("postform").submit();
  253. }
  254. }
  255. xmlhttp.send();
  256. document.body.appendChild(reply_box);
  257. }
  258.  
  259. function setCookie (c_name, value, expiresecs) {
  260. var exdate = new Date();
  261. exdate.setSeconds(exdate.getSeconds() + expiresecs);
  262. document.cookie = c_name + "=" + escape(value) + ((expiresecs == null) ? "" : ";expires=" + exdate.toGMTString());
  263. }
  264.  
  265. function setTimeLimit() {
  266. setCookie("SG_farmkit_ifPostTimeLimit", "1", 16);
  267. }
  268.  
  269. // 回复栏和快速回复栏
  270. (function () {
  271. for (var i = 0; i < fastFormNames.length; i++) {
  272. precensoreFastForm(fastFormNames[i]);
  273. }
  274. })();
  275.  
  276. // 侧边栏弹出回复栏
  277. (function () {
  278. document.getElementById("scrolltop").getElementsByTagName("a")[0].onclick = function () {
  279. showWindow('reply', this.href);
  280. setTimeout(function () {
  281. precensoreFastForm("postform");
  282. }, 500);
  283. return false;
  284. }
  285. })();
  286.  
  287. // 页面标题
  288. (function () {
  289. var tt = document.title;
  290. document.title = recoverText(tt);
  291. })();
  292.  
  293. // 主题标题
  294. (function () {
  295. var ih = document.getElementById("thread_subject").innerHTML;
  296. document.getElementById("thread_subject").innerHTML = recoverText(ih);
  297. })();
  298.  
  299. // 帖子顶栏、内容和底部
  300. (function () {
  301. var postlist = document.getElementById("postlist");
  302. if (postlist == null) {
  303. return;
  304. }
  305. var postNodes = postlist.childNodes;
  306. for (var i = 0, isReply = 0; i < postNodes.length; i++) {
  307. var postNode = postNodes[i];
  308. if (postNode &&
  309. postNode.getAttribute &&
  310. postNode.getAttribute("id") &&
  311. postNode.getAttribute("id").match("post_")) {
  312. var tds = postNode.getElementsByTagName("td");
  313. for (var k = 0; k < tds.length; k++) {
  314. // 内容
  315. if (tds[k].id && tds[k].id.match("postmessage_")) {
  316. tds[k].innerHTML = recoverText(tds[k].innerHTML);
  317. }
  318. }
  319. var fastre = null;
  320. var as = postNode.getElementsByTagName("a");
  321. var asLength = as.length;
  322. for (var k = 0; k < asLength; k++) {
  323. if (as[k].className == "fastre") {
  324. fastre = as[k];
  325. // 底部
  326. var firstNode = fastre.parentNode.getElementsByTagName("a")[0];
  327. if (firstNode.className != "cmmnt")
  328. {
  329. fastre.parentNode.insertBefore(createCommentButtonByReplyButton(fastre), fastre);
  330. }
  331. }
  332. }
  333. // 顶部
  334. if (isReply == 1) {
  335. var divs = postNode.getElementsByTagName("div");
  336. for (var j = 0; j < divs.length; j++) {
  337. if (divs[j].className == "authi" && divs[j].parentNode.className == "pti") {
  338. var span = document.createElement("span");
  339. span.className = "pipe";
  340. span.innerHTML = "|";
  341. span.style.cssFloat = "right";
  342. span.style.lineHeight = "16px";
  343. span.style.margin = "0px 2px";
  344. divs[j].appendChild(span);
  345. divs[j].appendChild(document.createTextNode("\n"));
  346. var farmArchor = document.createElement("a");
  347. farmArchor.innerHTML = "复制伐木";
  348. farmArchor.style.color = "green";
  349. farmArchor.style.cursor = "pointer";
  350. farmArchor.style.cssFloat = "right";
  351. farmArchor.style.lineHeight = "16px";
  352. farmArchor.style.padding = "0px 6px";
  353. divs[j].appendChild(farmArchor);
  354. divs[j].appendChild(document.createTextNode("\n"));
  355. var span1 = document.createElement("span");
  356. span1.className = "pipe";
  357. span1.innerHTML = "|";
  358. span1.style.cssFloat = "right";
  359. span1.style.lineHeight = "16px";
  360. span1.style.margin = "0px 2px";
  361. divs[j].appendChild(span1);
  362. var replyBox = document.createElement("span");
  363. var replyArchor = document.createElement("span");
  364. replyBox.appendChild(replyArchor);
  365. replyArchor.innerHTML = "快速回复";
  366. replyBox.style.cssText = "float: right; padding: 0px 6px;"
  367. replyArchor.style.cssText = "color: green; cursor: pointer; line-height: 16px;";
  368. divs[j].appendChild(replyBox);
  369. var fastReplyPoint = document.createElement("div");
  370. fastReplyPoint.style.cssText = "overflow-x: visible; overflow-y: visible; position: relative; height: 0px; width: 0px;";
  371. replyBox.appendChild(fastReplyPoint);
  372. replyBox.onmouseover = function () {
  373. this.childNodes[1].childNodes[0].style.display = "block";
  374. }
  375. replyBox.onmouseout = function (e) {
  376. if (isParent(e.relatedTarget, this)) {
  377. return false;
  378. }
  379. this.childNodes[1].childNodes[0].style.display = "none";
  380. }
  381. fastReplyPoint.appendChild(createFastReplyBox());
  382. divs[j].parentNode.parentNode.style.cssText = "overflow-x: visible; overflow-y: visible;";
  383. fastReplyPoint.fastre = fastre;
  384. farmArchor.divPElement = divs[j];
  385. farmArchor.onclick = function () {
  386. if (getCookie("SG_farmkit_ifPostTimeLimit")) {
  387. onNeedMoreTime();
  388. return false;
  389. }
  390. var postText = "伐木伐木";
  391. var tds = this.divPElement.parentNode.parentNode.parentNode.getElementsByTagName("td");
  392. for (var k = 0; k < tds.length; k++) {
  393. if (tds[k].getAttribute("id").match("postmessage_")) {
  394. replaceFace(tds[k]);
  395. postText = (tds[k].innerText || tds[k].textContent || tds[k].text).replace(/^\s*/g, "");
  396. if (postText[0] == "\n") {
  397. postText = postText.slice(1);
  398. }
  399. break;
  400. }
  401. }
  402. fastfarm(postText);
  403. return false;
  404. }
  405. }
  406. }
  407. } else {
  408. var divs = postNode.getElementsByTagName("div");
  409. for (var j = 0; j < divs.length; j++) {
  410. if (divs[j].className == "authi" && divs[j].parentNode.className == "pti") {
  411. var span = document.createElement("span");
  412. span.className = "pipe";
  413. span.innerHTML = "|";
  414. span.style.cssFloat = "right";
  415. span.style.lineHeight = "16px";
  416. span.style.margin = "0px 2px";
  417. divs[j].appendChild(span);
  418. divs[j].appendChild(document.createTextNode("\n"));
  419. var farmArchor = document.createElement("a");
  420. farmArchor.innerHTML = "复制伐木";
  421. farmArchor.style.cssText = "color: green; cursor: pointer; float: right; line-height: 16px; padding: 0px 6px; -moz-user-select:none; -webkit-user-select:none; user-select:none;";
  422. divs[j].appendChild(farmArchor);
  423. divs[j].appendChild(document.createTextNode("\n"));
  424. var span1 = document.createElement("span");
  425. span1.className = "pipe";
  426. span1.innerHTML = "|";
  427. span1.style.cssFloat = "right";
  428. span1.style.lineHeight = "16px";
  429. span1.style.margin = "0px 2px";
  430. divs[j].appendChild(span1);
  431. var replyBox = document.createElement("span");
  432. var replyArchor = document.createElement("span");
  433. replyBox.appendChild(replyArchor);
  434. replyArchor.innerHTML = "快速回复";
  435. replyBox.style.cssText = "float: right; padding: 0px 6px;"
  436. replyArchor.style.cssText = "color: green; cursor: pointer; line-height: 16px;";
  437. divs[j].appendChild(replyBox);
  438. var fastReplyPoint = document.createElement("div");
  439. fastReplyPoint.style.cssText = "overflow-x: visible; overflow-y: visible; position: relative; height: 0px; width: 0px;";
  440. replyBox.appendChild(fastReplyPoint);
  441. replyBox.onmouseover = function () {
  442. this.childNodes[1].childNodes[0].style.display = "block";
  443. }
  444. replyBox.onmouseout = function (e) {
  445. if (isParent(e.relatedTarget, this)) {
  446. return false;
  447. }
  448. this.childNodes[1].childNodes[0].style.display = "none";
  449. }
  450. fastReplyPoint.appendChild(createFastReplyBox());
  451. fastReplyPoint.fastre = fastre;
  452. divs[j].parentNode.parentNode.style.cssText = "overflow-x: visible; overflow-y: visible;";
  453. farmArchor.divPElement = divs[j];
  454. farmArchor.onclick = function () {
  455. if (getCookie("SG_farmkit_ifPostTimeLimit")) {
  456. onNeedMoreTime();
  457. return false;
  458. }
  459. var postText = "伐木伐木";
  460. var tds = this.divPElement.parentNode.parentNode.parentNode.getElementsByTagName("td");
  461. var selection = window.getSelection();
  462. var selectionText;
  463. if (selection != null && !selection.isCollapsed) {
  464. var focusNode = selection.focusNode;
  465. var focusOffset = selection.focusOffset;
  466. var anchorNode = selection.anchorNode;
  467. var anchorOffset = selection.anchorOffset
  468. replaceFace(selection.anchorNode.parentNode);
  469. selection.collapse(anchorNode, anchorOffset);
  470. selection.extend(focusNode, focusOffset);
  471. selectionText = selection.toString();
  472. }
  473. if (selectionText != null && selectionText.length > 0) {
  474. postText = selectionText;
  475. fastfarm(postText);
  476. return false;
  477. }
  478. for (var k = 0; k < tds.length; k++) {
  479. if (tds[k].getAttribute("id").match("postmessage_")) {
  480. replaceFace(tds[k]);
  481. postText = (tds[k].innerText || tds[k].textContent || tds[k].text)
  482. .replace(/(^\s*)|(\s*$)/g, "").split("\n").pop();
  483. if (postText[0] == "\n") {
  484. postText = postText.slice(1);
  485. }
  486. break;
  487. }
  488. }
  489. fastfarm(postText);
  490. return false;
  491. }
  492. }
  493. }
  494. isReply = 1;
  495. }
  496. }
  497. }
  498. })();
  499.  
  500. if (devmode) {
  501. alert("耗时:" + (new Date().getTime() - timestamp.getTime()) + "毫秒");
  502. }