diff --git a/RELASE-NOTES.md b/RELASE-NOTES.md deleted file mode 100644 index 7d18181..0000000 --- a/RELASE-NOTES.md +++ /dev/null @@ -1,28 +0,0 @@ -#Ornitho Decorator Release Notes - -## [0.3.0](https://github.com/pawellabaj/ornitho-decorator/releases/tag/0.2.0) - 25.07.2022 - -New features: -* allow copying the generated coordinates to a system Clipboard with a single click - -Housekeeping: -* fixed links in documentation - -## [0.2.0](https://github.com/pawellabaj/ornitho-decorator/releases/tag/0.2.0) - 4.07.2022 - -New features: -* configurable place where a map with a location is opened: - * the same tab - * the new tab - -Housekeeping: -* single [popup.html](./popup/popup.html) file; translations inserted with JS - -## [0.1.1](https://github.com/pawellabaj/ornitho-decorator/releases/tag/0.1.1) - 18.06.2022 - -Buf Fixes: -* corrected typos in a translation - -## 0.1.0 - -Initial version \ No newline at end of file diff --git a/content/decorator.js b/content/decorator.js index 57f7132..2d3557d 100644 --- a/content/decorator.js +++ b/content/decorator.js @@ -20,7 +20,7 @@ function addGCoordinates(options) { coordinatesCell.innerHTML += '
' + '' + gCoordinates + ''; - let copyAnchor = getClipboardAnchor(); + let copyAnchor = getClipboardAnchor(gCoordinates); if (copyAnchor) { coordinatesCell.innerHTML += ' '; coordinatesCell.appendChild(copyAnchor); @@ -45,9 +45,9 @@ function getGCoordinates(coordinatesText) { return latitude + ' , ' + longitude; } -function getClipboardAnchor() { - if (!document.queryCommandSupported('copy')) { - console.log('[Ornitho Decorator] Copy command is not supported by the browser'); +function getClipboardAnchor(coordinatesText) { + if (!navigator.clipboard) { + console.log('[Ornitho Decorator] Copying to the clipboard is not supported by the browser'); return null; } @@ -62,43 +62,17 @@ function getClipboardAnchor() { anchor.style = 'cursor : pointer;'; anchor.appendChild(img); - document.body.addEventListener('click', function (e) { - if (actionId === e.target.id) { - copyCoordinatesToTheClipboard(); + document.body.addEventListener('click', function (event) { + if (actionId === event.target.id) { + navigator.clipboard + .writeText(coordinatesText) + .catch(ex => console.log('[Ornitho Decorator] Unable to copy coordinates to the clipboard: ' + ex)); } }); return anchor; } -function copyCoordinatesToTheClipboard() { - let coordinatesSpan = document.getElementById('od_g_coordinates'); - - let selection = window.getSelection(); - let range = document.createRange(); - range.selectNodeContents(coordinatesSpan); - selection.removeAllRanges(); - selection.addRange(range); - - if (!range) { - return; - } - - try { - document.execCommand('copy'); - } catch (e) { - console.log('[Ornitho Decorator] Unable to copy coordinates: ' + e); - } - - if (window.getSelection().empty) { - window.getSelection().empty(); - } else if (window.getSelection().removeAllRanges) { - window.getSelection().removeAllRanges(); - } else if (window.getSelection().removeRange) { - window.getSelection().removeRange(range); - } -} - function getMapsAnchor(gCoordinates, mapTarget) { let img = document.createElement('img'); img.alt = chrome.i18n.getMessage('locationLinkAlt'); diff --git a/manifest.json b/manifest.json index efa30bd..6200e60 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "name": "Ornitho Decorator", "description": "__MSG_extensionDescription__", - "version": "0.3.0", + "version": "0.3.1", "manifest_version": 3, "icons": { "16": "images/icon16.png", diff --git a/popup/popup.html b/popup/popup.html index 6588d4a..f9a9f2a 100644 --- a/popup/popup.html +++ b/popup/popup.html @@ -8,7 +8,7 @@

Ornitho Decorator extension

Generates and displays location's coordinates in DD (Decimal Degrees) format.

-

For example, 20°01'37.37'' E / 50°03'15.18'' N coordinates are "translated" to 50.05421666666666 , 20.027047222222222.

+

For example, 20°01'37.37'' E / 50°03'15.18'' N coordinates are "translated" to 50.05421666666666 , 20.027047222222222.


It also generates link to Google Maps with the location.