gpt4 book ai didi

javascript - 如何为点击 Chrome 网页中特定链接的自动点击器编写代码

转载 作者:行者123 更新时间:2023-11-29 17:53:13 25 4
gpt4 key购买 nike

所以,我的编码背景很少,因此完全不知道如何处理这个问题。

我正在尝试浏览 Fortune Tech阅读 2016 年大部分时间的新闻,滚动到末尾时会出现一个链接,您需要单击该链接才能查看更多头条新闻。它说“查看更多技术头条”。我想以某种方式使这个过程自动化,就像我向下滚动一样,它会自动加载下一组标题,而无需我点击那里。我该怎么做?

最佳答案

我可以帮助您入门。您需要下载扩展 Tampermonkey所以你可以自动将代码注入(inject)网页。这是您希望在自定义脚本中包含的代码。

// ==UserScript==
// @name Fortune Tech Auto Click
// @author Some Random Guy On The Internet
// @include http://fortune.com/tech/
// @include http://someothersite.com/*
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js
// ==/UserScript==

(function() {
'use strict';

$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() == $(document).height()) {
if (document.location.href.search('fortune.com/tech') !== -1) { // This will run only on the fortune tech site
$("#section-see-more").trigger("click");
}else if (document.location.href.search('someothersite.com/*') !== -1) { // this will run on the someother.com/* site
// Selector of the button.
$("#other-button-id").trigger("click");
}
}
});

})();

您可能需要稍微尝试一下才能使其正常工作。

编辑以更好地适应下面的评论。

关于javascript - 如何为点击 Chrome 网页中特定链接的自动点击器编写代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41452797/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com