Skip to content

Commit

Permalink
Resolved Sonar findings (#10)
Browse files Browse the repository at this point in the history
Resolved Sonar findings
  • Loading branch information
pawellabaj authored Jul 28, 2022
1 parent 433afdb commit 31b9a33
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 65 deletions.
28 changes: 0 additions & 28 deletions RELASE-NOTES.md

This file was deleted.

44 changes: 9 additions & 35 deletions content/decorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function addGCoordinates(options) {

coordinatesCell.innerHTML += '<br>' + '<span id="od_g_coordinates">' + gCoordinates + '</span>';

let copyAnchor = getClipboardAnchor();
let copyAnchor = getClipboardAnchor(gCoordinates);
if (copyAnchor) {
coordinatesCell.innerHTML += '&nbsp;';
coordinatesCell.appendChild(copyAnchor);
Expand All @@ -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;
}

Expand All @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion popup/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<div style="margin: 0; overflow: hidden; min-width: 400px; min-height: 200px;">
<h1 id="title">Ornitho Decorator extension</h1>
<p id="description_1">Generates and displays location's coordinates in DD (Decimal Degrees) format.</p>
<p id="description_2">For example, <b>20°01'37.37'' E / 50°03'15.18'' N</b> coordinates are <em>"translated"</em> to <b>50.05421666666666 , 20.027047222222222</b>.</p>
<p id="description_2">For example, <strong>20°01'37.37'' E / 50°03'15.18'' N</strong> coordinates are <em>"translated"</em> to <strong>50.05421666666666 , 20.027047222222222</strong>.</p>
<hr>
<p id="description_3">It also generates link to Google Maps with the location.</p>
</div>
Expand Down

0 comments on commit 31b9a33

Please sign in to comment.