tweaks, know what to do for extension now i think maybe possibly

This commit is contained in:
Orion Reed 2024-12-13 23:47:41 -05:00
parent b3dc75f4ce
commit d8ae0b680b
5 changed files with 38 additions and 17 deletions

View File

@ -1,9 +1,5 @@
import browser from 'webextension-polyfill';
browser.runtime.onInstalled.addListener(() => {
console.log('Installed!');
});
browser.browserAction.onClicked.addListener((tab) => {
if (tab.id) {
browser.tabs.sendMessage(tab.id, { action: 'insertFolkCanvas' });

View File

@ -1,20 +1,15 @@
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) => {
console.log('HELLO MESSAGE', message);
if (message.action === 'insertFolkCanvas') {
// Append a 'folk-canvas' div to the document body
const folkCanvas = document.createElement('div');
folkCanvas.className = 'folk-canvas';
document.body.appendChild(folkCanvas);
// Create and add a 'folk-shape' element
const folkShape = document.createElement('folk-shape') as FolkShape;
folkShape.innerHTML = '<p>Hello, Folk Shape!</p>';
folkCanvas.appendChild(folkShape);
// Inject 'injected.js' into the page context
const script = document.createElement('script');
script.src = browser.runtime.getURL('injected.js');
script.onload = function () {
script.remove();
};
(document.head || document.documentElement).appendChild(script);
}
return true;
});

20
browser-ext/injected.ts Normal file
View File

@ -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');
}

View File

@ -6,6 +6,9 @@
"service_worker": "background.ts"
},
"options_page": "options.html",
"web_accessible_resources": [
"injected.ts"
],
"content_scripts": [
{
"matches": [

View File

@ -2,6 +2,13 @@ import { defineConfig } from 'vite';
import webExtension from 'vite-plugin-web-extension';
export default defineConfig({
build: {
rollupOptions: {
input: {
injected: 'injected.ts',
},
},
},
plugins: [
webExtension({
webExtConfig: {