微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

获取并搜索“仅”悬停的链接 URL

如何解决获取并搜索“仅”悬停的链接 URL

标题所示

「 只获取搜索悬停的链接 URL 」

实现这一目标需要哪些修正?

// Pattern1⃣ Malfunction
// ① Opens all URLs that contain the specified word,regardless of mouse over target.
// ② Opens with or without mouSEOver.
var ele = document.querySelectorAll(".centerarticle-entry-title a");
var link = ['Loading...','Dance Party'];
var L = window.onload = function(load) {
    window.addEventListener('keydown',(e) => {
        if (e.ctrlKey && e.keyCode === 13) { // CTRL + ENTER
            for (let i = 0; i < ele.length; i++) {
                for (let j = 0; j < link.length; j++) {
                    if (!link.onmouseenter) {
                        e.stopPropagation();
                    }
                    if (ele[i].innerHTML.match(link[j])) {
                        ele[i].innerHTML.match(link[j]).onmouseenter = window.open("https://web.archive.org/web/" + ele[i].href);
                        L = undefined;
                        ele[i].onmouseenter = undefined;
                        ele[i].onmouseenter = null;
                    }
                }
            }
        } else {
            ele[i].onmouseleave = e.preventDefault();
            return false;
        }
    });
};

在Pattern1⃣的情况下,这在另一个意义上是实用和方便的,但是我们这次要实现的功能与Pattern1⃣不同。

你要实现的功能是 「 获取搜索悬停的链接 URL "only" 」 我很讲究。

我已经创建了一些其他原型,但它们更不实用,因为Pattern 1⃣的版本更糟糕或者搜索结果为空。

// Pattern2⃣ Malfunction
// ① Opens all URLs that contain the specified word,regardless of mouse over target.
// ② There is a 'case' that opens even if you don't mouse over.
// ③ In some cases,nothing responds in the first place,in which case you need to do a super reload etc. each time.
// ④ The number of times you pressed the ENTER key to the sky may have accumulated. Alternatively,the number of hovering times can be accumulated as it is. That possibility can open duplicate TABs unnecessarily.
var ele = document.querySelectorAll(".centerarticle-entry-title a");
var link = ['Loading...','Dance Party'];
document.addEventListener('mouseenter',(m_enter) => {
    document.addEventListener('mouseleave',(m_leave) => {
        m_enter.preventDefault();
        e.preventDefault();
        return false;
    });
    window.addEventListener('keydown',(e) => {
        if (!(e.ctrlKey && e.keyCode == 13)) {
            m_enter.preventDefault();
            return false;
        }
        if (e.ctrlKey && e.keyCode == 13) {
            for (let i = 0; i < ele.length; i++) {
                for (let j = 0; j < link.length; j++) {
                    if (ele.innerHTML.match(link[j])) {
                        link[j].onmouSEOver = window.open("https://web.archive.org/web/" + ele[i].href);
                        location.reload();
                        break;
                    }
                }
            }
        } else {
            return false;
        }
    });
});


// Pattern3⃣ Malfunction
// ① Opens only one (probably top) URL that contains the specified word,regardless of whether you hover your mouse over the target.
// ② Opens with or without mouSEOver.
var ele = document.querySelectorAll(".centerarticle-entry-title a");
var link = ['Loading...','Dance Party'];
window.addEventListener('keydown',(e) => {
    if (e.ctrlKey && e.keyCode === 13) { // CTRL + ENTER key
        for (let i = 0; i < ele.length; i++) {
            for (let j = 0; j < link.length; j++) {
                if (ele[i].innerHTML.match(link[j])) {
                    link[j].onmouSEOver = window.open(("https://web.archive.org/web/" + ele[i].href));
                    return false;
                }
            }
        }
    }
});


// Pattern4⃣ Malfunction
// ① Opens with or without mouSEOver.
// ② Search results are empty or "undefined"
var ele = document.querySelectorAll(":hover");
var link = ['Loading...',(e) => {
    if (e.ctrlKey && e.keyCode == 13) {
        link.onmouseenter =
            window.open("https://web.archive.org/web/" + this.href);
        return false;
    }
});

实际的实验目标页面如下。

https://b.hatena.ne.jp/search/tag?q=bookmarklet&page=67

请告诉我,

解决方法

<a href="https://google.com">Google</a>
<a href="https://yahoo.com">Yahoo</a>
<script>
document.onkeydown = () => {
  const link = document.querySelector('a:hover')
  if (link) window.open(link.href)
}
</script>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。