Is there a better javascript algorithm for constantly checking a condition? Some websites have never-ending scrolling like twitter, where every time you scroll down, new content comes up. I want to modify the html inside the content that keeps appearing every time you scroll. To do that, I have a recursive function that constantly changes those content every second. For those of you who don't understand what I'm saying, imagine pressing a button to turn something on. The machine checks if the button is pressed, then checks if the button is pressed, then checks if the button is pressed, then oh hey it's pressed, do something, then check if the button is pressed, check if the button is pressed...etc. There's definitely a less naïve way to do this with javascript, but I'm not sure how. I don't think there's event listeners that checks if new content has been loaded after scrolling down.
Here's an example of code I use to make everyone's username on QC the same color: ```javascript function setSameUsernameColor(){ for(let i=0;i< document.getElementsByClassName('user-link username').length;i++){ if(document.getElementsByClassName('user-link username').style.display != "none"){ document.getElementsByClassName('user-link username').setAttribute('style','color:darkorange!important;'); } } setTimeout(setSameUsernameColor,1000); } ``` As you can see, I'm recursively calling the function every second to check if a username's color is orange, and if it is, change it. This is running forever.
How do you do this?
I finished, but how do you get it to work?
OOOF, it worked.
I use tampermonkey extension to inject javascript into webpages. if you just want to test it, you can do inspect-element, then copy-paste it into the console. @CoolRekterizer
Warning: scam warning... ooof idk y it says that
the part where you press "F12"
into the console
|dw:1569526631542:dw| wot?
ok, so i just click install when i click "raw" although i dont see install
Oh you mean for my github. You have to install tampermonkey extension first.
whats the link?
I got tampermonkey, now what?
now just click the raw button, and it should bring up a prompt to install it: https://github.com/mchappychen/Simplify-QuestionCove/blob/master/SimplifyQC.user.js Tampermonkey is an extension so you can disable it on the top right, or just uninstall the extension
i installed the function, now what?
its working OOOF
My webpage doesn't look exactly like yours because I use uBlock Origin to block user avatars.
ooooooooooh ok
lol if you want me to add/change something you can tell me and I'll see if I can do it
What other things do you have that are AWESOME?
Well I made this to make reading wikipedia easier: https://github.com/the-beef-organization/Wikipedia-Easy-Read other extensions I've made are kinda offensive to some people lol, idk if u wanna see it. It removes news from google searches
I really dont care.
Lemme try some.
I msged u so other people can't see it
ok
Join our real-time social learning platform and learn together with your friends!