js定制查找元素并替换链接代码
<script>
/*修改video标签直接跳转*/
let attemptCount = 0;
const maxAttempts = 30;
const intervalId = setInterval(() => {
attemptCount++;
// 选择两个元素
const element1 = document.querySelector('#menu-item-2798 > div > a');
const element2 = document.querySelector('#nv-primary-navigation-sidebar > a');
// 如果找到两个元素
if (element1 && element2) {
element1.href = 'https://';
element1.target = '_blank';
element2.href = 'https://';
element2.target = '_blank';
clearInterval(intervalId);
} else if (attemptCount >= maxAttempts) {
clearInterval(intervalId);
}
}, 100);
</script>