Created
October 30, 2017 08:32
-
-
Save mrk-andreev/dfe21a8c6de95dfbb2bd89c0253ed080 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name JupyterUserscript | |
// @version 0.1 | |
// @author Mark Andreev | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
var YOUR_NAME = 'Mark,'; | |
var LONG_TIME_THRESHOLD = 5000; | |
document.addEventListener("DOMContentLoaded", function(){ | |
function NbContainerWait() { | |
if (document.getElementById('notebook-container')) { | |
document.getElementById('notebook-container').style.width = '100%'; | |
document.getElementById('ipython_notebook').style.display = 'None'; | |
document.getElementById('kernel_logo_widget').style.display = 'None'; | |
var kernel_was_busy = false; | |
var kernel_start_busy_time = null; | |
function NbKernelWait(){ | |
if (Jupyter.kernelselector.notebook.kernel_busy){ | |
if (!kernel_was_busy){ | |
kernel_was_busy = true; | |
kernel_start_busy_time = new Date(); | |
} | |
} | |
else { | |
if (kernel_was_busy){ | |
kernel_was_busy = false; | |
var task_time = new Date() - kernel_start_busy_time; | |
if (task_time > LONG_TIME_THRESHOLD){ | |
var notebook_name = document.getElementById('notebook_name').innerText; | |
var msg = YOUR_NAME + 'notebook ' + notebook_name + 'is ready'; | |
window.speechSynthesis.speak(new SpeechSynthesisUtterance(msg)); | |
} | |
} | |
} | |
setTimeout(NbKernelWait, 10); | |
} | |
NbKernelWait(); | |
} else { | |
setTimeout(NbContainerWait, 10); | |
} | |
} | |
NbContainerWait(); | |
}()); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment