|
|
|
@ -1,6 +1,24 @@
|
|
|
|
|
(() => {
|
|
|
|
|
try {
|
|
|
|
|
addEventListener('message', onMessage);
|
|
|
|
|
const detectJs = chain => {
|
|
|
|
|
const properties = chain.split('.');
|
|
|
|
|
|
|
|
|
|
let value = properties.length ? window : null;
|
|
|
|
|
|
|
|
|
|
for ( let i = 0; i < properties.length; i ++ ) {
|
|
|
|
|
let property = properties[i];
|
|
|
|
|
|
|
|
|
|
if ( value && value.hasOwnProperty(property) ) {
|
|
|
|
|
value = value[property];
|
|
|
|
|
} else {
|
|
|
|
|
value = null;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return typeof value === 'string' || typeof value === 'number' ? value : !!value;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const onMessage = event => {
|
|
|
|
|
if ( event.data.id !== 'patterns' ) {
|
|
|
|
@ -36,25 +54,7 @@
|
|
|
|
|
postMessage({ id: 'js', js }, '*');
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const detectJs = chain => {
|
|
|
|
|
const properties = chain.split('.');
|
|
|
|
|
|
|
|
|
|
let value = properties.length ? window : null;
|
|
|
|
|
|
|
|
|
|
for ( let i = 0; i < properties.length; i ++ ) {
|
|
|
|
|
let property = properties[i];
|
|
|
|
|
|
|
|
|
|
if ( value && value.hasOwnProperty(property) ) {
|
|
|
|
|
value = value[property];
|
|
|
|
|
} else {
|
|
|
|
|
value = null;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return typeof value === 'string' || typeof value === 'number' ? value : !!value;
|
|
|
|
|
};
|
|
|
|
|
addEventListener('message', onMessage);
|
|
|
|
|
} catch(e) {
|
|
|
|
|
// Fail quietly
|
|
|
|
|
}
|
|
|
|
|