Advertisement
Guest User

Lichess Lounger: a poorly implemented attempt to chat

a guest
Jul 30th, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Lichess Lounger
  3. // @namespace    https://lichess.org/@/Hedgehogs4Me
  4. // @version      0.1
  5. // @description  Include chat in Lichess TV
  6. // @author       Hedgehogs4Me
  7. // @include      https://*lichess.org/*
  8. // @grant        none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12.     'use strict';
  13.  
  14.     function LoungeBug(message) {
  15.         var userWarning = document.createElement("P");
  16.         userWarning.appendChild(document.createTextNode("LOUNGER ERROR:" + message));
  17.         userWarning.style.color="red";
  18.         document.body.appendChild(userWarning);
  19.     }
  20.  
  21.     var failed = false;
  22.     var boardArray = document.getElementsByClassName("cg-board-wrap");
  23.  
  24.     var h = 512; //I've left the former definitions in for archival/curiousity purposes, but the reason this really must be 512 is that there isn't any point in it being anything else.
  25.     // You see, not only does resizing happen *after* the page has loaded, but also, if any board resizing has been done, the board suddenly takes precedence over the chat in small
  26.     // windows! This could *maybe* be worked around by making it a large iframe and covering it up, but then I would have to make the entire thing bigger, and figure out how everything
  27.     // fits together, and then... well, look, I'm not doing it. I made this because I'm so lazy I want to sit back and watch Lichess TV all day and not even have to switch pages to
  28.     // comment, so clearly I'm not going to put in that work. If someone else wants to do it, though, feel free, and I'd love to see your results!
  29.  
  30.     if(window.self === window.top) {
  31.         if(document.URL.search(/https:\/\/.+lichess\.org\/tv.+/) != -1) {
  32.             if(boardArray.length===0){
  33.                 failed = true;
  34.                 LoungeBug("Thibault probably changed the board wrapper name. What a bastard.");
  35.             }
  36.             var sidebarArray = document.getElementsByClassName("lichess_ground");
  37.             if(boardArray.length===0){
  38.                 failed = true;
  39.                 LoungeBug("Thibault probably changed the move list wrapper name. God damn it.");
  40.             }
  41.             var analysisArray = document.getElementsByClassName("analysis");
  42.             if(analysisArray.length===0){
  43.                 failed = true;
  44.                 LoungeBug("Thibault probably changed the analysis button class name, and I am not happy about that.");
  45.             }
  46.             if(document.getElementById("friend_box")===null){
  47.                 failed = true;
  48.                 LoungeBug("thibault probably changed the friend box class name, which would've made this look pretty ugly.");
  49.             }
  50.             if(failed===true){
  51.                 LoungeBug("I mean, thibault is cool, but you should turn off this userscript.");
  52.                 return;
  53.             }
  54.  
  55.             //var h = (boardArray[0].style.height!=="")?parseInt(boardArray[0].style.height):512;
  56.             sidebarArray[0].style.height=(h+98)+"px"; //98 px is how big the crosstable is and I want to use as much space as I can
  57.             var chatFrame = document.createElement("IFRAME");
  58.             chatFrame.style.overflow="hidden";
  59.             chatFrame.style.border="none";
  60.             // chatFrame.style.height="100%";
  61.             // chatFrame.style.height=(h+98-370)+"px"; //god damn it all, none of this is working
  62.             chatFrame.style.setProperty("height", (h+98-370)+"px", "important");
  63.             chatFrame.scrolling="no";
  64.             chatFrame.id="chat_page";
  65.             chatFrame.src=analysisArray[0].href.slice(0,31)+"#chat";
  66.             sidebarArray[0].appendChild(chatFrame);
  67.             //setTimeout(function(){ sidebarArray[0].appendChild(chatFrame); }, 1000);
  68.             //setTimeout(function(){ chatFrame.scrollLeft = 0; }, 2000); // Well, I tried. Didn't think it'd work.
  69.         }
  70.     } else {
  71.         if(window.top.location.href.search(/https:\/\/.+lichess\.org\/tv.+/) != -1) {
  72.             //var h = (boardArray[0].style.height!=="")?parseInt(boardArray[0].style.height):512;
  73.             document.getElementById("friend_box").style.display="none";
  74.             var chat = document.getElementById("chat");
  75.             chat.style.setProperty("width", "242px", "important");
  76.             chat.style.setProperty("height", (h+98-370)+"px", "important"); //board height, plus under-thingy height, minus height of the stuff above the chat. Trust me on this one.
  77.             boardArray[0].style.visibility="hidden"; //This bit scares me.
  78.             //setTimeout(function(){ chat.scrollIntoView(); }, 1000);
  79.         }
  80.     }
  81. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement