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.
NewEduCoderBuild/js/jupyter.js

54 lines
1.2 KiB

(function (open) {
XMLHttpRequest.prototype.open = function (method, url, async, user, password) {
this.addEventListener("load", function () {
if (method === "PUT") {
window.top.postMessage('jupytermessage', '*');
}
});
open.call(this, method, url, async, user, password);
};
})(XMLHttpRequest.prototype.open);
(function (fetch) {
window.fetch = function (url, options) {
options = options || {}
return fetch.apply(this, arguments).then(function (response) {
try {
if (options.method === "PUT" || (typeof url === "object" && url.method === "PUT")) {
window.top.postMessage('jupytermessage', '*');
}
} catch (error) {
}
return response;
});
};
})(window.fetch);
function saveCode() {
var saveEvent = new KeyboardEvent('keydown', {
key: 's',
ctrlKey: true
});
document.dispatchEvent(saveEvent);
}
function onReceiveMessage(e) {
try {
if (mes.type === 'saveCode') {
saveCode()
}
} catch (error) {
console.log('error:', error, e);
}
}
(function () {
setInterval(() => {
saveCode()
}, 5000)
})();
window.addEventListener('message', onReceiveMessage);