From 62b7af8ce0ccbad26cd00be24cc2cf1e817b8581 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Thu, 17 Oct 2024 10:26:52 +0800 Subject: feat: more precise way to get htmlHolder and blocks --- addon/index.mjs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'addon') 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 @@ -const { Leaflet } = window.mapclay.renderers +const url = new URL(window.location) +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: 'Leaflet', width: '100%', @@ -13,6 +35,7 @@ const simpleRender = window.mapclay.renderWith(config => ({ window.generateMaps(document.querySelector('main') ?? document.body, { crs: url.searchParams.get('crs') ?? 'EPSG:4326', + addBlocks, initialLayout: '', render: simpleRender, }) -- cgit v1.2.3-70-g09d2