sg farmkit

SG伐木助手

目前为 2015-02-28 提交的版本。查看 最新版本

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