Dynamically find mileage element
This commit is contained in:
@@ -1,8 +1,17 @@
|
|||||||
$(function() {
|
$(function() {
|
||||||
|
// Only run on issue show page
|
||||||
const regex = /^\/issues\/\d+/;
|
const regex = /^\/issues\/\d+/;
|
||||||
if (regex.test(window.location.pathname)) {
|
if (regex.test(window.location.pathname)) {
|
||||||
const firstElement = document.getElementsByClassName('int_cf cf_4 attribute')[0].children[1];
|
|
||||||
if (firstElement) { // Check if the element exists
|
//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() {
|
firstElement.addEventListener('click', function() {
|
||||||
try {
|
try {
|
||||||
const text = firstElement.innerText;
|
const text = firstElement.innerText;
|
||||||
|
|||||||
Reference in New Issue
Block a user