ssborbis / ContextSearch-web-ext

Search engine manager for modern browsers
337 stars 37 forks source link

How to click? #679

Open StrollStars opened 7 months ago

StrollStars commented 7 months ago

site: https://magnet.pics/ Post-Search Script:

let input = document.querySelector('[class="magnet-input"]'); input.value = searchTerms; input.dispatchEvent(new Event("input")); document.querySelector('[class="preview-button"]').click();

It cannot directly generate search results, manual clicking of the search button is required. How can the code be modified?

StrollStars commented 7 months ago

@7peanuts 可否帮忙看下?

ssborbis commented 7 months ago

Try bubbling the event. I can't tell if this works without a test URL, but ...

document.querySelector('[class="preview-button"]').dispatchEvent(new MouseEvent('click', {bubbles:true}));
7peanuts commented 7 months ago

下面这个可以

  let input = document.querySelector('.magnet-input');
  input.value = searchTerms;
  input.dispatchEvent(new Event("input", {bubbles:true}));
  document.querySelector('.preview-button').click();

这是搜索结果页面 https://magnet.pics/m/8c5dece7a72036bbf2ad664fc51fb7e76387e002 磁力链接取 hash 参数,可以用正则提取出来。 (不过感觉没啥用啊,预览图就一张,看了等于没看😂)

@ssborbis This website can view screenshots of magnetic links. magnet:?xt=urn:btih:8c5dece7a72036bbf2ad664fc51fb7e76387e002&dn=Marvels+THE+AVENGERS

StrollStars commented 7 months ago

@ssborbis I also found a test URL online, you can try this one: magnet:?xt=urn:btih:6214a4304a40da9007863701d1a87125dc47f2b3

@7peanuts 嗯,我也发现了就是哈希值,只是我会正则不会脚本😂 这个取决于网站的磁链信息搜集程度吧,你那个有点奇怪,试试这个:magnet:?xt=urn:btih:6214a4304a40da9007863701d1a87125dc47f2b3

另外你再看看这个网站该怎么写:https://metaso.cn/

let input = document.querySelector('[class="search-consult-textarea search-consult-textarea_search-consult-textarea__kjgyz"]'); input.value = searchTerms; input.dispatchEvent(new Event("input")); document.querySelector('[class="MuiButtonBase-root Mui-disabled MuiIconButton-root Mui-disabled MuiIconButton-sizeMedium send-arrow-button css-tqe64j"]').click();

顺便问下,元素的确定是不是只要有一个唯一的就够了,不用全放上去?

ssborbis commented 7 months ago

bubbling all the events seems to work for me

let input = document.querySelector('[class="magnet-input"]');
input.value = searchTerms;
input.dispatchEvent(new Event("input", {bubbles:true}));
input.dispatchEvent(new Event("change", {bubbles:true}));
document.querySelector('[class="preview-button"]').dispatchEvent(new MouseEvent('click', {bubbles:true}));

image

StrollStars commented 7 months ago

@ssborbis Thank you for your help, but testing input.dispatchEvent(new Event("input", {bubbles:true})); is work. Can you take another look at https://metaso.cn/ for me?

7peanuts commented 7 months ago

@ssborbis Thank you for your help, but testing input.dispatchEvent(new Event("input", {bubbles:true})); is work. Can you take another look at https://metaso.cn/ for me?

火狐上可用,mataso 这个我也不会

StrollStars commented 7 months ago

@ssborbis Could you help me?

ssborbis commented 7 months ago

@StrollStars

I'm having trouble accessing that site. I'll check again later

StrollStars commented 6 months ago

@7peanuts 麻烦帮忙看下 https://24hbook.com/ 如何模拟按Enter键?

7peanuts commented 6 months ago

@7peanuts 麻烦帮忙看下 https://24hbook.com/ 如何模拟按Enter键?

这样吧,输入不显示的用 bubbles 试试

(async() => {
  let input = document.querySelector('input.chakra-input.css-1ndqqtl');
  input.focus();
  await new Promise(r => setTimeout(r, 500));
  input.value = searchTerms;
  input.dispatchEvent(new Event("input", {bubbles:true}));
  input.dispatchEvent(new Event("change", {bubbles:true}));
})();
StrollStars commented 6 months ago

@7peanuts 确实可用,不过我发现你的类与我的不同,我这边是class="chakra-input css-1cjy4zv"。 再请教下,这里是两个类对吧?可为什么我只用其中一个不起作用,需要用两个,搜了下两个类都是唯一的。

7peanuts commented 6 months ago

再请教下,这里是两个类对吧?可为什么我只用其中一个不起作用,需要用两个,搜了下两个类都是唯一的。

不知道,刚看了下我这边的也变了,但是还能用。 说实话,我太懒了,两年了仍然没开始学编程,打算润色一下的中文翻译才完成 25% 😀

StrollStars commented 6 months ago

再请教下,这里是两个类对吧?可为什么我只用其中一个不起作用,需要用两个,搜了下两个类都是唯一的。

不知道,刚看了下我这边的也变了,但是还能用。 说实话,我太懒了,两年了仍然没开始学编程,打算润色一下的中文翻译才完成 25% 😀

那很奇怪啊,我直接拿来不能用,改了类才行。 在你们眼里JS不算编程…… 我Python看完了,发现还是不会,JS看了菜鸟的没啥感觉,你有没有啥由浅入深的推荐下?要求不高,能写这个扩展的脚本就行,比如你的代码里,事件那个没懂。

StrollStars commented 4 months ago

@7peanuts 天工AI发送后还需要按一次键盘才能点搜索按钮,脚本应该怎么写?

7peanuts commented 4 months ago

这还得登录😅,下面这个能用,应该可以简化一下,你可以简化一下。

(async() => {
  let input = document.querySelector('.el-textarea__inner');
  input.focus();
  await new Promise(r => setTimeout(r, 100));
  input.value = searchTerms;
  input.dispatchEvent(new Event("input"));
  input.dispatchEvent(new Event("change"));
  document.querySelector('.i-search-text').click();
})();
StrollStars commented 4 months ago

@7peanuts 可用,谢谢。 搜索还是可以直接用的,下面就都需要登录了。😅