aboutsummaryrefslogtreecommitdiffhomepage
path: root/addon/index.mjs
blob: d13877531ac5d1d0f496ce4e6c1204e621324bf9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const url = new URL(window.location)
const use = url.searchParams.get('use')
if (url.host === 'www.ptt.cc') {
  const content = document.querySelector('#main-content')
  Array.from(content.childNodes)
    .filter(n => !(n instanceof window.HTMLElement))
    .forEach(text => {
      const span = document.createElement('span')
      span.innerText = text.textContent
      text.replaceWith(span)
    })
}

const blockSelectors = {
  'developer.mozilla': '.section-content',
  'hackmd.io': '#doc > *',
  'www.ptt.cc': '#main-content > span',
}
const blockSelector = blockSelectors[url.host]

const addBlocks = blockSelector
  ? root => Array.from(root.querySelectorAll(blockSelector))
  : undefined

const simpleRender = window.mapclay.renderWith(config => ({
  use: use ?? 'Leaflet',
  width: '100%',
  height: '200px',
  XYZ: 'https://tile.openstreetmap.jp/styles/osm-bright/512/{z}/{x}/{y}.png',
  ...config,
  aliases: {
    use: window.mapclay.renderers,
    ...(config.aliases ?? {}),
  },
}))

if (!document.querySelector('.Dumby')) {
  window.generateMaps(document.querySelector('main') ?? document.body, {
    crs: url.searchParams.get('crs') ?? 'EPSG:4326',
    addBlocks,
    initialLayout: 'sticky',
    render: simpleRender,
    autoMap: true,
  })
}