f0ad357af2
feat: support chrome.scripting extension APIs
30 lines
786 B
JavaScript
30 lines
786 B
JavaScript
/* global chrome */
|
|
|
|
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
|
sendResponse(request);
|
|
});
|
|
|
|
const map = {
|
|
executeScript () {
|
|
chrome.runtime.sendMessage({ method: 'executeScript' }, response => {
|
|
console.log(JSON.stringify(response));
|
|
});
|
|
},
|
|
registerContentScripts () {
|
|
chrome.runtime.sendMessage({ method: 'registerContentScripts' }, response => {
|
|
console.log(JSON.stringify(response));
|
|
});
|
|
},
|
|
insertCSS () {
|
|
chrome.runtime.sendMessage({ method: 'insertCSS' }, response => {
|
|
console.log(JSON.stringify(response));
|
|
});
|
|
}
|
|
};
|
|
|
|
const dispatchTest = (event) => {
|
|
const { method, args = [] } = JSON.parse(event.data);
|
|
map[method](...args);
|
|
};
|
|
|
|
window.addEventListener('message', dispatchTest, false);
|