Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //////////////
- // CMod //
- //////////////
- var userID;
- var ky;
- $(document).ready(
- function(){
- var start = performance.now();
- userID = proboards.data("user").id;
- GetUserKey();
- //Changing links to the board
- $("#logo").prop("href", "http://genericdiscussion.freeforums.net/board/1/general-board");
- document.getElementById("navigation-menu").childNodes[1].childNodes[1].childNodes[1].href = "http://genericdiscussion.freeforums.net/board/1/general-board";
- EnabledSettings();
- //Adding events upon load and page changing
- try {
- colonelGift();
- setTimeout(function() {
- var start = performance.now();
- colonelGift();
- PlayerUnfuck();
- TwitchHandling();
- //if(ky.holiday && ky.enabled) Hattify();
- var end = performance.now();
- var time = end - start;
- console.log('CMod delayed function execution time: ' + Math.round(time * 100) / 100 + " miliseconds");
- setInterval(function(){
- PlayerUnfuck();
- var start = performance.now();
- TwitchHandling();
- colonelGift();
- var end = performance.now();
- var time = end - start;
- console.log('CMod interval function execution time: ' + Math.round(time * 100) / 100 + " miliseconds");
- }, 2000);
- }, 1500);
- var pageButtons = document.querySelectorAll(".ui-pagination li");
- for (i = 0; i < pageButtons.length; ++i) {
- pageButtons[i].childNodes[0].addEventListener("click", function() {
- $("html, body").animate({ scrollTop: $("#navigation-menu").offset().top }, 500)
- setTimeout(function() {
- PlayerUnfuck();
- var start = performance.now();
- TwitchHandling();
- BlockThreadClass();
- if(ky.blank && ky.enabled) stopBlankFuckers();
- if(ky.username && ky.enabled) DisplayUsernames();
- //if(ky.holiday && ky.enabled) Hattify();
- var end = performance.now();
- var time = end - start;
- console.log('CMod onclick delayed execution time: ' + Math.round(time * 100) / 100 + " miliseconds");
- }, 1500);
- });
- }
- BlockThreadClass()
- }catch(err){console.log(err);}
- if(ky.enabled == 0){return;}
- //Adding panel HTML
- var htmlinsert = '<div id="cmod-wrapper"> <h1>CMod</h1> <div id="cmod-post-height-wrapper"><span id="cmod-post-height-label">Post height limit in pixels (0=no limit): </span> <input id="cmod-post-limit" type="number" value="0" min="0" max="4000" maxlength="4"> </div><div id="cmod-sig-height-wrapper"><span id="cmod-sig-height-label">Signature height limit in pixels (0=no limit): </span> <input id="cmod-sig-limit" type="number" value="0" min="0" max="1000" maxlength="4" size="4"> </div><div id="cmod-bpost-wrapper"><span id="cmod-bpost-label">Blocked post handling:</span> </br> <div style="text-align: left;"> <input type="radio" name="cmod-bpost" id="cmod-bpost-0" value="0" checked> Default </br> <input type="radio" name="cmod-bpost" id="cmod-bpost-1" value="1"> Thin line </br> <input type="radio" name="cmod-bpost" id="cmod-bpost-2" value="2"> Thin line - click to reveal </br> <input type="radio" name="cmod-bpost" id="cmod-bpost-3" value="3"> Completely hide </br> </div></div><div id="cmod-bthread-wrapper"><span id="cmod-bthread-label">Blocked thread handling:</span> </br> <div style="text-align: left"> <input type="radio" name="cmod-bthread" id="cmod-bthread-0" value="0" checked> Default </br> <input type="radio" name="cmod-bthread" id="cmod-bthread-1" value="1"> Thin line </br> <input type="radio" name="cmod-bthread" id="cmod-bthread-2" value="2"> Completely hide </br> </div></br><a target="_blank" href="http://genericdiscussion.freeforums.net/thread/54455/">If you\'re having issues with thread blocking, this might help</a></div><div id="cmod-color-wrapper">Blocked line color: <input type="color" id="cmod-color" value="#8B0000"> </div><div id="cmod-username-wrapper" style="text-align: left;"> <input id="cmod-username" type="checkbox" value="0" min="0" max="4000" maxlength="4"><span id="cmod-username-label">Show usernames under display names </span> </div><div id="cmod-blank-wrapper" style="text-align: left;"> <input id="cmod-blank" type="checkbox" value="0" min="0" max="4000" maxlength="4"><span id="cmod-username-label">Replace blank names with usernames </span> </div><div id="cmod-holiday-wrapper" style="text-align: left;"><span id="cmod-holiday-label">Are you triggered by holiday stuff or use a toaster?</span></br> <div><input id="cmod-holiday" type="checkbox" value="0" min="0" max="4000" maxlength="4"><span id="cmod-username-label">Show Holiday Stuff?</span></div></div><div id="cmod-twitch-wrapper"><span id="cmod-twitch-label">Twitch handling:</span> </br> <div style="text-align: left;"> <input type="radio" name="cmod-twitch" id="cmod-twitch-0" value="0"> Keep embeds and autoplay </br> <input type="radio" name="cmod-twitch" id="cmod-twitch-1" value="1" checked> Keep embeds but turn off autoplay</br> <input type="radio" name="cmod-twitch" id="cmod-twitch-2" value="2"> Turn Twitch embeds into links </br> </div></div><div style="clear: both;"></div></br> <input type="button" id="cmod-close" value="Close" class="cmodbutton" onclick="PanelToggle()"> <input type="button" id="cmod-save" value="Save" class="cmodbutton" onclick="Save();"> <input type="button" class="cmodbutton" id="cmod-reset" value="Reset" onclick="LoadKey()"> <div style="clear: both;"></div><div style="text-align: center;"> </br><a target="_blank" href="http://i.subarashii.me/93f43">Like, Favorite and Subscribe for more forum ruining</a></br> </br> </br> </div></div>';
- document.querySelector("#banner-container").innerHTML+=htmlinsert;
- //Adding panel CSS
- var css_popup = "#cmod-bpost-wrapper,#cmod-bthread-wrapper,#cmod-color-wrapper,#cmod-blank-wrapper,#cmod-holiday-label,#cmod-holiday-wrapper,#cmod-post-height-wrapper,#cmod-sig-height-wrapper,#cmod-twitch-wrapper,#cmod-username-wrapper,h1{margin-bottom:15px}h1{font-size:30px}#cmod-wrapper{z-index:2000;position:fixed;display:none;bottom:0;left:0;box-sizing:border-box;width:500px;height:750px;padding-top:30px;padding-left:30px;padding-right:30px;border-top:2px solid #000;border-right:2px solid #000;background-color:#575757;color:#fff;text-align:center;overflow-y:auto}#cmod-post-limit,#cmod-sig-limit{width:50px}.cmodbutton{color:#fff!important;float:right;margin-left:10px;width:55px;height:25px;background-color:#575757!important;border-color:#fff!important;background-image:none!important}.cmodbutton:hover{color:#fff!important;background-color:#5F5F5F!important}.cmodbutton:active{color:#fff!important;background-color:#1D1D1D!important}#cmod-color{width:120px}a{color:#add8e6}";
- var css_style = document.createElement("style");
- css_style.appendChild(document.createTextNode(css_popup));
- document.querySelector("head").appendChild(css_style);
- //disabling save button if user logged out
- if(userID == 0){
- document.getElementById('cmod-save').disabled = true;
- document.getElementById('cmod-save').style.visibility = "hidden";
- }
- //Adding CMod Panel toggle button
- var navbar = document.querySelector("ul[role=navigation]");
- var navbarItem = document.createElement('li');
- var panelButton = document.createElement('a');
- panelButton.appendChild(document.createTextNode("Show CMod Panel"));
- panelButton.setAttribute("id", "panelButton");
- panelButton.setAttribute("onclick", "PanelToggle()");
- navbarItem.appendChild(panelButton);
- navbar.appendChild(navbarItem);
- LoadKey();
- //Applying the CSS options
- var css_insert = "";
- if (ky.plimit > 0) css_insert += "article .message, .content .message{padding-right:5px; overflow-y: auto !important; max-height:" + ky.plimit + "px;}";
- if (ky.slimit > 0) css_insert += ".signature{overflow-y: auto; max-height: " + ky.slimit + "px;}";
- switch (ky.bpost) {
- case 0:
- break;
- case 1:
- css_insert += ".blocked a, .blocked a:hover, .blocked a:active{display: none;}.blocked .message{display: none !important;}.blocked{padding: 0px !important; height: 10px; font-size: 1px; background-color:" + ky.clr + ";}";
- break;
- case 2:
- css_insert += ".blocked a, .blocked a:hover, .blocked a:active{font-size: 0px !important; width: 100%; height: 10px !important; min-height: 10px !important; box-sizing: border-box; border-top-left-radius: 0px;border-top-right-radius: 0px; border-radius: 0px 0px 0px 0px; background-image: none !important; margin: 0px !important; padding: 0px !important; background-color:" + ky.clr + "!important;}.blocked .message{display: none !important;}.blocked{padding: 0px !important; height: 10px; font-size: 1px; background-color:" + ky.clr + ";}";
- break;
- case 3:
- css_insert += ".blocked{display: none !important;}";
- break;
- }
- switch (ky.bthread) {
- case 0:
- break;
- case 1:
- css_insert += ".blocked-thread{font-size: 0px !important; width: 100%; height: 10px !important; min-height: 10px !important; box-sizing: border-box; border-top-left-radius: 0px;border-top-right-radius: 0px; border-radius: 0px 0px 0px 0px; background-image: none !important; margin: 0px !important; padding: 0px !important; background-color:" + ky.clr + "!important;}";
- break;
- case 2:
- css_insert += ".blocked-thread{display: none;}";
- break;
- }
- css_insert += "";
- var css_options_style = document.createElement("style");
- css_options_style.appendChild(document.createTextNode(css_insert));
- document.querySelector("head").appendChild(css_options_style);
- if(ky.username) DisplayUsernames();
- if(ky.blank) stopBlankFuckers();
- var end = performance.now();
- var time = end - start;
- console.log('CMod execution time: ' + Math.round(time * 100) / 100 + " miliseconds");
- }
- );
- function colonelGift(){
- var miniprofiles = document.querySelectorAll(".mini-profile");
- var match = "@colonelj";
- if(miniprofiles.length < 1) return;
- for (i=0; i<miniprofiles.length; i++){
- var mp = miniprofiles[i];
- var un = "";
- try {
- un = mp.querySelector("a").getAttribute("title");
- }catch(err){}
- if (un == match){
- mp = mp.parentNode.parentNode.parentNode.parentNode.parentNode;
- mp.style.backgroundImage = "url(http://i.imgur.com/gEJkDqv.png)";
- }
- }
- }
- //Toggle panel visibility
- function PanelToggle() {
- var pop = document.getElementById("cmod-wrapper");
- if (pop.style.display == "none" || pop.style.display == "") {
- document.getElementById("panelButton").childNodes[0].nodeValue = "Hide CMod Panel";
- pop.style.display = "block";
- } else {
- document.getElementById("panelButton").childNodes[0].nodeValue = "Show CMod Panel";
- pop.style.display = "none";
- }
- }
- function stopBlankFuckers(){
- for (x = 0; x < document.getElementsByClassName("user-link").length; x++){
- var y = document.getElementsByClassName("user-link")[x].innerHTML.trim();
- y = removeZWS(y);
- if(y == ""){
- document.getElementsByClassName("user-link")[x].innerHTML = document.getElementsByClassName("user-link")[x].title;
- }
- }
- for (x = 0; x < $('.user-link span').size(); x++){
- var y = $('.user-link span')[x].innerHTML.trim();
- y = removeZWS(y);
- if(y == ""){
- $('.user-link span')[x].innerHTML = $('.user-link span')[x].parentNode.title;
- }
- }
- }
- //Saves CMod panel options to the key and pushes key to PB
- function Save() {
- PanelToggle();
- ky.plimit = document.getElementById("cmod-post-limit").value;
- ky.slimit = document.getElementById("cmod-sig-limit").value;
- if (document.getElementById("cmod-bpost-0").checked == true) ky.bpost = 0;
- if (document.getElementById("cmod-bpost-1").checked == true) ky.bpost = 1;
- if (document.getElementById("cmod-bpost-2").checked == true) ky.bpost = 2;
- if (document.getElementById("cmod-bpost-3").checked == true) ky.bpost = 3;
- if (document.getElementById("cmod-bthread-0").checked == true) ky.bthread = 0;
- if (document.getElementById("cmod-bthread-1").checked == true) ky.bthread = 1;
- if (document.getElementById("cmod-bthread-2").checked == true) ky.bthread = 2;
- ky.clr = document.getElementById("cmod-color").value;
- if (document.getElementById("cmod-username").checked == true){
- ky.username = 1;
- }else{
- ky.username = 0;
- }
- if (document.getElementById("cmod-blank").checked == true){
- ky.blank = 1;
- }else{
- ky.blank = 0;
- }
- if (document.getElementById("cmod-holiday").checked == true){
- ky.holiday = 1;
- }else{
- ky.holiday = 0;
- }
- if (document.getElementById("cmod-twitch-0").checked == true) ky.twitch = 0;
- if (document.getElementById("cmod-twitch-1").checked == true) ky.twitch = 1;
- if (document.getElementById("cmod-twitch-2").checked == true) ky.twitch = 2;
- pb.plugin.key('cmod_options').set({
- value: ky
- });
- }
- //Loads key values into the CMod Panel
- function LoadKey() {
- document.getElementById("cmod-post-limit").value = ky.plimit;
- document.getElementById("cmod-sig-limit").value = ky.slimit;
- switch (ky.bpost) {
- case 0:
- document.getElementById("cmod-bpost-0").checked = true;
- break;
- case 1:
- document.getElementById("cmod-bpost-1").checked = true;
- break;
- case 2:
- document.getElementById("cmod-bpost-2").checked = true;
- break;
- case 3:
- document.getElementById("cmod-bpost-3").checked = true;
- break;
- }
- switch (ky.bthread) {
- case 0:
- document.getElementById("cmod-bthread-0").checked = true;
- break;
- case 1:
- document.getElementById("cmod-bthread-1").checked = true;
- break;
- case 2:
- document.getElementById("cmod-bthread-2").checked = true;
- break;
- }
- document.getElementById("cmod-color").value = ky.clr;
- if(ky.username == 1){
- document.getElementById("cmod-username").checked = true;
- }
- if(ky.blank == 1){
- document.getElementById("cmod-blank").checked = true;
- }
- if(ky.holiday == 1){
- document.getElementById("cmod-holiday").checked = true;
- }
- switch (ky.twitch) {
- case 0:
- document.getElementById("cmod-twitch-0").checked = true;
- break;
- case 1:
- document.getElementById("cmod-twitch-1").checked = true;
- break;
- case 2:
- document.getElementById("cmod-twitch-2").checked = true;
- break;
- }
- }
- //Adds class to the blocked threads added by another plugin.
- function BlockThreadClass() {
- try {
- var tdArr = document.getElementsByClassName("list")[0].getElementsByTagName("td");
- for (i = 0; i < tdArr.length; ++i) {
- if (tdArr[i].getAttribute("colspan") == 7) {
- tdArr[i].className = "blocked-thread";
- }
- }
- }catch(err){console.log(err);}
- }
- //Gets user key and fills with default values if any are missing. Sets a default key of no user is logged in.
- function GetUserKey(){
- if (userID != 0) {
- ky = pb.plugin.key('cmod_options').get();
- var pass = 1;
- if (ky == undefined) {
- pass = 0
- ky = {
- "plimit": 950,
- "slimit": 400,
- "bpost": 0,
- "bthread": 0,
- "clr": "#8B0000",
- "blank":0,
- "username": 0,
- "enabled": 1,
- "holiday": 1,
- "twitch": 1
- };
- }else{
- if(ky.plimit == undefined){
- pass = 0;
- ky.plimit = 950;
- }
- if(ky.slimit == undefined){
- pass = 0;
- ky.slimit = 400;
- }
- if(ky.bpost == undefined){
- pass = 0;
- ky.bpost = 0;
- }
- if(ky.blank == undefined){
- pass = 0;
- ky.blank = 0;
- }
- if(ky.bthread == undefined){
- pass = 0;
- ky.bthread = 0;
- }
- if(ky.clr == undefined){
- pass = 0;
- ky.clr = "#8B0000";
- }
- if(ky.username == undefined){
- pass = 0;
- ky.username = 0;
- }
- if(ky.enabled == undefined){
- pass = 0;
- ky.enabled = 1;
- }
- if(ky.holiday == undefined){
- pass = 0;
- ky.holiday = 1;
- }
- if(ky.twitch == undefined){
- pass = 0;
- ky.twitch = 1;
- }
- }
- if(pass == 0){
- pb.plugin.key('cmod_options').set({
- value: ky
- })
- ky = pb.plugin.key('cmod_options').get();
- }
- } else {
- ky = {
- "plimit": 950,
- "slimit": 400,
- "bpost": 0,
- "bthread": 0,
- "clr": "#8B0000",
- "blank":0,
- "username": 0,
- "enabled": 1,
- "holiday": 1,
- "twitch": 1
- };
- }
- }
- //Checks if on settings page, and adds Enable button if yes.
- function EnabledSettings(){
- var metas = document.getElementsByTagName('meta');
- var settingsPage = 0;
- for (i=0; i<metas.length; i++) {
- if (metas[i].getAttribute("property") == "og:title") {
- if (metas[i].getAttribute("content") == "Edit Profile | General Discussion"){
- settingsPage = 1;
- }
- }
- }
- if(settingsPage == 1){
- var settingForm = document.querySelector(".form_user_edit_settings");
- var enableBtn = document.createElement('input');
- enableBtn.setAttribute("type", "button");
- enableBtn.setAttribute("id", "cmod-enable");
- if(ky.enabled == 1){
- enableBtn.setAttribute("value", "Disable CMod (refresh to apply)");
- enableBtn.addEventListener("click", function(){
- ky.enabled = 0;
- pb.plugin.key('cmod_options').set({
- value: ky
- });
- });
- }else{
- enableBtn.setAttribute("value", "Enable CMod (refresh to apply)");
- enableBtn.addEventListener("click", function(){
- ky.enabled = 1;
- pb.plugin.key('cmod_options').set({
- value: ky
- });
- });
- }
- settingForm.appendChild(enableBtn);
- }
- }
- function DisplayUsernames(){
- var miniprofiles = document.querySelectorAll(".mini-profile");
- if(miniprofiles.length < 1) return;
- for (i=0; i<miniprofiles.length; i++){
- var mp = miniprofiles[i];
- if(mp.className.indexOf("un-added") > -1) continue;
- var un = "";
- try {un = mp.querySelector("a").getAttribute("title");}catch(err){}
- mp.insertBefore(document.createElement("div"), mp.children[1]);
- mp.insertBefore(document.createTextNode("\n" + un), mp.children[2]);
- mp.className = mp.className + " un-added";
- }
- }
- function PlayerUnfuck(){
- var players = document.querySelectorAll(".imgur-embed");
- for (i=0; i<players.length; i++){
- if(players[i].hasAttribute("controls")) continue;
- players[i].setAttribute("controls","");
- }
- var eww = document.querySelectorAll(".embed-video-overlay");
- for (i=0; i<eww.length; i++){
- eww[i].parentElement.removeChild(eww[i]);
- }
- }
- function Hattify(){
- var miniprofiles = document.querySelectorAll(".mini-profile");
- if(miniprofiles.length < 1) return;
- for (i=0; i<miniprofiles.length; i++){
- var mp = miniprofiles[i];
- var mpheight = $(mp).height();
- var topoff = (-1 * $(mp).height()) - 50;
- if(mp.className.indexOf("hat-added") > -1) continue;
- var hat = document.createElement("img");
- hat.src = "http://i.imgur.com/9j9D1FH.png";
- hat.style.position = "relative";
- hat.style.top = topoff.toString() + "px";
- hat.style.left = "-58px";
- hat.style.display = "inline-block";
- hat.style.zIndex = "200";
- var mpheight = $(mp).height();
- try{
- if(mp.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.childNodes[3].className.indexOf("blocked") > -1){
- continue;
- }
- }catch(err){}
- mp.appendChild(hat);
- mp.className = mp.className + " hat-added";
- mp.style.height = mpheight.toString() + "px";
- mp.children[0].style.position = "relative";
- mp.children[0].style.zIndex = "201";
- mp.style.overflow = "visible";
- mp = mp.parentNode;
- mp.style.overflow = "visible";
- mp = mp.parentNode;
- mp.style.overflow = "visible";
- mp = mp.parentNode;
- mp.style.overflow = "visible";
- mp = mp.parentNode;
- mp.style.overflow = "visible";
- mp = mp.parentNode;
- mp.style.overflow = "visible";
- mp = mp.parentNode;
- mp.style.overflow = "visible";
- mp = mp.parentNode;
- mp.style.overflow = "visible";
- mp = mp.parentNode;
- mp.style.overflow = "visible";
- mp = mp.parentNode;
- mp.style.overflow = "visible";
- mp = mp.parentNode;
- mp.style.overflow = "visible";
- mp = mp.parentNode;
- mp.style.overflow = "visible";
- mp = mp.parentNode;
- mp.style.overflow = "visible";
- }
- }
- function removeZWS(input){
- return input.replace(/\u200B/g,'');
- }
- function TwitchHandling(){
- if(ky.twitch == "0") return;
- var iframes = document.getElementsByTagName("iframe");
- for (i = 0; i < iframes.length; ++i) {
- if(iframes[i].getAttribute("src") == null) continue;
- if(iframes[i].getAttribute("src").indexOf("http://www.twitch.tv") < 0) continue;
- var link = iframes[i].getAttribute("src").substring(0, iframes[i].getAttribute("src").length - 6);
- var channel = link.substring(21);
- var replacement;
- if(ky.twitch == "2"){
- replacement = document.createElement("a");
- replacement.appendChild(document.createTextNode(link));
- replacement.href = link;
- }
- if(ky.twitch == "1"){
- replacement = document.createElement("object");
- var objectHTML = '<param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><param name="allowNetworking" value="all"/><param name="movie" value="http://www.twitch.tv/widgets/live_embed_player.swf"/><param name="flashvars" value="hostname=www.twitch.tv&channel=' + channel + '&auto_play=false&start_volume=25"/>';
- replacement.setAttribute("style", "opacity:1;");
- replacement.setAttribute("type", "application/x-shockwave-flash");
- replacement.setAttribute("height", "300");
- replacement.setAttribute("width", "400");
- replacement.setAttribute("data", "http://www.twitch.tv/widgets/live_embed_player.swf");
- replacement.setAttribute("bgcolor", "#000000");
- replacement.innerHTML = objectHTML;
- }
- iframes[i].parentNode.replaceChild(replacement, iframes[i]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement