graou13

sb.js

Jul 14th, 2014
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*#Credits to Graou this sb.js*/
  2.  
  3. function toggleSB() {
  4.     if(document.getElementById("shoutbox_e").style.display == "none") {return "lolnope";}
  5.     var size = document.getElementById("shoutbox_data").scrollHeight + "px";
  6.     var exButton = document.getElementById("datToggle");
  7.     var height = document.getElementById("shoutbox_data").style.height;
  8.     if(height == SBContractSize) {
  9.         document.getElementById("shoutbox_data").style.height = size;
  10.         exButton.innerHTML = "Contract ShoutBox";
  11.     } else if(height >= size) {
  12.         document.getElementById("shoutbox_data").style.height = SBContractSize;
  13.         exButton.innerHTML = "Expand ShoutBox";
  14.     } else if(height < size) {
  15.         SBContractSize = document.getElementById("shoutbox_data").style.height;
  16.     }
  17. }
  18.  
  19. function toggleSBDisplay() {
  20.     if(document.getElementById("shoutbox_e").style.display == "none") {
  21.         SBRuleNonButtonClick = 1;
  22.         SBDisplay();
  23.     } else {
  24.         document.getElementById("AcceptButton").parentNode.style.display = "none";
  25.     }
  26. }
  27.  
  28. function isIE11() {
  29.     if (navigator.userAgent.indexOf('MSIE') !== -1 || navigator.appVersion.indexOf('Trident/') > 0) {
  30.         if (!(window.ActiveXObject) && "ActiveXObject") {
  31.             return true;
  32.         } else {return false;}
  33.     } else {return false;}
  34. }
  35.  
  36. function getCookieSBDisplay() {
  37.     var name = "WeepForumShoutboxDisplay=";
  38.     var cookArray = document.cookie.split(';');
  39.     for(var i=0; i<cookArray.length; i++) {
  40.         var cook = cookArray[i];
  41.         while (cook.charAt(0)==' '){
  42.             cook = cook.substring(1);
  43.         }
  44.         if (cook.indexOf(name) != -1) {
  45.             return cook.substring(name.length,cook.length);
  46.         }
  47.     }
  48.     return false;
  49. }
  50.  
  51. function setCookieSBDisplay(cookValue) {
  52.     var name = "WeepForumShoutboxDisplay=";
  53.     var cookArray = document.cookie.split(';');
  54.     for(var i=0; i<cookArray.length; i++) {
  55.         var cook = cookArray[i];
  56.         while (cook.charAt(0)==' '){
  57.             cook = cook.substring(1);
  58.         }
  59.         if (cook.indexOf(name) != -1) {
  60.             var toReplace = name + cook.substring(name.length,cook.length);
  61.             var replacement = name + cookValue;
  62.             document.cookie = document.cookie.replace(toReplace, replacement);
  63.             return true;
  64.         }
  65.     }
  66.     document.cookie += '; WeepForumShoutboxDisplay='+cookValue+';';
  67.     return false;
  68. }
  69.  
  70. function LoadSBDisplay() {
  71.  
  72.     if(typeof(Storage) !== "undefined") {
  73.         if(!localStorage.getItem("PrefDisplaySB")) {
  74.             localStorage.setItem("PrefDisplaySB", 0);
  75.             var SBDisplayPref = 0;
  76.         } else {
  77.             var SBDisplayPref = localStorage.getItem("PrefDisplaySB");
  78.         }
  79.     } else {
  80.         if(!getCookieSBDisplay()) {
  81.             setCookieSBDisplay(0);
  82.             var SBDisplayPref = 0;
  83.         } else {
  84.             var SBDisplayPref = getCookieSBDisplay();
  85.         }
  86.     }
  87.    
  88.     return parseInt(SBDisplayPref);
  89. }
  90.  
  91. function SaveSBDisplay(prefValue) {
  92.     if(typeof(Storage) !== "undefined") {
  93.         localStorage.setItem("PrefDisplaySB", prefValue);
  94.     } else {
  95.         setCookieSBDisplay(prefValue);
  96.     }
  97.    
  98.     return true;
  99. }
  100.  
  101. function SBDisplay() {
  102.     if(document.getElementById("shoutbox_e").style.display == "none" && SBRuleNonButtonClick == 0) {return "lolnope";}
  103.    
  104.     if(!SBTimeRemaining && !timerOn) {
  105.         SaveSBDisplay(1);
  106.     }
  107.    
  108.     SBRuleNonButtonClick = 0;
  109.     if (typeof(SBRuleResizing) != "undefined") { clearInterval(SBRuleResizing); }
  110.     var SBDisplayPref = LoadSBDisplay();
  111.     var SBRuleResizing = setInterval(function(){resizeSBRule();}, 250);
  112.    
  113.     if(SBDisplayPref){
  114.         document.getElementById("AcceptButton").innerHTML = "Accept the rules";
  115.         clearInterval(SBRuleResizing);
  116.         document.getElementById("AcceptButton").parentNode.style.display = "none";
  117.     } else if (!SBDisplayPref && SBTimeRemaining == 30){
  118.         SBRuleTimer();
  119.         document.getElementById("AcceptButton").parentNode.style.display = "table";
  120.     } else if (!SBDisplayPref) {
  121.         document.getElementById("AcceptButton").parentNode.style.display = "table";
  122.     }
  123. }
  124.  
  125. function ToggleSBRules() {
  126.     var height = document.getElementById("shoutbox_e").clientHeight;
  127.     document.getElementById("AcceptButton").parentNode.style.height = height;
  128. }
  129.  
  130. function SBRuleTimer() {
  131.     if(typeof(SBtimer) == "undefined" && timerOn == 0 && SBTimeRemaining > 0) {
  132.         SBTimeRemaining = 30;
  133.         var SBtimer = setTimeout(function(){SBRuleTimer()}, 1000);
  134.         timerOn = 1;
  135.     } else if(SBTimeRemaining > 0 && timerOn == 1) {
  136.         SBTimeRemaining--;
  137.         document.getElementById("AcceptButton").innerHTML = "Accept the rules ("+ SBTimeRemaining +")";
  138.         SBtimer = setTimeout(function(){SBRuleTimer()}, 1000);
  139.         timerOn = 1;
  140.     } else if (SBTimeRemaining < 0) {
  141.         SBTimeRemaining = 30;
  142.         SBtimer = setTimeout(function(){SBRuleTimer()}, 1000);
  143.         timerOn = 1;
  144.     }
  145.    
  146.     if(SBTimeRemaining == 0 && timerOn == 1) {
  147.         document.getElementById("AcceptButton").innerHTML = "Accept the rules";
  148.         timerOn = 0;
  149.     }
  150.    
  151.     return false;
  152. }
  153.  
  154. function resizeSBRule() {
  155.     var SBRuleBox = document.getElementById("AcceptButton").parentNode;
  156.     SBRuleBox.style.width = document.getElementById("shoutbox_e").clientWidth + "px";
  157.     SBRuleBox.style.height = document.getElementById("shoutbox_e").clientHeight + "px";
  158.     var ShoutingBox = document.getElementById("shoutbox_e").getElementsByTagName("tr");
  159.     var ShoutingBoxtoComp = ShoutingBox[1].getElementsByTagName("td")[0]
  160.     var excessHeight = 2*(parseInt(window.getComputedStyle(ShoutingBoxtoComp, null).getPropertyValue("padding-top")) + parseInt(window.getComputedStyle(ShoutingBoxtoComp, null).getPropertyValue("border-top-width")) + parseInt(window.getComputedStyle(SBRuleBox, null).getPropertyValue("padding-top")) + parseInt(window.getComputedStyle(SBRuleBox, null).getPropertyValue("border-top-width")));
  161.     var HToGo = SBRuleBox.clientHeight - ShoutingBox[0].clientHeight - excessHeight + "px";
  162.     if(isIE11()){HToGo = parseInt(HToGo) - 1 + "px";}
  163.     document.getElementById("shoutbox_data").style.height = HToGo;
  164. }
  165.  
  166. function showSBRules() {
  167.    
  168.     if(LoadSBDisplay()) {
  169.         SaveSBDisplay(0);
  170.         SBTimeRemaining = 0;
  171.         timerOn = 1;
  172.         SBDisplay();
  173.         timerOn = 0;
  174.     }
  175. }
  176.  
  177. var FullShoutbox = document.getElementById("shoutbox_e");
  178. var coverDiv = document.createElement("div");
  179. SHeight = document.getElementById("shoutbox_e").clientHeight + "px";
  180. SWidth = document.getElementById("shoutbox_e").clientWidth + "px";
  181. /*
  182. ##########################
  183. RULES
  184. ##########################
  185. */
  186. FullShoutbox.parentNode.insertBefore(coverDiv, FullShoutbox);
  187. coverDiv.outerHTML = '<div style="color: #777; position: absolute; z-index: 10; height: '+SHeight+'; width: '+SWidth+'; background: #181818" class="trow1"><div style="margin-bottom: 20px; display: table; margin-left: auto; margin-right: auto; margin-top: 10px">'+
  188. 'This is an english chat. speak english<br/>'+
  189. 'This is not for WeepCraft help. use the help section<br/>'+
  190. 'This is not for advertisement. if you have a grief request post a thread or add it to the server list<br/>'+
  191. 'No Spam \/ Flame \/ Racism<br/>'+
  192. 'No shouting gross pictures or websites nor screamer sites.<br/>'+
  193. 'This is a chat for users to interact <strong>not</strong> for support questions<br/>'+
  194. 'Breaking any of the above may result in a ban from the shoutbox without warning.<br/>'+
  195. '</div>'+
  196. '<a class="button" id="AcceptButton" onclick="SBDisplay();" style="display:table; margin: 0 auto; margin-bottom: 10px">Accept the rules (30)</a></div>';
  197. var SBTimeRemaining = 30;
  198. var timerOn = 0;
  199. var SBContractSize = document.getElementById("shoutbox_data").style.height;
  200. var SBRuleNonButtonClick = 0;
  201. document.getElementById("datToggle").setAttribute("onclick", "toggleSB(); ToggleSBRules();");
  202. document.getElementById("shoutbox_img").setAttribute("onclick", "toggleSBDisplay();");
  203. document.getElementById("shout_data").setAttribute("autocomplete", "off");
  204. SBDisplay();
  205.  
  206. //I really hope fly-senpai will notice me
Advertisement
Add Comment
Please, Sign In to add comment