diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | addon/background.js | 16 | ||||
-rw-r--r-- | addon/index.mjs | 12 | ||||
-rw-r--r-- | addon/manifest.json | 8 | ||||
-rw-r--r-- | src/dumbymap.mjs | 76 |
5 files changed, 74 insertions, 39 deletions
@@ -3,6 +3,7 @@ docs/ | |||
3 | addon/**js | 3 | addon/**js |
4 | addon/**css | 4 | addon/**css |
5 | !addon/index** | 5 | !addon/index** |
6 | !addon/background** | ||
6 | doc-coverage/ | 7 | doc-coverage/ |
7 | node_modules/ | 8 | node_modules/ |
8 | package-lock.json | 9 | package-lock.json |
diff --git a/addon/background.js b/addon/background.js new file mode 100644 index 0000000..24771aa --- /dev/null +++ b/addon/background.js | |||
@@ -0,0 +1,16 @@ | |||
1 | console.log('background') | ||
2 | |||
3 | browser.contextMenus.create( | ||
4 | { | ||
5 | id: 'map-inline', | ||
6 | title: 'MapInline', | ||
7 | contexts: ['page', 'selection'], | ||
8 | }, | ||
9 | () => void browser.runtime.lastError, | ||
10 | ) | ||
11 | |||
12 | browser.contextMenus.onClicked.addListener((info, tab) => { | ||
13 | if (info.menuItemId !== 'map-inline') return | ||
14 | |||
15 | browser.tabs.sendMessage(tab.id, 'map-inline') | ||
16 | }) | ||
diff --git a/addon/index.mjs b/addon/index.mjs index 5776a18..b9fc349 100644 --- a/addon/index.mjs +++ b/addon/index.mjs | |||
@@ -1,3 +1,13 @@ | |||
1 | browser.runtime.onMessage.addListener((message, sender, sendResponse) => { | ||
2 | console.log('receive message', message) | ||
3 | sendResponse('received') | ||
4 | if (message === 'map-inline') { | ||
5 | alert('map') | ||
6 | return Promise.resolve('done') | ||
7 | } | ||
8 | return false | ||
9 | }) | ||
10 | |||
1 | const url = new URL(window.location) | 11 | const url = new URL(window.location) |
2 | const use = url.searchParams.get('use') | 12 | const use = url.searchParams.get('use') |
3 | if (url.host === 'www.ptt.cc') { | 13 | if (url.host === 'www.ptt.cc') { |
@@ -41,6 +51,6 @@ if (!document.querySelector('.Dumby')) { | |||
41 | addBlocks, | 51 | addBlocks, |
42 | initialLayout: 'sticky', | 52 | initialLayout: 'sticky', |
43 | render: simpleRender, | 53 | render: simpleRender, |
44 | autoMap: true, | 54 | autoMap: false, |
45 | }) | 55 | }) |
46 | } | 56 | } |
diff --git a/addon/manifest.json b/addon/manifest.json index b95fd4b..c354f65 100644 --- a/addon/manifest.json +++ b/addon/manifest.json | |||
@@ -27,10 +27,18 @@ | |||
27 | } | 27 | } |
28 | ], | 28 | ], |
29 | 29 | ||
30 | "background": { | ||
31 | "scripts": [ | ||
32 | "background.js" | ||
33 | ], | ||
34 | "persistent": false | ||
35 | }, | ||
36 | |||
30 | "permissions": [ | 37 | "permissions": [ |
31 | "activeTab", | 38 | "activeTab", |
32 | "tabs", | 39 | "tabs", |
33 | "scripting", | 40 | "scripting", |
41 | "contextMenus", | ||
34 | "https://epsg.io/*", | 42 | "https://epsg.io/*", |
35 | "https://cdn.jsdelivr.net/*" | 43 | "https://cdn.jsdelivr.net/*" |
36 | ] | 44 | ] |
diff --git a/src/dumbymap.mjs b/src/dumbymap.mjs index 7d24e45..a7b0394 100644 --- a/src/dumbymap.mjs +++ b/src/dumbymap.mjs | |||
@@ -530,44 +530,44 @@ export const generateMaps = (container, { | |||
530 | } | 530 | } |
531 | container.appendChild(menu) | 531 | container.appendChild(menu) |
532 | 532 | ||
533 | /** Menu Items for Context Menu */ | 533 | // /** Menu Items for Context Menu */ |
534 | container.oncontextmenu = e => { | 534 | // container.oncontextmenu = e => { |
535 | menu.replaceChildren() | 535 | // menu.replaceChildren() |
536 | menu.style.display = 'block' | 536 | // menu.style.display = 'block' |
537 | menu.style.cssText = `left: ${e.clientX - menu.offsetParent.offsetLeft + 10}px; top: ${e.clientY - menu.offsetParent.offsetTop + 5}px;` | 537 | // menu.style.cssText = `left: ${e.clientX - menu.offsetParent.offsetLeft + 10}px; top: ${e.clientY - menu.offsetParent.offsetTop + 5}px;` |
538 | e.preventDefault() | 538 | // e.preventDefault() |
539 | 539 | // | |
540 | // Menu Items for map | 540 | // // Menu Items for map |
541 | const map = e.target.closest('.mapclay') | 541 | // const map = e.target.closest('.mapclay') |
542 | if (map?.renderer?.results) { | 542 | // if (map?.renderer?.results) { |
543 | const rect = map.getBoundingClientRect() | 543 | // const rect = map.getBoundingClientRect() |
544 | const [x, y] = [e.x - rect.left, e.y - rect.top] | 544 | // const [x, y] = [e.x - rect.left, e.y - rect.top] |
545 | menu.appendChild(menuItem.toggleMapFocus(map)) | 545 | // menu.appendChild(menuItem.toggleMapFocus(map)) |
546 | menu.appendChild(menuItem.renderResults(dumbymap, map)) | 546 | // menu.appendChild(menuItem.renderResults(dumbymap, map)) |
547 | menu.appendChild(menuItem.getCoordinatesByPixels(map, [x, y])) | 547 | // menu.appendChild(menuItem.getCoordinatesByPixels(map, [x, y])) |
548 | menu.appendChild(menuItem.restoreCamera(map)) | 548 | // menu.appendChild(menuItem.restoreCamera(map)) |
549 | } else { | 549 | // } else { |
550 | // Toggle block focus | 550 | // // Toggle block focus |
551 | const block = e.target.closest('.dumby-block') | 551 | // const block = e.target.closest('.dumby-block') |
552 | if (block) { | 552 | // if (block) { |
553 | menu.appendChild(menuItem.toggleBlockFocus(block)) | 553 | // menu.appendChild(menuItem.toggleBlockFocus(block)) |
554 | } | 554 | // } |
555 | } | 555 | // } |
556 | 556 | // | |
557 | // Menu Items for map/block/layout | 557 | // // Menu Items for map/block/layout |
558 | if (!map || map.closest('.Showcase')) { | 558 | // if (!map || map.closest('.Showcase')) { |
559 | if (dumbymap.utils.renderedMaps().length > 0) { | 559 | // if (dumbymap.utils.renderedMaps().length > 0) { |
560 | menu.appendChild(menuItem.pickMapItem(dumbymap)) | 560 | // menu.appendChild(menuItem.pickMapItem(dumbymap)) |
561 | } | 561 | // } |
562 | menu.appendChild(menuItem.pickBlockItem(dumbymap)) | 562 | // menu.appendChild(menuItem.pickBlockItem(dumbymap)) |
563 | menu.appendChild(menuItem.pickLayoutItem(dumbymap)) | 563 | // menu.appendChild(menuItem.pickLayoutItem(dumbymap)) |
564 | } | 564 | // } |
565 | 565 | // | |
566 | shiftByWindow(menu) | 566 | // shiftByWindow(menu) |
567 | 567 | // | |
568 | return menu | 568 | // return menu |
569 | } | 569 | // } |
570 | 570 | // | |
571 | /** Event Handler when clicking outside of Context Manu */ | 571 | /** Event Handler when clicking outside of Context Manu */ |
572 | const actionOutsideMenu = e => { | 572 | const actionOutsideMenu = e => { |
573 | if (menu.style.display === 'none') return | 573 | if (menu.style.display === 'none') return |