Ask your own question, for FREE!
Miscellaneous 17 Online
mhchen:

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.

mhchen:

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.

CoolRekterizer:

How do you do this?

CoolRekterizer:

I finished, but how do you get it to work?

CoolRekterizer:

OOOF, it worked.

mhchen:

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

CoolRekterizer:

Warning: scam warning... ooof idk y it says that

CoolRekterizer:

the part where you press "F12"

CoolRekterizer:

into the console

mhchen:

|dw:1569526631542:dw| wot?

CoolRekterizer:

ok, so i just click install when i click "raw" although i dont see install

mhchen:

Oh you mean for my github. You have to install tampermonkey extension first.

CoolRekterizer:

whats the link?

CoolRekterizer:

I got tampermonkey, now what?

mhchen:

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

CoolRekterizer:

i installed the function, now what?

CoolRekterizer:

its working OOOF

mhchen:

My webpage doesn't look exactly like yours because I use uBlock Origin to block user avatars.

CoolRekterizer:

ooooooooooh ok

mhchen:

lol if you want me to add/change something you can tell me and I'll see if I can do it

CoolRekterizer:

What other things do you have that are AWESOME?

mhchen:

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

CoolRekterizer:

I really dont care.

CoolRekterizer:

Lemme try some.

mhchen:

I msged u so other people can't see it

CoolRekterizer:

ok

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!