sg farmkit

SG伐木助手

目前为 2016-02-09 提交的版本,查看 最新版本

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