Rename page and content scripts (self-explanatory) (#33)

This commit is contained in:
Jaco Greeff
2019-05-29 14:33:15 +02:00
committed by GitHub
parent a79d174e5e
commit 5df1dc3e73
12 changed files with 152 additions and 112 deletions
+2 -2
View File
@@ -11,7 +11,7 @@
"default_popup": "popup.html"
},
"content_scripts": [{
"js": ["loader.js"],
"js": ["content.js"],
"matches": [
"https://polkadot.js.org/apps/*",
"http://localhost:3000/*"
@@ -25,6 +25,6 @@
"64": "images/icon-64.png",
"128": "images/icon-128.png"
},
"web_accessible_resources": ["inject.js"],
"web_accessible_resources": ["page.js"],
"content_security_policy": "script-src 'self' 'unsafe-eval' 'wasm-eval'; object-src 'self'"
}
+1 -1
View File
@@ -5,7 +5,7 @@
"author": "Jaco Greeff <jacogr@gmail.com>",
"license": "Apache-2",
"dependencies": {
"@polkadot/api": "^0.80.0-beta.2",
"@polkadot/api": "^0.80.0-beta.6",
"@polkadot/extension-ui": "^0.1.1-beta.8",
"@polkadot/ui-keyring": "^0.40.0-beta.1"
},
@@ -5,13 +5,13 @@
import extension from 'extensionizer';
function sendResponse (data: any): void {
window.postMessage({ ...data, origin: 'loader' }, '*');
window.postMessage({ ...data, origin: 'content' }, '*');
}
// Handle all messages, passing messages to the extension
window.addEventListener('message', ({ data, source }) => {
// only allow messages from our window, by the inject
if (source !== window || data.origin !== 'inject') {
if (source !== window || data.origin !== 'page') {
return;
}
@@ -30,7 +30,7 @@ window.addEventListener('message', ({ data, source }) => {
// inject our data injector
const script = document.createElement('script');
script.src = extension.extension.getURL('inject.js');
script.src = extension.extension.getURL('page.js');
script.onload = (): void => {
// remove the injecting tag when loaded
if (script.parentNode) {
@@ -34,7 +34,7 @@ function sendMessage (message: MessageTypes, request: any = null): Promise<any>
callbacks[id] = { resolve, reject };
window.postMessage({ id, message, origin: 'inject', request }, '*');
window.postMessage({ id, message, origin: 'page', request }, '*');
});
}
@@ -48,7 +48,7 @@ async function enable (origin: string): Promise<Injected> {
// setup a response listener (events created by the loader for extension responses)
window.addEventListener('message', ({ data, source }) => {
// only allow messages from our window, by the loader
if (source !== window || data.origin !== 'loader') {
if (source !== window || data.origin !== 'content') {
return;
}
+3 -3
View File
@@ -25,9 +25,9 @@ function createWebpack ({ alias = {}, context }) {
devtool: false,
entry: {
background: './src/background/index.ts',
inject: './src/inject/index.ts',
loader: './src/loader.ts',
popup: `./src/views/popup.ts`
content: './src/content.ts',
page: './src/page/index.ts',
popup: `./src/popup.ts`
},
mode: ENV,
output: {