41 lines
1.4 KiB
JavaScript
41 lines
1.4 KiB
JavaScript
$(function() {
|
|
// Only run on issue show page
|
|
const regex = /^\/issues\/\d+/;
|
|
if (regex.test(window.location.pathname)) {
|
|
|
|
//search for the span element that contains the text "Mileage" and get its parent element's class name
|
|
const allSpans = document.querySelectorAll('span');
|
|
const wantedSpan = [...allSpans].find(el => el.textContent.includes('Mileage'));
|
|
const element = wantedSpan.parentElement.parentElement.className;
|
|
console.log(element);
|
|
|
|
// Get the first child element of the element with the class name and add a click event listener to it
|
|
const firstElement = document.getElementsByClassName(element)[0].children[1];
|
|
if (firstElement) {
|
|
firstElement.addEventListener('click', function() {
|
|
try {
|
|
const text = firstElement.innerText;
|
|
|
|
// If the text is already "Copied!", don't do anything
|
|
if (text == "Copied!") {
|
|
return;
|
|
}
|
|
|
|
navigator.clipboard.writeText(text);
|
|
|
|
firstElement.innerHTML = "<b>Copied!</b>";
|
|
firstElement.style.color = "#4CAF50"; // Turn green
|
|
|
|
setTimeout(() => {
|
|
firstElement.innerText = text;
|
|
firstElement.style.color = "";
|
|
}, 2000);
|
|
|
|
} catch (err) {
|
|
console.error('Unable to copy', err);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
});
|