Google Colab Auto Reconnector

Automatically reconnect to Colab's session without clicking button.

Pada tanggal 25 Juni 2019. Lihat %(latest_version_link).

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name Google Colab Auto Reconnector
// @namespace http://tampermonkey.net/
// @version 1.2
// @description Automatically reconnect to Colab's session without clicking button.
// @author PartMent
// @match https://colab.research.google.com/*
// @match http://colab.research.google.com/*
// @match https://*.research.google.com/*
// @match http://*.research.google.com/*
// @license MIT
// @grant none
// ==/UserScript==

//Keep Page Active
Object.defineProperty(document, 'visibilityState', {value: 'visible', writable: true});
Object.defineProperty(document, 'hidden', {value: false, writable: true});
document.dispatchEvent(new Event("visibilitychange"));

//Define MutationObserver to automatically reconnect
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
if (MutationObserver) console.log('Auto reconnector is enabled.');
var observer = new MutationObserver(function(mutations) {
    console.log('Detected DOM changes.');
    setTimeout(function () {
        var ok = document.getElementById('ok');
        if(ok.textContent.includes("連接") || ok.textContent.includes("连接") || ok.textContent.includes("Connect") || ok.textContent.includes("connect") || ok.textContent.includes("CONNECT")) {
            console.log('Reconnecting...');
            ok.click();
            console.log('Connected');
        }
    }, 3000);
});
observer.observe(document.body, {childList: true});