diff options
| author | Hsieh Chin Fan <pham@topo.tw> | 2024-10-17 10:38:15 +0800 |
|---|---|---|
| committer | Hsieh Chin Fan <pham@topo.tw> | 2024-10-17 10:38:15 +0800 |
| commit | d91501af0d3860da1022e960199115c33b4a63a6 (patch) | |
| tree | 7a9c02421b33dcb36460acceed381d4a116c148d /addon | |
| parent | 9c90bd1cbdc5de5b50def0eb4cb3e65e80194af3 (diff) | |
| parent | 9a66411258781a57d5c953b7113403fdf0d218cf (diff) | |
Merge branch "addon"
Diffstat (limited to 'addon')
| -rw-r--r-- | addon/index.mjs | 42 | ||||
| -rw-r--r-- | addon/manifest.json | 14 |
2 files changed, 53 insertions, 3 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 | }) | ||
diff --git a/addon/manifest.json b/addon/manifest.json index 27433b3..2d7b1ed 100644 --- a/addon/manifest.json +++ b/addon/manifest.json | |||
| @@ -11,8 +11,15 @@ | |||
| 11 | 11 | ||
| 12 | "content_scripts": [ | 12 | "content_scripts": [ |
| 13 | { | 13 | { |
| 14 | "matches": ["*://*.mozilla.org/*"], | 14 | "matches": [ |
| 15 | "js": ["index.mjs"], | 15 | "*://developer.mozilla.org/*", |
| 16 | "*://hackmd.io/*", | ||
| 17 | "*://*.ptt.cc/*" | ||
| 18 | ], | ||
| 19 | "js": [ | ||
| 20 | "dumbymap.mjs", | ||
| 21 | "index.mjs" | ||
| 22 | ], | ||
| 16 | "css": [ | 23 | "css": [ |
| 17 | "css/dumbymap.css" | 24 | "css/dumbymap.css" |
| 18 | ] | 25 | ] |
| @@ -22,6 +29,7 @@ | |||
| 22 | "permissions": [ | 29 | "permissions": [ |
| 23 | "activeTab", | 30 | "activeTab", |
| 24 | "tabs", | 31 | "tabs", |
| 25 | "scripting" | 32 | "scripting", |
| 33 | "https://epsg.io/*" | ||
| 26 | ] | 34 | ] |
| 27 | } | 35 | } |