diff options
Diffstat (limited to 'addon/index.mjs')
-rw-r--r-- | addon/index.mjs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/addon/index.mjs b/addon/index.mjs new file mode 100644 index 0000000..b5d71ba --- /dev/null +++ b/addon/index.mjs | |||
@@ -0,0 +1,42 @@ | |||
1 | const url = new URL(window.location) | ||
2 | if (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 | |||
13 | const blockSelectors = { | ||
14 | 'developer.mozilla': '.section-content', | ||
15 | 'hackmd.io': '#doc > *', | ||
16 | 'www.ptt.cc': '#main-content > span', | ||
17 | } | ||
18 | const blockSelector = blockSelectors[url.host] | ||
19 | |||
20 | const addBlocks = blockSelector | ||
21 | ? root => Array.from(root.querySelectorAll(blockSelector)) | ||
22 | : undefined | ||
23 | |||
24 | const simpleRender = window.mapclay.renderWith(config => ({ | ||
25 | use: 'Leaflet', | ||
26 | width: '100%', | ||
27 | height: '200px', | ||
28 | XYZ: 'https://tile.openstreetmap.jp/styles/osm-bright/512/{z}/{x}/{y}.png', | ||
29 | ...config, | ||
30 | aliases: { | ||
31 | use: window.mapclay.renderers, | ||
32 | ...(config.aliases ?? {}), | ||
33 | }, | ||
34 | })) | ||
35 | |||
36 | window.generateMaps(document.querySelector('main') ?? document.body, { | ||
37 | crs: url.searchParams.get('crs') ?? 'EPSG:4326', | ||
38 | addBlocks, | ||
39 | initialLayout: '', | ||
40 | render: simpleRender, | ||
41 | autoMap: true, | ||
42 | }) | ||