2019-11-01 20:37:02 +00:00
|
|
|
/* eslint-disable */
|
2020-09-15 16:29:32 +00:00
|
|
|
|
|
|
|
function evalInMainWorld(fn) {
|
|
|
|
const script = document.createElement('script')
|
|
|
|
script.textContent = `((${fn})())`
|
|
|
|
document.documentElement.appendChild(script)
|
|
|
|
}
|
|
|
|
|
|
|
|
async function exec(name) {
|
|
|
|
let result
|
|
|
|
switch (name) {
|
|
|
|
case 'getManifest':
|
|
|
|
result = chrome.runtime.getManifest()
|
|
|
|
break
|
|
|
|
case 'id':
|
|
|
|
result = chrome.runtime.id
|
|
|
|
break
|
|
|
|
case 'getURL':
|
|
|
|
result = chrome.runtime.getURL('main.js')
|
|
|
|
break
|
|
|
|
case 'getPlatformInfo': {
|
|
|
|
result = await new Promise(resolve => {
|
|
|
|
chrome.runtime.sendMessage(name, resolve)
|
|
|
|
})
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const funcStr = `() => { require('electron').ipcRenderer.send('success', ${JSON.stringify(result)}) }`
|
|
|
|
evalInMainWorld(funcStr)
|
|
|
|
}
|
|
|
|
|
|
|
|
window.addEventListener('message', event => {
|
|
|
|
exec(event.data.name)
|
|
|
|
})
|
|
|
|
|
|
|
|
evalInMainWorld(() => {
|
|
|
|
window.exec = name => window.postMessage({ name })
|
2019-07-24 23:01:08 +00:00
|
|
|
})
|