aboutsummaryrefslogtreecommitdiffhomepage
path: root/addon/index.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'addon/index.mjs')
-rw-r--r--addon/index.mjs25
1 files changed, 24 insertions, 1 deletions
diff --git a/addon/index.mjs b/addon/index.mjs
index 2494ec4..7f33fc5 100644
--- a/addon/index.mjs
+++ b/addon/index.mjs
@@ -1,4 +1,26 @@
1const { Leaflet } = window.mapclay.renderers 1const url = new URL(window.location)
2if (url.host === 'www.ptt.cc') {
3 const content = document.querySelector('#main-content')
4 Array.from(content.childNodes)
5 .filter(n => !(n instanceof window.HTMLElement))
6 .forEach(text => {
7 const span = document.createElement('span')
8 span.innerText = text.textContent
9 text.replaceWith(span)
10 })
11}
12
13const blockSelectors = {
14 'developer.mozilla': '.section-content',
15 'hackmd.io': '#doc > *',
16 'www.ptt.cc': '#main-content > span',
17}
18const blockSelector = blockSelectors[url.host]
19
20const addBlocks = blockSelector
21 ? root => Array.from(root.querySelectorAll(blockSelector))
22 : undefined
23
2const simpleRender = window.mapclay.renderWith(config => ({ 24const simpleRender = window.mapclay.renderWith(config => ({
3 use: 'Leaflet', 25 use: 'Leaflet',
4 width: '100%', 26 width: '100%',
@@ -13,6 +35,7 @@ const simpleRender = window.mapclay.renderWith(config => ({
13 35
14window.generateMaps(document.querySelector('main') ?? document.body, { 36window.generateMaps(document.querySelector('main') ?? document.body, {
15 crs: url.searchParams.get('crs') ?? 'EPSG:4326', 37 crs: url.searchParams.get('crs') ?? 'EPSG:4326',
38 addBlocks,
16 initialLayout: '', 39 initialLayout: '',
17 render: simpleRender, 40 render: simpleRender,
18}) 41})