[Greasemonkey] On/Off CG player button (avoid high CPU consumption)


CodinGame player (canvas) on Firefox consume lot of CPU (especially on Spoon puzzle) which is annoying and most of the time we don't need it.

I made a Greasemonkey script which add a toggle On/Off button to hide CodinGame player and let our CPU breathe.

Script :

    // ==UserScript==
    // @name        Codingame On/Off Player
    // @namespace   http://www.codingame.com
    // @version     1
    // @include     http://www.codingame.com/*
    // @require     http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
    // @require     https://gist.github.com/raw/2625891/waitForKeyElements.js
    // @grant       none
    // ==/UserScript==

    var iFrame = "#ideFrame";
    var btnText = "On/Off Player";
    var btnImg = "http://png-5.findicons.com/files/icons/2580/android_icons/24/nuclear_power_plant_checkmark.png";
    var headerBtnNode = null;

    this.$ = this.jQuery = jQuery.noConflict(true);

    // Wait for div "headerButtons" (Invite Friends, I need help, ...)
    waitForKeyElements("div.headerButtons", waitForHeaderBtn, false, iFrame);

    function waitForHeaderBtn(jNode) {
        headerBtnNode = jNode;
        waitForKeyElements(".player", addTogglePlayerBtn, false, iFrame);

    function addTogglePlayerBtn(jNode) {
        if(headerBtnNode != null) {
            headerBtnNode.prepend("<div class=\"headerButtonInstance\"><button class=\"headerButton togglePlayer\"><div class=\"button_icon iconNormal icon inviteFriend\" style=\"margin-right:8px\"><img src=\"" + btnImg + "\"></div><span>" + btnText + "</span></button></div>");
        $(iFrame).contents().find(".togglePlayer").click(function() {

E.g: APU: Init Phase (hidden player)

/!\ You must have Greasemonkey/tampermonkey installed to use it.

Install : Codingame On/Off Player

Enjoy wink


Tested on chrome with tampermonkey, it works fine there too. smiley

Maybe it improves the CPU performances (I couldn't test that yet), but the memory is still consumed (and in particular for the APU puzzles, it still leaks). Is that normal?


Yes it's normal because the player still exist. In some cases like in PA2 hide the player don't decrease CPU usage (even if I remove it) and I don't know why, I mean I do not know what causes it, so even if I remove the player instead of hide it, I don't think it will help for RAM consumption.
In APU puzzles I don't have memory leaks anymore (CG made an update on it).


where should this button appear?
i just tried it and didn't see the button ...

maybe it is no longer compatible with the last UI update