You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
educoder/public/javascripts/jupyter.js

52 lines
1.1 KiB

5 years ago
//用于嵌入到jupyter pod中的js
//guange 2019.12.18
5 years ago
var timebool=false;
5 years ago
window.onload=function(){
5 years ago
console.log("开始发送消息了");
5 years ago
timebool=true;
5 years ago
// runEvery10Sec();
5 years ago
}
5 years ago
function runEvery10Sec() {
// 1000 * 10 = 10 秒钟
5 years ago
// console.log("每隔10秒中一次");
5 years ago
require(["base/js/namespace"],function(Jupyter) {
Jupyter.notebook.save_checkpoint();
});
5 years ago
window.parent.postMessage('jupytermessage','*');
5 years ago
// if(timebool===true){
// setTimeout( runEvery10Sec, 1000 * 10 );
// }
5 years ago
5 years ago
}
5 years ago
window.onload=function(){
5 years ago
document.addEventListener('keydown', (e) => {
5 years ago
if (e.keyCode == 83 && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)){
e.preventDefault();
5 years ago
console.log("ctrl+s");
5 years ago
window.parent.postMessage('jupytermessage','*');
}
});
5 years ago
5 years ago
window.addEventListener('message', (e) => {
if(e){
if(e.data){
5 years ago
if(e.data==="stopParent"){
5 years ago
//重置停止
timebool=false;
5 years ago
// console.log("父窗口调用停止");
5 years ago
}else if(e.data==="clonsParent"){
5 years ago
// console.log("父窗口调用启动");
5 years ago
//取消启动
timebool=true;
5 years ago
// runEvery10Sec();
5 years ago
}
}
}
});
5 years ago
}