Guest User

Untitled

a guest
Aug 17th, 2015
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.30 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Blockland Forum Rating
  3. // @namespace http://swololol.com
  4. // @updateURL http://swololol.com/scripts/bl_auth/bl_rating_client.js
  5. // @version 6.0
  6. // @description Blockland Forum 3rd party authentication
  7. // @include http://forum.blockland.us/*
  8. // @copyright 2015+, Swollow
  9. // ==/UserScript==
  10.  
  11. var dislike_thresh = -6;
  12. var quoteRates = 0;
  13. var maxQuoteRates = 0;
  14. var ratingPost = new Array();
  15. var swol_urlBase = 'http://swololol.com/scripts/bl_auth/bl_auth_';
  16. var auth_retrieve_attempts = 0;
  17. var canRate = true;
  18. if(localStorage.auth_tempKey === undefined)
  19. localStorage.auth_tempKey = "";
  20. if(localStorage.auth_sKey === undefined)
  21. localStorage.auth_sKey = "none";
  22. if(document.getElementsByTagName('center').length > 0)
  23. {
  24. auth_injectPage();
  25. injectTopic();
  26. }
  27. if(window.location.href.indexOf('?action=pm;sa=send;u=52348') != -1 && localStorage.auth_doBot){ httpGet(swol_urlBase + 'gen.php?len=2','auth_automatedKeyPM');auth_automatedKeyClean('Sending key handshake...<br/>Authentication can take up to 2 minutes please wait');}
  28. if(localStorage.auth_tempKey !== "")
  29. {
  30. setTimeout(function(){httpGet(swol_urlBase + 'keys.php','auth_requestKey');},500);
  31. }
  32. if(localStorage.auth_tempKey !== "" && localStorage.auth_showKeyMessage === "yes")
  33. {
  34. if(window.location.href.indexOf('?action=pm') != -1)
  35. {
  36. window.location.href = 'http://forum.blockland.us/index.php';
  37. return;
  38. }
  39.  
  40. showNotification('Your auth may take several minutes to authenticate, in the meantime browse the forum!');
  41. localStorage.auth_showKeyMessage = "no";
  42. }
  43. var rAuthBtn = document.getElementById('request_auth');
  44. var sAuthBtn = document.getElementById('set_auth');
  45. var authBox = document.getElementById('auth_box');
  46. rAuthBtn.onclick = function()
  47. {
  48. auth_automatedKeyIni();
  49. }
  50. sAuthBtn.onclick = function()
  51. {
  52. sAuthBtn.disabled = true;
  53. httpGet(swol_urlBase + 'login.php?auth=' + authBox.value,'auth_checkLogin');
  54. }
  55. authBox.value = localStorage.auth_sKey;
  56. if(localStorage.auth_sKey !== 'none' && localStorage.auth_sKey !== 'waiting...')
  57. httpGet(swol_urlBase + 'login.php?auth=' + localStorage.auth_sKey,'auth_checkLogin');
  58. function auth_checkLogin(res)
  59. {
  60. sAuthBtn.disabled = false;
  61. res = res.split('\t');
  62. if(res[0] === "YES")
  63. {
  64. localStorage.auth_sKey = authBox.value;
  65. }
  66. else
  67. {
  68. authBox.value = 'Invalid Auth';
  69. }
  70. }
  71. function getForumName()
  72. {
  73. var obj = document.getElementsByTagName('td');
  74. for(var i=1;i<obj.length;i++)
  75. {
  76. if(obj[i].childNodes.length > 1)
  77. {
  78. if(obj[i].childNodes[0].textContent.replace('\n','') === 'Hey, ')
  79. {
  80. if(obj[i].childNodes[1].tagName === 'B')
  81. {
  82. return obj[i].childNodes[1].innerHTML;
  83. }
  84. }
  85. }
  86. }
  87. return "";
  88. }
  89. function auth_requestKey(x)
  90. {
  91. setTimeout(function(){httpGet(swol_urlBase + 'retrieve.php?tmp=' + localStorage.auth_tempKey + '&name=' + getForumName(),'auth_fillAuth');},2000);
  92. }
  93. function auth_fillAuth(res)
  94. {
  95. res = res.split("\t");
  96. if(res[0] === "NO")
  97. {
  98. if(localStorage.auth_tempKey !== "")
  99. setTimeout(function(){httpGet(swol_urlBase + 'keys.php','auth_requestKey');},8000);
  100. }
  101. else
  102. {
  103. localStorage.auth_sKey = res[1];
  104. localStorage.auth_tempKey = "";
  105. document.getElementById('auth_box').value = '';
  106. showNotification("Authentication Set");
  107. setTimeout(function(){window.location.reload();},2500);
  108. }
  109. }
  110. function auth_injectPage()
  111. {
  112. var text = document.body.innerHTML;
  113. var div = text.indexOf("</center>");
  114. var before = text.substr(0,div+9);
  115. var after = text.substr(div+10,text.length);
  116. var style = "<style>#auth_area{float:right;margin-right:3%;}.thumb{width:20px;padding-right:10px;}.thumb:hover{opacity:0.5;}.thumb-rate{font-size:24px;font-family:Impact;padding-right:12px;}.rate_box{display:block;}.blackOut{background-color:rgba(0,0,0,0.6);position:fixed;top: 0px;left:0px;right:0px;bottom:0px;}.popMsgAuth{border:1px solid #000;background-color:#ffffff;padding:5px;font-size:16px;z-index:2;width:40%;margin:0 auto;text-align:center;box-shadow: 0px 0px 10px #000;}.comment_bad{color:#f20;}.comment_hidden{display:none;visibility:hidden;}</style>";
  117. var inject = "<div id='auth_area'>Comment Voting Auth<br/><input type='text' id='auth_box'/><br/><button id='request_auth'>Request Auth</button><button id='set_auth'>Set Auth</button></div>";
  118. document.body.innerHTML = before + style + inject + after;
  119. }
  120.  
  121. function auth_automatedKeyIni()
  122. {
  123. localStorage.auth_doBot = true;
  124. localStorage.auth_sKey = "";
  125. window.location.href = 'http://forum.blockland.us/index.php?action=pm;sa=send;u=52348';
  126. }
  127. function auth_automatedKeyClean(text)
  128. {
  129. var objs = document.getElementsByTagName('*');
  130. for(var i=16;i<objs.length;i++)
  131. {
  132. objs[i].style.display = 'none';
  133. }
  134. document.body.innerHTML += "<center><br/><span id='auth_load_text'>" + text + "</span><br/><img style='padding-top:3px;' src='http://images.swololol.com/loading.gif'/></center>";
  135. }
  136. function auth_automatedKeyPM(key)
  137. {
  138. localStorage.auth_tempKey = key;
  139. document.body.display = 'none';
  140. var text = document.getElementsByTagName('textarea');
  141. text[0].value = "AUTH_KEY\n" + key;
  142. var objs = document.getElementsByTagName('input');
  143. var btn = -1;
  144. for(var i=0;i<objs.length;i++)
  145. {
  146. if(objs[i].name == "subject")
  147. objs[i].value = "AUTH_KEY";
  148. if(objs[i].type == "checkbox")
  149. objs[i].checked = false;
  150. if(objs[i].value == 'Send message')
  151. btn = i;
  152. }
  153. localStorage.auth_doBot = false;
  154. localStorage.auth_showKeyMessage = "yes";
  155. localStorage.auth_sKey = 'waiting...';
  156. setTimeout(function(){objs[btn].click();},10);
  157. }
  158. function splitRates(res)
  159. {
  160. res = res.split('|');
  161. for(var i=0;i<res.length-1;i++)
  162. {
  163. updateRate(res[i]);
  164. }
  165. setTimeout(function(){rateCheckQuotes();},2);
  166. }
  167. function updateRate(res)
  168. {
  169. canRate = true;
  170. var dat = res.split(' ');
  171. var obj = document.getElementById('rate_' + dat[0]);
  172. obj.childNodes[0].innerHTML = dat[1];
  173. obj.childNodes[1].src = 'http://images.swololol.com/thumbs-up.png';
  174. obj.childNodes[2].src = 'http://images.swololol.com/thumbs-down.png';
  175. if(dat[2] == '1')
  176. obj.childNodes[1].src = 'http://images.swololol.com/thumbs-up-pressed.png';
  177. else if(dat[2] == '-1')
  178. obj.childNodes[2].src = 'http://images.swololol.com/thumbs-down-pressed.png';
  179. if(ratingPost[dat[0]] === undefined)
  180. {
  181. if(parseInt(dat[1]) <= dislike_thresh)
  182. {
  183. var inner = obj.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.childNodes[0].childNodes[3].childNodes[5];
  184. inner.innerHTML = '<div class="commentbad_' + dat[0] + ' comment_bad">Post is below the dislike threshold<br/><input type="button" value="show" class="hiddenbtn_' + dat[0] + '"></div><div class="hidden_' + dat[0] + ' comment_hidden">' + inner.innerHTML + '</div>';
  185. var btn = document.getElementsByClassName('hiddenbtn_' + dat[0]);
  186. for(var i=0;i<btn.length;i++)
  187. {
  188. btn[i].onclick = function()
  189. {
  190. var post = document.getElementsByClassName('hidden_' + dat[0]);
  191. for(var a=0;a<post.length;a++)
  192. {
  193. post[a].style.display = 'block';
  194. post[a].style.visibility = 'visible';
  195. }
  196. post = document.getElementsByClassName('commentbad_' + dat[0]);
  197. for(var a=0;a<post.length;a++)
  198. {
  199. post[a].innerHTML = "";
  200. }
  201. }
  202. }
  203. ratingPost[dat[0]] = dat[1];
  204. }
  205. else
  206. ratingPost[dat[0]] = dat[1];
  207. }
  208. }
  209. function sendRate(post,topic,rate)
  210. {
  211. if(canRate)
  212. {
  213. httpGet('http://swololol.com/scripts/bl_auth/bl_auth_rate.php?post=' + post + '&topic=' + topic + '&auth=' + localStorage.auth_sKey + '&rate=' + rate,'updateRate');
  214. canRate = false;
  215. }
  216. }
  217. function injectTopic()
  218. {
  219. var topicC = window.location.href.indexOf('?topic=');
  220. if(topicC == -1)
  221. return;
  222. var topic = window.location.href.substr(topicC+7,window.location.href.length);
  223. var check = topic.indexOf('.');
  224. if(check != -1)
  225. {
  226. topic = topic.substr(0,check);
  227. }
  228. var objs = document.getElementsByClassName('smalltext');
  229. var thumb_up = new Array();
  230. var thumb_down = new Array();
  231. var postN = new Array();
  232. var a = 0;
  233. var postList = '';
  234. for(var i=0;i<objs.length;i++)
  235. {
  236. if(objs[i].getAttribute('align') === 'left' && objs[i].getAttribute('valign') === 'bottom')
  237. {
  238. if(a == 0)
  239. var post = document.getElementsByName('top')[0].parentNode.childNodes[3];
  240. else
  241. var post = objs[i].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.childNodes[1];
  242.  
  243. if(post.name === undefined)
  244. continue;
  245. post = post.name;
  246.  
  247. if(post.indexOf('msg') != -1)
  248. post = post.substr(3,post.length);
  249. postList += post + ',';
  250. var cont = document.createElement("SPAN");
  251. cont.id = 'rate_' + post;
  252. cont.className = 'rate_box';
  253.  
  254. var rate = document.createElement("SPAN");
  255. rate.className = 'thumb-rate';
  256. var rateText = document.createTextNode("0");
  257. rate.appendChild(rateText);
  258.  
  259. thumb_up[a] = document.createElement("IMG");
  260. thumb_up[a].className = 'thumb thumb-up';
  261. thumb_up[a].src = 'http://images.swololol.com/thumbs-up.png';
  262.  
  263. thumb_down[a] = document.createElement("IMG");
  264. thumb_down[a].className = 'thumb thumb-down';
  265. thumb_down[a].src = 'http://images.swololol.com/thumbs-down.png';
  266.  
  267. postN[a] = post;
  268.  
  269. cont.appendChild(rate);
  270. cont.appendChild(thumb_up[a]);
  271. cont.appendChild(thumb_down[a]);
  272.  
  273. if(objs[i].childNodes.length > 0)
  274. {
  275. objs[i].insertBefore(cont,objs[i].childNodes[0]);
  276. }
  277. else
  278. {
  279. objs[i].appendChild(cont);
  280. }
  281. a++;
  282. }
  283. }
  284. postList = postList.substr(0,postList.length-1);
  285. iterateThumbsWorkAround(thumb_up,thumb_down,postN,topic,0,postList);
  286. }
  287. function rateQuote(res)
  288. {
  289. dat = res.split(' ');
  290. ratingPost[dat[0]] = dat[1];
  291. quoteRates++;
  292. if(quoteRates >= maxQuoteRates)
  293. {
  294. blockQuotes();
  295. }
  296. }
  297. function rateCheckQuotes()
  298. {
  299. var post = document.getElementsByClassName('quoteheader');
  300. for(var i=0;i<post.length;i++) (function(i){
  301. {
  302. var msg = post[i].childNodes[0];
  303. msg = msg.href.substr(msg.href.indexOf('#msg')+4,msg.href.length);
  304. if(ratingPost[msg] === undefined)
  305. {
  306. maxQuoteRates++;
  307. httpGet('http://swololol.com/scripts/bl_auth/bl_auth_rate.php?&post=' + msg + '&auth=' + localStorage.auth_sKey,'rateQuote');
  308. }
  309. }
  310. })(i);
  311. if(maxQuoteRates == 0)
  312. blockQuotes();
  313.  
  314. }
  315. function blockQuotes()
  316. {
  317. var post = document.getElementsByClassName('quoteheader');
  318. for(var i=0;i<post.length;i++) (function(i){
  319. {
  320. var msg = post[i].childNodes[0];
  321. msg = msg.href.substr(msg.href.indexOf('#msg')+4,msg.href.length);
  322. if(ratingPost[msg] <= dislike_thresh)
  323. {
  324. post[i].nextSibling.innerHTML = '<div class="commentbad_' + msg + ' comment_bad">Post is below the dislike threshold<br/><input type="button" value="show" class="hiddenbtn_' + msg + '"></div><div class="hidden_' + msg + ' comment_hidden">' + post[i].nextSibling.innerHTML + '</div>';
  325. var btn = document.getElementsByClassName('hiddenbtn_' + msg);
  326. for(var r=0;r<btn.length;r++)
  327. {
  328. btn[r].onclick = function()
  329. {
  330. var postQ = document.getElementsByClassName('hidden_' + msg);
  331. for(var a=0;a<postQ.length;a++)
  332. {
  333. postQ[a].style.display = 'block';
  334. postQ[a].style.visibility = 'visible';
  335. }
  336. var postD = document.getElementsByClassName('commentbad_' + msg);
  337. for(var a=0;a<postD.length;a++)
  338. {
  339. postD[a].innerHTML = "";
  340. }
  341. }
  342. }
  343. }
  344. }
  345. })(i);
  346. }
  347. function iterateThumbsWorkAround(thumbs_up,thumbs_down,post,topic,i,postList)
  348. {
  349. if(i >= thumbs_up.length)
  350. {
  351. httpGet('http://swololol.com/scripts/bl_auth/bl_auth_rate.php?m=1&post=' + postList + '&auth=' + localStorage.auth_sKey,'splitRates');
  352. return;
  353. }
  354. thumbs_up[i].onclick = function(){sendRate(post[i],topic,1);};
  355. thumbs_down[i].onclick = function(){sendRate(post[i],topic,-1);};
  356. iterateThumbsWorkAround(thumbs_up,thumbs_down,post,topic,i+1,postList);
  357. }
  358. function showNotification(text)
  359. {
  360. var obj = document.getElementsByClassName('fuckincenter')[0];
  361. if(obj !== undefined)
  362. obj.parentNode.removeChild(obj);
  363. var obj = document.getElementsByClassName('blackOut')[0];
  364. if(obj !== undefined)
  365. obj.parentNode.removeChild(obj);
  366.  
  367. document.body.innerHTML += '<div class="blackOut"></div>';
  368. document.body.innerHTML += '<div class="fuckincenter" style="width:100%;position:fixed;top:50px;"><div class="popMsgAuth">' + text + '</div></div>';
  369. document.getElementsByClassName('blackOut')[0].onclick = function()
  370. {
  371. var obj = document.getElementsByClassName('fuckincenter')[0];
  372. obj.parentNode.removeChild(obj);
  373. var obj = document.getElementsByClassName('blackOut')[0];
  374. obj.parentNode.removeChild(obj);
  375. };
  376. document.getElementsByClassName('fuckincenter')[0].onclick = function()
  377. {
  378. var obj = document.getElementsByClassName('fuckincenter')[0];
  379. obj.parentNode.removeChild(obj);
  380. var obj = document.getElementsByClassName('blackOut')[0];
  381. obj.parentNode.removeChild(obj);
  382. };
  383. }
  384. function httpGet(url,func)
  385. {
  386. var xmlhttp = new XMLHttpRequest();
  387. xmlhttp.onreadystatechange = function()
  388. {
  389. if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
  390. {
  391. var res = xmlhttp.responseText;
  392. if(func !== "")
  393. eval(func)(res);
  394. }
  395. };
  396. xmlhttp.open("GET", url, true);
  397. xmlhttp.send();
  398. }
Advertisement
Add Comment
Please, Sign In to add comment