sg farmkit

SG伐木助手

目前为 2015-07-08 提交的版本。查看 最新版本

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