sg farmkit

SG伐木助手

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