tweaks, know what to do for extension now i think maybe possibly
This commit is contained in:
parent
b3dc75f4ce
commit
d8ae0b680b
|
|
@ -1,9 +1,5 @@
|
||||||
import browser from 'webextension-polyfill';
|
import browser from 'webextension-polyfill';
|
||||||
|
|
||||||
browser.runtime.onInstalled.addListener(() => {
|
|
||||||
console.log('Installed!');
|
|
||||||
});
|
|
||||||
|
|
||||||
browser.browserAction.onClicked.addListener((tab) => {
|
browser.browserAction.onClicked.addListener((tab) => {
|
||||||
if (tab.id) {
|
if (tab.id) {
|
||||||
browser.tabs.sendMessage(tab.id, { action: 'insertFolkCanvas' });
|
browser.tabs.sendMessage(tab.id, { action: 'insertFolkCanvas' });
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,15 @@
|
||||||
import browser from 'webextension-polyfill';
|
import browser from 'webextension-polyfill';
|
||||||
import { FolkShape } from '../src/folk-shape';
|
|
||||||
|
|
||||||
// Define the custom element with its proper tag name
|
|
||||||
customElements.define('folk-shape', FolkShape);
|
|
||||||
|
|
||||||
browser.runtime.onMessage.addListener((message: any) => {
|
browser.runtime.onMessage.addListener((message: any) => {
|
||||||
|
console.log('HELLO MESSAGE', message);
|
||||||
if (message.action === 'insertFolkCanvas') {
|
if (message.action === 'insertFolkCanvas') {
|
||||||
// Append a 'folk-canvas' div to the document body
|
// Inject 'injected.js' into the page context
|
||||||
const folkCanvas = document.createElement('div');
|
const script = document.createElement('script');
|
||||||
folkCanvas.className = 'folk-canvas';
|
script.src = browser.runtime.getURL('injected.js');
|
||||||
document.body.appendChild(folkCanvas);
|
script.onload = function () {
|
||||||
|
script.remove();
|
||||||
// Create and add a 'folk-shape' element
|
};
|
||||||
const folkShape = document.createElement('folk-shape') as FolkShape;
|
(document.head || document.documentElement).appendChild(script);
|
||||||
folkShape.innerHTML = '<p>Hello, Folk Shape!</p>';
|
|
||||||
folkCanvas.appendChild(folkShape);
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
// just checking we can add a simple element (we can)
|
||||||
|
const testElement = document.createElement('p');
|
||||||
|
testElement.textContent = 'Hello, TEST!';
|
||||||
|
document.body.appendChild(testElement);
|
||||||
|
|
||||||
|
// Now you can use FolkShape in the page context
|
||||||
|
const folkShape = document.createElement('folk-shape');
|
||||||
|
document.body.appendChild(folkShape);
|
||||||
|
|
||||||
|
if (typeof customElements !== 'undefined') {
|
||||||
|
console.log('defining folk-shape');
|
||||||
|
// need to find the right way to bundle this all up and call it at the right time
|
||||||
|
// FolkShape.define();
|
||||||
|
console.log('importing folk-shape');
|
||||||
|
// this also won't work
|
||||||
|
// maybe just simply build and bundle it all up, this is probl easiest.
|
||||||
|
// import('../src/folk-shape').then((m) => m.FolkShape.define());
|
||||||
|
} else {
|
||||||
|
console.warn('CUSTOM ELEMENTS NOT DEFINED');
|
||||||
|
}
|
||||||
|
|
@ -6,6 +6,9 @@
|
||||||
"service_worker": "background.ts"
|
"service_worker": "background.ts"
|
||||||
},
|
},
|
||||||
"options_page": "options.html",
|
"options_page": "options.html",
|
||||||
|
"web_accessible_resources": [
|
||||||
|
"injected.ts"
|
||||||
|
],
|
||||||
"content_scripts": [
|
"content_scripts": [
|
||||||
{
|
{
|
||||||
"matches": [
|
"matches": [
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,13 @@ import { defineConfig } from 'vite';
|
||||||
import webExtension from 'vite-plugin-web-extension';
|
import webExtension from 'vite-plugin-web-extension';
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
|
build: {
|
||||||
|
rollupOptions: {
|
||||||
|
input: {
|
||||||
|
injected: 'injected.ts',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
webExtension({
|
webExtension({
|
||||||
webExtConfig: {
|
webExtConfig: {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue