diff options
| -rw-r--r-- | addon/index.mjs | 25 | ||||
| -rw-r--r-- | src/dumbymap.mjs | 5 |
2 files changed, 28 insertions, 2 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 @@ | |||
| 1 | const { Leaflet } = window.mapclay.renderers | 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 | |||
| 2 | const simpleRender = window.mapclay.renderWith(config => ({ | 24 | const 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 | ||
| 14 | window.generateMaps(document.querySelector('main') ?? document.body, { | 36 | window.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 | }) |
diff --git a/src/dumbymap.mjs b/src/dumbymap.mjs index cbd44b2..94fcc1d 100644 --- a/src/dumbymap.mjs +++ b/src/dumbymap.mjs | |||
| @@ -171,8 +171,11 @@ export const generateMaps = (container, { | |||
| 171 | container.dataset.layout = initialLayout ?? defaultLayouts[0].name | 171 | container.dataset.layout = initialLayout ?? defaultLayouts[0].name |
| 172 | 172 | ||
| 173 | /** Prepare Semantic HTML part and blocks of contents inside */ | 173 | /** Prepare Semantic HTML part and blocks of contents inside */ |
| 174 | const htmlHolder = container.querySelector('.SemanticHtml, :has(article, section)') ?? container.firstElementChild | 174 | const htmlHolder = container.querySelector('.SemanticHtml') ?? |
| 175 | Array.from(container.children).find(e => e.id?.includes('main') || e.className.includes('main')) ?? | ||
| 176 | Array.from(container.children).sort((a, b) => a.textContent.length < b.textContent.length).at(0) | ||
| 175 | htmlHolder.classList.add('.SemanticHtml') | 177 | htmlHolder.classList.add('.SemanticHtml') |
| 178 | |||
| 176 | const blocks = addBlocks(htmlHolder) | 179 | const blocks = addBlocks(htmlHolder) |
| 177 | blocks.forEach(b => { | 180 | blocks.forEach(b => { |
| 178 | b.classList.add('dumby-block') | 181 | b.classList.add('dumby-block') |