Skip to content

Commit

Permalink
Allow to copy ID of the block/item to clipboard. This fixes #73.
Browse files Browse the repository at this point in the history
  • Loading branch information
Matriks404 committed Mar 10, 2024
1 parent ca30a6c commit b79dd5c
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions site/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,23 @@ var excludeCheckboxes = [
'exclude-obtainable-in-winter-mode',
];

function writeToClipboard(el) {
var idElement = el.querySelector('.id');
var id = idElement.firstChild.nodeValue;

var damageValueElement = idElement.querySelector('.damage-value');

if (damageValueElement) {
var damageValue = damageValueElement.innerText;

navigator.clipboard.writeText(id + ':' + damageValue);
} else {
navigator.clipboard.writeText(id);
}

alert("ID copied!");
}

function fetchJSONData(filename) {
return fetch(filename)
.then(function (res) {
Expand Down Expand Up @@ -98,8 +115,8 @@ function loadVersionList() {
var versions = versionGroups[groupId].versions;

Object.keys(versions).forEach(function (id) {
var option = document.createElement('option');
option.setAttribute('value', id);
var optionElement = document.createElement('option');
optionElement.setAttribute('value', id);

var version = versions[id]
var name;
Expand All @@ -116,9 +133,9 @@ function loadVersionList() {
name += " [NEEDS TESTING]";
}

option.text = name;
optionElement.text = name;

el.add(option);
el.add(optionElement);
});
}

Expand Down Expand Up @@ -390,6 +407,13 @@ function loadCurrentVersion() {
loadEntries(items, itemsContentElement, "items", version.hasUnknownItemIds);
}

var entryElements = document.querySelectorAll('.entry');

Array.prototype.forEach.call(entryElements, function(el) {
el.addEventListener('click', () => writeToClipboard(el));
//el.addEventListener('touchend', () => writeToClipboard(el));
});

var elementsWithTooltips = document.querySelectorAll('.with-tooltip');

Array.prototype.forEach.call(elementsWithTooltips, function (el) {
Expand Down

0 comments on commit b79dd5c

Please sign in to comment.