Greasy Fork is available in English.

ColabHelper

A helper to start and terminate the colab session

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

You will need to install an extension such as Tampermonkey 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.

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

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         ColabHelper
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  A helper to start and terminate the colab session
// @author       You
// @match        https://colab.research.google.com/drive/*
// @icon         https://www.google.com/s2/favicons?domain=colab.research.google.com
// @grant        none
// ==/UserScript==

var zNode = document.createElement ('div');
zNode.innerHTML = '<button id="startButton" type="button">Start</button>  <button id="closeButton" type="button">Close</button>';
zNode.setAttribute ('id', 'myContainer');
document.body.appendChild (zNode);

//--- Activate the newly added button.
document.getElementById ("startButton").addEventListener (
    "click", startButtonClickAction, false
);

document.getElementById ("closeButton").addEventListener (
    "click", endButtonClickAction, false
);

function startButtonClickAction (zEvent) {
    /*--- For our dummy action, we'll just add a line of text to the top
        of the screen.
    */
    var zNode = document.createElement ('p');
    document.getElementById ("myContainer").appendChild (zNode);
    document.querySelector("colab-run-button").click();
}

function endButtonClickAction (zEvent) {
    end();
}

//Sleep function
const sleep = (milliseconds) => {
  return new Promise(resolve => setTimeout(resolve, milliseconds))
}

//End function
const end = async () => {
    //Click on menu button
    document.querySelector("#top-toolbar > colab-connect-button").shadowRoot.querySelector("#connect").click();
    await sleep(500);

    //Click on manage sessions
    document.querySelector("colab-usage-display").shadowRoot.querySelector("div paper-button").click();
    await sleep(2000);

    //Click on terminate session
    //document.querySelector("body > colab-dialog > paper-dialog > colab-sessions-dialog").shadowRoot.querySelector("div.dialog-main-content > div.sessions-content.layout.vertical > div.dialog-table > colab-session > div.button-action-column > paper-icon-button").click()
    document.querySelector("body > colab-dialog > paper-dialog > colab-sessions-dialog").shadowRoot.querySelector("div.dialog-main-content > div.sessions-content.layout.vertical > div.dialog-table > colab-session > div.button-action-column > paper-button").click();
    await sleep(1000);

    //Click on okay buttom if prompted
    try {
      document.querySelector("#ok").click();
      // await sleep(1000);
    }
    catch(err) {
      console.log('No okay button')
    }

    document.querySelector("body > colab-dialog > paper-dialog > colab-sessions-dialog").shadowRoot.querySelector("paper-button.dismiss").click()
    await sleep(1000);
    //document.querySelector("colab-usage-display").shadowRoot.querySelector("div paper-button").click();
}