CGChat

The CodinGame web-chat without CodinGame.

当前为 2020-08-29 提交的版本,查看 最新版本

// ==UserScript==
// @name        CGChat
// @namespace   BlaiseEbuth
// @match       https://www.codingame.com/*
// @grant       none
// @version     1.1.2
// @author      BlaiseEbuth
// @description The CodinGame web-chat without CodinGame.
// @icon https://i.imgur.com/E39sADi.png
// ==/UserScript==

'use strict';

var openedLinks = {};

function setTitle()
{
    var title = document.getElementsByTagName("title");

    if(title.length == 1)
    {
        title[0].innerHTML = "CGChat";
    }
}

function signin()
{
    var nav = document.getElementById("navigation");
    var cookies = document.getElementsByClassName("cg-cookies-banner");
    var footer = document.getElementsByClassName("cg-login-form_footer");
    
    if(nav != null)nav.style.display = "none";
    if(cookies.length == 1)cookies[0].style.display = "none";
    if(footer.length == 1)footer[0].style.display = "none";
}

function chat()
{
    if(window.isNwjs && document.getElementById("jquery") == null)
    {
        var head = document.getElementsByTagName("head");

        if(head.length == 1)
        {
            var jquery = document.createElement("script");
            jquery.id = "jquery";
            jquery.type = "text/javascript";
            jquery.src = "https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js";
            head[0].appendChild(jquery);
        }
    }

    var leftCol = document.getElementsByClassName("left-column");
    var nav = document.getElementById("navigation");

    if(leftCol.length == 1)leftCol[0].style.display = "none"; 
    if(nav != null)nav.style.display = "none";
    
    var wrapper = document.getElementsByClassName("chat-wrapper");
    var chat = document.getElementById("chat");

    if(wrapper.length == 1)wrapper[0].style.cssText = "width:100% !important"; 
    if(chat != null)chat.style.cssText = "display:flex !important";
    
    var small = document.getElementsByClassName("small-chat");

    if(small.length == 1)small[0].click();

    var chatClass = document.getElementsByClassName("chat");
    var discord = document.getElementsByTagName("cg-discord-disclaimer");
    var hideWrapper = document.getElementsByClassName("hide-wrapper");
    var help = document.getElementsByClassName("help-center");

    if(chatClass.length == 1)chatClass[0].style.width = "100%";
    if(discord.length == 1)discord[0].style.display = "none";
    if(hideWrapper.length == 1)hideWrapper[0].style.display = "none";
    if(help.length == 1)help[0].style.display = "none";

    var settings = document.getElementsByClassName("settings-popup");

    if(settings.length == 1)
    {
        for(var i = 0; i < 3; i++)
        {
            settings[0].children[i].style.display = "none";
        }
    }

    var messages = document.getElementById("messages");
    
    if(document.getElementById("messages") != null)
    {
        messages.style.width = "100%";
        
        if(window.isNwjs)
        {
          var links = messages.getElementsByTagName("a");

          if(links.length > 0)
          {
              $('a[target=_blank]').on('click', function()
              {
                  if(!(this.href in openedLinks))
                  {
                      require('nw.gui').Shell.openExternal(this.href);
                      openedLinks[this.href] = 100;
                  }
                  return false;
              });
          }
        }
    }
}

var main = function()
{
    if(window.isNwjs == null)
    {
        try
        {
            window.isNwjs = (typeof require('nw.gui') !== "undefined");
        }
        catch(e)
        {
            window.isNwjs = false;
        }
    }
  
    setTitle();

    for(var l in openedLinks)
    {
        openedLinks[l]--;

        if(openedLinks[l] == 0)
        {
            delete openedLinks[l];
        }
    }

    var path = window.location.pathname;

    if(path  == "/start")
    {
        window.location.replace("/signin");
    }
    else if(path == "/signin")
    {
        signin();
    }
    else
    {
        chat();
    }
}

setInterval(main, 100);