aboutsummaryrefslogtreecommitdiffhomepage
path: root/addon/index.mjs
diff options
context:
space:
mode:
authorHsieh Chin Fan <pham@topo.tw>2024-11-04 00:20:35 +0800
committerHsieh Chin Fan <pham@topo.tw>2024-11-04 00:20:35 +0800
commit0151c246004de1c0f3ad944f3da6c70a76a49c7e (patch)
tree254aef50e1a59b0fb7f84598a83355a632b22038 /addon/index.mjs
parent15c85d991530c6eec92597c47012452649b1a503 (diff)
refactor(build): update build script for addon
* To fit file size limit for addon submission of mozilla.org, add scripts for each renderers * add scripts/addon.sh for bundling, with simple rollup commands * scripts/rollup.config.js no more handle addon build
Diffstat (limited to 'addon/index.mjs')
-rw-r--r--addon/index.mjs55
1 files changed, 0 insertions, 55 deletions
diff --git a/addon/index.mjs b/addon/index.mjs
deleted file mode 100644
index dd8fa11..0000000
--- a/addon/index.mjs
+++ /dev/null
@@ -1,55 +0,0 @@
1/* global browser */
2/* eslint-disable-next-line no-console */
3console.log('content script loaded')
4
5const url = new URL(window.location)
6const use = url.searchParams.get('use')
7if (url.host === 'www.ptt.cc') {
8 const content = document.querySelector('#main-content')
9 Array.from(content.childNodes)
10 .filter(n => !(n instanceof window.HTMLElement))
11 .forEach(text => {
12 const span = document.createElement('span')
13 span.innerText = text.textContent
14 text.replaceWith(span)
15 })
16}
17
18const contentSelectors = {
19 'developer.mozilla': ':has(.section-content)',
20 'hackmd.io': '#doc',
21 'www.ptt.cc': '#main-content',
22 'prosemirror.net': '.ProseMirror',
23}
24const contentSelector = contentSelectors[url.host]
25
26const simpleRender = mapclay.renderWith(config => ({
27 use: use ?? 'Leaflet',
28 width: '100%',
29 height: '200px',
30 XYZ: 'https://tile.openstreetmap.jp/styles/osm-bright/512/{z}/{x}/{y}.png',
31 ...config,
32 aliases: {
33 use: mapclay.renderers,
34 ...(config.aliases ?? {}),
35 },
36}))
37
38const container = document.querySelector(contentSelector ?? 'main') ?? document.body
39
40browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
41 /* eslint-disable-next-line no-console */
42 console.log('receive message', message)
43 sendResponse('received')
44 if (message.id === 'map-inline-add') {
45 generateMaps(container, {
46 crs: url.searchParams.get('crs') ?? 'EPSG:4326',
47 render: simpleRender,
48 })
49 return Promise.resolve('done')
50 } else if (message.id === 'map-inline-menu') {
51 container.dataset.menu = message.checked ? 'enabled' : 'disabled'
52 return Promise.resolve('done')
53 }
54 return false
55})