Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Blockland Forum Rating
- // @namespace http://swololol.com
- // @updateURL http://swololol.com/scripts/bl_auth/bl_rating_client.js
- // @version 6.0
- // @description Blockland Forum 3rd party authentication
- // @include http://forum.blockland.us/*
- // @copyright 2015+, Swollow
- // ==/UserScript==
- var dislike_thresh = -6;
- var quoteRates = 0;
- var maxQuoteRates = 0;
- var ratingPost = new Array();
- var swol_urlBase = 'http://swololol.com/scripts/bl_auth/bl_auth_';
- var auth_retrieve_attempts = 0;
- var canRate = true;
- if(localStorage.auth_tempKey === undefined)
- localStorage.auth_tempKey = "";
- if(localStorage.auth_sKey === undefined)
- localStorage.auth_sKey = "none";
- if(document.getElementsByTagName('center').length > 0)
- {
- auth_injectPage();
- injectTopic();
- }
- 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');}
- if(localStorage.auth_tempKey !== "")
- {
- setTimeout(function(){httpGet(swol_urlBase + 'keys.php','auth_requestKey');},500);
- }
- if(localStorage.auth_tempKey !== "" && localStorage.auth_showKeyMessage === "yes")
- {
- if(window.location.href.indexOf('?action=pm') != -1)
- {
- window.location.href = 'http://forum.blockland.us/index.php';
- return;
- }
- showNotification('Your auth may take several minutes to authenticate, in the meantime browse the forum!');
- localStorage.auth_showKeyMessage = "no";
- }
- var rAuthBtn = document.getElementById('request_auth');
- var sAuthBtn = document.getElementById('set_auth');
- var authBox = document.getElementById('auth_box');
- rAuthBtn.onclick = function()
- {
- auth_automatedKeyIni();
- }
- sAuthBtn.onclick = function()
- {
- sAuthBtn.disabled = true;
- httpGet(swol_urlBase + 'login.php?auth=' + authBox.value,'auth_checkLogin');
- }
- authBox.value = localStorage.auth_sKey;
- if(localStorage.auth_sKey !== 'none' && localStorage.auth_sKey !== 'waiting...')
- httpGet(swol_urlBase + 'login.php?auth=' + localStorage.auth_sKey,'auth_checkLogin');
- function auth_checkLogin(res)
- {
- sAuthBtn.disabled = false;
- res = res.split('\t');
- if(res[0] === "YES")
- {
- localStorage.auth_sKey = authBox.value;
- }
- else
- {
- authBox.value = 'Invalid Auth';
- }
- }
- function getForumName()
- {
- var obj = document.getElementsByTagName('td');
- for(var i=1;i<obj.length;i++)
- {
- if(obj[i].childNodes.length > 1)
- {
- if(obj[i].childNodes[0].textContent.replace('\n','') === 'Hey, ')
- {
- if(obj[i].childNodes[1].tagName === 'B')
- {
- return obj[i].childNodes[1].innerHTML;
- }
- }
- }
- }
- return "";
- }
- function auth_requestKey(x)
- {
- setTimeout(function(){httpGet(swol_urlBase + 'retrieve.php?tmp=' + localStorage.auth_tempKey + '&name=' + getForumName(),'auth_fillAuth');},2000);
- }
- function auth_fillAuth(res)
- {
- res = res.split("\t");
- if(res[0] === "NO")
- {
- if(localStorage.auth_tempKey !== "")
- setTimeout(function(){httpGet(swol_urlBase + 'keys.php','auth_requestKey');},8000);
- }
- else
- {
- localStorage.auth_sKey = res[1];
- localStorage.auth_tempKey = "";
- document.getElementById('auth_box').value = '';
- showNotification("Authentication Set");
- setTimeout(function(){window.location.reload();},2500);
- }
- }
- function auth_injectPage()
- {
- var text = document.body.innerHTML;
- var div = text.indexOf("</center>");
- var before = text.substr(0,div+9);
- var after = text.substr(div+10,text.length);
- 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>";
- 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>";
- document.body.innerHTML = before + style + inject + after;
- }
- function auth_automatedKeyIni()
- {
- localStorage.auth_doBot = true;
- localStorage.auth_sKey = "";
- window.location.href = 'http://forum.blockland.us/index.php?action=pm;sa=send;u=52348';
- }
- function auth_automatedKeyClean(text)
- {
- var objs = document.getElementsByTagName('*');
- for(var i=16;i<objs.length;i++)
- {
- objs[i].style.display = 'none';
- }
- 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>";
- }
- function auth_automatedKeyPM(key)
- {
- localStorage.auth_tempKey = key;
- document.body.display = 'none';
- var text = document.getElementsByTagName('textarea');
- text[0].value = "AUTH_KEY\n" + key;
- var objs = document.getElementsByTagName('input');
- var btn = -1;
- for(var i=0;i<objs.length;i++)
- {
- if(objs[i].name == "subject")
- objs[i].value = "AUTH_KEY";
- if(objs[i].type == "checkbox")
- objs[i].checked = false;
- if(objs[i].value == 'Send message')
- btn = i;
- }
- localStorage.auth_doBot = false;
- localStorage.auth_showKeyMessage = "yes";
- localStorage.auth_sKey = 'waiting...';
- setTimeout(function(){objs[btn].click();},10);
- }
- function splitRates(res)
- {
- res = res.split('|');
- for(var i=0;i<res.length-1;i++)
- {
- updateRate(res[i]);
- }
- setTimeout(function(){rateCheckQuotes();},2);
- }
- function updateRate(res)
- {
- canRate = true;
- var dat = res.split(' ');
- var obj = document.getElementById('rate_' + dat[0]);
- obj.childNodes[0].innerHTML = dat[1];
- obj.childNodes[1].src = 'http://images.swololol.com/thumbs-up.png';
- obj.childNodes[2].src = 'http://images.swololol.com/thumbs-down.png';
- if(dat[2] == '1')
- obj.childNodes[1].src = 'http://images.swololol.com/thumbs-up-pressed.png';
- else if(dat[2] == '-1')
- obj.childNodes[2].src = 'http://images.swololol.com/thumbs-down-pressed.png';
- if(ratingPost[dat[0]] === undefined)
- {
- if(parseInt(dat[1]) <= dislike_thresh)
- {
- var inner = obj.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.childNodes[0].childNodes[3].childNodes[5];
- 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>';
- var btn = document.getElementsByClassName('hiddenbtn_' + dat[0]);
- for(var i=0;i<btn.length;i++)
- {
- btn[i].onclick = function()
- {
- var post = document.getElementsByClassName('hidden_' + dat[0]);
- for(var a=0;a<post.length;a++)
- {
- post[a].style.display = 'block';
- post[a].style.visibility = 'visible';
- }
- post = document.getElementsByClassName('commentbad_' + dat[0]);
- for(var a=0;a<post.length;a++)
- {
- post[a].innerHTML = "";
- }
- }
- }
- ratingPost[dat[0]] = dat[1];
- }
- else
- ratingPost[dat[0]] = dat[1];
- }
- }
- function sendRate(post,topic,rate)
- {
- if(canRate)
- {
- httpGet('http://swololol.com/scripts/bl_auth/bl_auth_rate.php?post=' + post + '&topic=' + topic + '&auth=' + localStorage.auth_sKey + '&rate=' + rate,'updateRate');
- canRate = false;
- }
- }
- function injectTopic()
- {
- var topicC = window.location.href.indexOf('?topic=');
- if(topicC == -1)
- return;
- var topic = window.location.href.substr(topicC+7,window.location.href.length);
- var check = topic.indexOf('.');
- if(check != -1)
- {
- topic = topic.substr(0,check);
- }
- var objs = document.getElementsByClassName('smalltext');
- var thumb_up = new Array();
- var thumb_down = new Array();
- var postN = new Array();
- var a = 0;
- var postList = '';
- for(var i=0;i<objs.length;i++)
- {
- if(objs[i].getAttribute('align') === 'left' && objs[i].getAttribute('valign') === 'bottom')
- {
- if(a == 0)
- var post = document.getElementsByName('top')[0].parentNode.childNodes[3];
- else
- var post = objs[i].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.childNodes[1];
- if(post.name === undefined)
- continue;
- post = post.name;
- if(post.indexOf('msg') != -1)
- post = post.substr(3,post.length);
- postList += post + ',';
- var cont = document.createElement("SPAN");
- cont.id = 'rate_' + post;
- cont.className = 'rate_box';
- var rate = document.createElement("SPAN");
- rate.className = 'thumb-rate';
- var rateText = document.createTextNode("0");
- rate.appendChild(rateText);
- thumb_up[a] = document.createElement("IMG");
- thumb_up[a].className = 'thumb thumb-up';
- thumb_up[a].src = 'http://images.swololol.com/thumbs-up.png';
- thumb_down[a] = document.createElement("IMG");
- thumb_down[a].className = 'thumb thumb-down';
- thumb_down[a].src = 'http://images.swololol.com/thumbs-down.png';
- postN[a] = post;
- cont.appendChild(rate);
- cont.appendChild(thumb_up[a]);
- cont.appendChild(thumb_down[a]);
- if(objs[i].childNodes.length > 0)
- {
- objs[i].insertBefore(cont,objs[i].childNodes[0]);
- }
- else
- {
- objs[i].appendChild(cont);
- }
- a++;
- }
- }
- postList = postList.substr(0,postList.length-1);
- iterateThumbsWorkAround(thumb_up,thumb_down,postN,topic,0,postList);
- }
- function rateQuote(res)
- {
- dat = res.split(' ');
- ratingPost[dat[0]] = dat[1];
- quoteRates++;
- if(quoteRates >= maxQuoteRates)
- {
- blockQuotes();
- }
- }
- function rateCheckQuotes()
- {
- var post = document.getElementsByClassName('quoteheader');
- for(var i=0;i<post.length;i++) (function(i){
- {
- var msg = post[i].childNodes[0];
- msg = msg.href.substr(msg.href.indexOf('#msg')+4,msg.href.length);
- if(ratingPost[msg] === undefined)
- {
- maxQuoteRates++;
- httpGet('http://swololol.com/scripts/bl_auth/bl_auth_rate.php?&post=' + msg + '&auth=' + localStorage.auth_sKey,'rateQuote');
- }
- }
- })(i);
- if(maxQuoteRates == 0)
- blockQuotes();
- }
- function blockQuotes()
- {
- var post = document.getElementsByClassName('quoteheader');
- for(var i=0;i<post.length;i++) (function(i){
- {
- var msg = post[i].childNodes[0];
- msg = msg.href.substr(msg.href.indexOf('#msg')+4,msg.href.length);
- if(ratingPost[msg] <= dislike_thresh)
- {
- 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>';
- var btn = document.getElementsByClassName('hiddenbtn_' + msg);
- for(var r=0;r<btn.length;r++)
- {
- btn[r].onclick = function()
- {
- var postQ = document.getElementsByClassName('hidden_' + msg);
- for(var a=0;a<postQ.length;a++)
- {
- postQ[a].style.display = 'block';
- postQ[a].style.visibility = 'visible';
- }
- var postD = document.getElementsByClassName('commentbad_' + msg);
- for(var a=0;a<postD.length;a++)
- {
- postD[a].innerHTML = "";
- }
- }
- }
- }
- }
- })(i);
- }
- function iterateThumbsWorkAround(thumbs_up,thumbs_down,post,topic,i,postList)
- {
- if(i >= thumbs_up.length)
- {
- httpGet('http://swololol.com/scripts/bl_auth/bl_auth_rate.php?m=1&post=' + postList + '&auth=' + localStorage.auth_sKey,'splitRates');
- return;
- }
- thumbs_up[i].onclick = function(){sendRate(post[i],topic,1);};
- thumbs_down[i].onclick = function(){sendRate(post[i],topic,-1);};
- iterateThumbsWorkAround(thumbs_up,thumbs_down,post,topic,i+1,postList);
- }
- function showNotification(text)
- {
- var obj = document.getElementsByClassName('fuckincenter')[0];
- if(obj !== undefined)
- obj.parentNode.removeChild(obj);
- var obj = document.getElementsByClassName('blackOut')[0];
- if(obj !== undefined)
- obj.parentNode.removeChild(obj);
- document.body.innerHTML += '<div class="blackOut"></div>';
- document.body.innerHTML += '<div class="fuckincenter" style="width:100%;position:fixed;top:50px;"><div class="popMsgAuth">' + text + '</div></div>';
- document.getElementsByClassName('blackOut')[0].onclick = function()
- {
- var obj = document.getElementsByClassName('fuckincenter')[0];
- obj.parentNode.removeChild(obj);
- var obj = document.getElementsByClassName('blackOut')[0];
- obj.parentNode.removeChild(obj);
- };
- document.getElementsByClassName('fuckincenter')[0].onclick = function()
- {
- var obj = document.getElementsByClassName('fuckincenter')[0];
- obj.parentNode.removeChild(obj);
- var obj = document.getElementsByClassName('blackOut')[0];
- obj.parentNode.removeChild(obj);
- };
- }
- function httpGet(url,func)
- {
- var xmlhttp = new XMLHttpRequest();
- xmlhttp.onreadystatechange = function()
- {
- if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
- {
- var res = xmlhttp.responseText;
- if(func !== "")
- eval(func)(res);
- }
- };
- xmlhttp.open("GET", url, true);
- xmlhttp.send();
- }
Advertisement
Add Comment
Please, Sign In to add comment