Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Lichess Lounger
- // @namespace https://lichess.org/@/Hedgehogs4Me
- // @version 0.1
- // @description Include chat in Lichess TV
- // @author Hedgehogs4Me
- // @include https://*lichess.org/*
- // @grant none
- // ==/UserScript==
- (function() {
- 'use strict';
- function LoungeBug(message) {
- var userWarning = document.createElement("P");
- userWarning.appendChild(document.createTextNode("LOUNGER ERROR:" + message));
- userWarning.style.color="red";
- document.body.appendChild(userWarning);
- }
- var failed = false;
- var boardArray = document.getElementsByClassName("cg-board-wrap");
- 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.
- // 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
- // 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
- // 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
- // 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!
- if(window.self === window.top) {
- if(document.URL.search(/https:\/\/.+lichess\.org\/tv.+/) != -1) {
- if(boardArray.length===0){
- failed = true;
- LoungeBug("Thibault probably changed the board wrapper name. What a bastard.");
- }
- var sidebarArray = document.getElementsByClassName("lichess_ground");
- if(boardArray.length===0){
- failed = true;
- LoungeBug("Thibault probably changed the move list wrapper name. God damn it.");
- }
- var analysisArray = document.getElementsByClassName("analysis");
- if(analysisArray.length===0){
- failed = true;
- LoungeBug("Thibault probably changed the analysis button class name, and I am not happy about that.");
- }
- if(document.getElementById("friend_box")===null){
- failed = true;
- LoungeBug("thibault probably changed the friend box class name, which would've made this look pretty ugly.");
- }
- if(failed===true){
- LoungeBug("I mean, thibault is cool, but you should turn off this userscript.");
- return;
- }
- //var h = (boardArray[0].style.height!=="")?parseInt(boardArray[0].style.height):512;
- 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
- var chatFrame = document.createElement("IFRAME");
- chatFrame.style.overflow="hidden";
- chatFrame.style.border="none";
- // chatFrame.style.height="100%";
- // chatFrame.style.height=(h+98-370)+"px"; //god damn it all, none of this is working
- chatFrame.style.setProperty("height", (h+98-370)+"px", "important");
- chatFrame.scrolling="no";
- chatFrame.id="chat_page";
- chatFrame.src=analysisArray[0].href.slice(0,31)+"#chat";
- sidebarArray[0].appendChild(chatFrame);
- //setTimeout(function(){ sidebarArray[0].appendChild(chatFrame); }, 1000);
- //setTimeout(function(){ chatFrame.scrollLeft = 0; }, 2000); // Well, I tried. Didn't think it'd work.
- }
- } else {
- if(window.top.location.href.search(/https:\/\/.+lichess\.org\/tv.+/) != -1) {
- //var h = (boardArray[0].style.height!=="")?parseInt(boardArray[0].style.height):512;
- document.getElementById("friend_box").style.display="none";
- var chat = document.getElementById("chat");
- chat.style.setProperty("width", "242px", "important");
- 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.
- boardArray[0].style.visibility="hidden"; //This bit scares me.
- //setTimeout(function(){ chat.scrollIntoView(); }, 1000);
- }
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement