add to git
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
export function hello() {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
window.onerror = function (error) {
|
||||
parent.document.body.getElementsByTagName("notification-bubbles")[0].add(error, 'syntax-error');
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
try {
|
||||
setTimeout(() => {
|
||||
[replace]
|
||||
});
|
||||
|
||||
}
|
||||
catch (ex) {
|
||||
parent.document.body.getElementsByTagName("notification-bubbles")[0].add(ex, 'syntax-error');
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// define a new console
|
||||
var console=(function(oldCons){
|
||||
return {
|
||||
log: function(text){
|
||||
oldCons.log(text);
|
||||
parent.document.body.getElementsByTagName("notification-bubbles")[0].add(text, 'log');
|
||||
},
|
||||
info: function (text) {
|
||||
oldCons.info(text);
|
||||
parent.document.body.getElementsByTagName("notification-bubbles")[0].add(text, 'info');
|
||||
},
|
||||
warn: function (text) {
|
||||
oldCons.warn(text);
|
||||
parent.document.body.getElementsByTagName("notification-bubbles")[0].add(text, 'warn');
|
||||
},
|
||||
error: function (text) {
|
||||
oldCons.error(text);
|
||||
parent.document.body.getElementsByTagName("notification-bubbles")[0].add(text, 'error');
|
||||
}
|
||||
};
|
||||
}(window.console));
|
||||
|
||||
//Then redefine the old console
|
||||
window.console = console;
|
||||
@@ -0,0 +1,4 @@
|
||||
setTimeout(() => {
|
||||
window.stop();
|
||||
console.log("window stopped");
|
||||
}, 4 * 1000);
|
||||
@@ -0,0 +1,12 @@
|
||||
output-frame {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: block;
|
||||
}
|
||||
|
||||
output-frame > iframe {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border: none;
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
import { BaseElement } from "../_base";
|
||||
import './output-frame.less';
|
||||
import watchConsole from './injects/watch-console.txt';
|
||||
import tryCatch from './injects/try-catch.txt';
|
||||
import onError from './injects/on-error.txt';
|
||||
import windowStopScript from './injects/window-stop.txt';
|
||||
import { NotificationBubbles } from "../notification-bubbles/notification-bubbles";
|
||||
|
||||
export class OutputFrame extends BaseElement {
|
||||
public Iframe: HTMLIFrameElement | null = null;
|
||||
private watchConsoleScript: string;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.watchConsoleScript = watchConsole;
|
||||
}
|
||||
|
||||
onInit(): void {
|
||||
this.reset();
|
||||
}
|
||||
|
||||
onUpdate(): void {
|
||||
}
|
||||
|
||||
reset() {
|
||||
if (this.Iframe && this.hasChild(this.Iframe)) {
|
||||
this.removeChild(this.Iframe);
|
||||
}
|
||||
|
||||
this.Iframe = document.createElement("iframe");
|
||||
this.Iframe.setAttribute("sandbox", "allow-pointer-lock allow-same-origin allow-scripts");
|
||||
|
||||
this.appendChild(this.Iframe);
|
||||
|
||||
var bubbles = <NotificationBubbles>this.find("notification-bubbles");
|
||||
bubbles.reset();
|
||||
|
||||
this.setInitScript(windowStopScript);
|
||||
this.setInitScript(onError);
|
||||
this.setInitScript(watchConsole);
|
||||
}
|
||||
|
||||
preventInfiniteLoop(value: string) {
|
||||
return value.replace("while (true)", "while (false)");
|
||||
}
|
||||
|
||||
private setInitScript(value: string) {
|
||||
var script: HTMLScriptElement = document.createElement("script");
|
||||
script.setAttribute("async", "");
|
||||
script.innerHTML = this.preventInfiniteLoop(value);
|
||||
|
||||
this.Iframe?.contentWindow?.document.body.appendChild(script);
|
||||
}
|
||||
|
||||
setScript(value: string) {
|
||||
this.reset();
|
||||
|
||||
var script: HTMLScriptElement = document.createElement("script");
|
||||
script.setAttribute("async", "");
|
||||
script.innerHTML = this.preventInfiniteLoop(value);
|
||||
|
||||
this.Iframe?.contentWindow?.document.body.appendChild(script);
|
||||
}
|
||||
|
||||
surroundTryCatch(value: string) {
|
||||
return tryCatch.replace("[replace]", value);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user