diff --git a/index.html b/index.html index 4f5c83e..d9d0ac2 100644 --- a/index.html +++ b/index.html @@ -73,6 +73,9 @@ flex-direction: column; align-items: stretch; } + .copyonclick { + cursor: pointer; + } .clicktext { display: none; } @@ -165,6 +168,21 @@ ]; var bgimg = bgs[Math.floor(Math.random() * bgs.length)]; $("body").css("background-image", "url(./img/bg/" + bgimg + ")"); + + $("body").on("click", ".copyonclick", function () { + var copyitem = $(this); + var copytext = copyitem.text(); + if (copytext == "Copied to clipboard!") { + // prevent copying copied text if double-clicked + return; + } + navigator.clipboard.writeText(copytext).then(() => { + copyitem.text("Copied to clipboard!"); + setTimeout(function () { + copyitem.text(copytext); + }, 1000); + }); + }); }; function dolookup(words) { @@ -173,11 +191,11 @@ var coords = FixPhrase.decode(words); location.hash = "#map"; - new mapboxgl.Popup() - .setLngLat({lat: coords[0], lng: coords[1]}) - .setHTML("" + words + "
" + coords[0] + ", " + coords[1]) - .addTo(map); - map.animateMapIn(coords[0], coords[1], 18); + new mapboxgl.Popup() + .setLngLat({lat: coords[0], lng: coords[1]}) + .setHTML("" + words + "
" + coords[0] + ", " + coords[1]) + .addTo(map); + map.animateMapIn(coords[0], coords[1], 18); } catch (e) { alert(e); } diff --git a/js/fixphrase.js b/js/fixphrase.js index 7af9cd7..cd5efe6 100644 --- a/js/fixphrase.js +++ b/js/fixphrase.js @@ -53,15 +53,12 @@ var FixPhrase = { (Number(lon.substring(4, 7)) + 6610), ]; - console.log(groups); - return this.wordlist[groups[0]] + " " + this.wordlist[groups[1]] + " " + this.wordlist[groups[2]] + " " + this.wordlist[groups[3]]; }, decode: function (words) { var indexes = [-1, -1, -1, -1]; words = words.toLowerCase(); words = words.split(" "); - console.log(words); if (words.length < 2) { throw "Not enough words!"; diff --git a/js/map_maplibre.js b/js/map_maplibre.js index 2d45900..5e5c7b8 100644 --- a/js/map_maplibre.js +++ b/js/map_maplibre.js @@ -36,7 +36,7 @@ function maplibreMap() { var words = FixPhrase.encode(coordinates.lat, coordinates.lng); var popup = new mapboxgl.Popup(); popup.setLngLat(e.lngLat); - popup.setHTML("" + words + "
" + (Math.round(coordinates.lat * 10000) / 10000) + ", " + (Math.round(coordinates.lng * 10000) / 10000)); + popup.setHTML("" + words + "
" + (Math.round(coordinates.lat * 10000) / 10000) + ", " + (Math.round(coordinates.lng * 10000) / 10000)); popup.addTo(map); map.flyTo({ center: e.lngLat,