Greasy Fork is available in English.

Обговорення » Розробка

how to load script on dynamically loaded menu on bing?

§
Опубліковано: 23.06.2016

how to load script on dynamically loaded menu on bing?

bing results have a dropdown menu to filter results by date. I want to change the default date to a year ago. The menu for changing the date only loads when you click the "any time" link see here: http://www.bing.com/search?q=example
It looks like it loads by triggering some javascript.

I have code to change the date that works if I click on the "any time" link and then run the code through the console but I can't get it to run on its own in a userscript. What code would work to get the userscript to trigger when "any time" menu is loaded?

§
Опубліковано: 24.06.2016

Hmm, how about if you add a step to the script to open the menu?

When I load a search on Bing, this works to drop the menu:

document.getElementById("h5091").click();

Possibly the ID of that element changes. In that case, you could try a less direct route to it:

document.querySelectorAll("#b_tween a")[0].click();

That targets the first link in div#b_tween which I assume is stable.

Otherwise:

You would need to add a mutation observer to the page to watch for the introduction of the menu items as a new element which seems like more work than it's worth in this case.

§
Опубліковано: 26.06.2016

thanks! i'll take a look at it and see if it will work for me.

Опублікувати відповідь

Sign in to post a reply.