« first day (3175 days earlier)      last day (1777 days later) » 

1:04 PM
x = document.getElementsByClassName("stopWatch_time_now");
setTimeout(function(){ alert("stopwatch hit the targeted time"); }, x);
is it possible to use setTimeout in this way ?
 
Njet. x has to be a number
 
ok how else i can do this without using a while loop?
 
@JRick you can save what gets returned from setTimeout as a timer id which can be canceled
 
@JRick What is "this" exactly? Stopping the timer or displaying the 20 seconds thingy?
 
@geisterfurz007 yea , checking if timer have reached a certain time
@Neil that is possible but what if when a user stop the stopwatch it didnt stop for whatever reason and the setTImeout kept running , that would screw everything up
 
1:08 PM
@JRick Ok, so you have a function that increases a thingy each time, right?
 
i think it's safer to just keep checking the value of the timer every certain period of time
@geisterfurz007 yea
basically it's a stopwatch
locally hosted
 
What stops you from checking if that value exceeds another value?
 
@geisterfurz007 the trigger
 
the function itself runs but only 1 time
i need to (keep) checking the value of "x" for example
 
1:11 PM
You also need to KEEP increasing the value of x.
 
while loop sometimes Crashes the browser/pc if there was an error
 
So why not do both at the same time?
 
@geisterfurz007 increaseing the value of x is not a problem
 
Mhm.
But checking it is?
 
like if timer = 10 sec // do something
if not keep checking
 
1:13 PM
let x = 15;
let limit = 18;

function doesStuff() {
  x++;
  //why don't you check here?
}
Stuff in setInterval doesn't have to be just one line. You are free to put more in there.
 
tata
 
@geisterfurz007 well because it interacts with an online hosted timer for a system that is kinda similar to google's that was not hosted by me
i'm just orgonizing the competition for the company through out an extention so i can't really edit their system
 
At some point you have to know the amount of seconds passed to display them. At that point you can check if exceeds the given limit.
 
i know
that is what i said
 
1:19 PM
Ye, I didn't understand any of that, sorry :D
I really don't understand your problem :/
 
when i practice it locally sometimes it crashes ( using while loop ) can break the entire browser
 
Did you check the fiddle?
 
ok let me make it simipler , lets say im making an extention that is based on google's stopwatch ( just so we both can check it out) what function i use to keep checking if the stopwatch is working and time haven't hit the target yet ( lets say target = 20 sec ) ?
@geisterfurz007 of course , the problem with the code that if user have paused ( the stop watch ) the function will keep going regardless
so i kinda need to loop over the value of the timer to see if user hit the target or not
 
Well, you can stop and start it again if needed
You can throw an additional listener on the pause button for example.
Alternatively you can use the same setInterval thing on the element displaying the current stopwatch time to check every second or every 100ms, read and parse the content of said element and use that value.
 
that would work but only if the stopwatch stopped and worked once user click on the pause and continue buttons on the stopwatch but what if there was a bug ?
 
1:24 PM
If I understood that correctly.
 
@yes second option is what iam interested in
but how ?
 
Google stopwatch as example, you say?
 
How I can piblish all packages inside my node_modules to some other folder
 
Let's use this one: online-stopwatch.chronme.com
As an example, ok?
 
how i can publish
 
1:27 PM
i don't want to use while loop because if there is a bug it may crash the browser
yes
 
@geisterfurz007 yes whatever any stop watch will work
 
that's an extended version of the previous
you can "pause" the timer
 
@JRick Good, we'll use mine then, because your link doesn't show a stopwatch to me.
:D
Using your devtools (F12 in Firefox; unsure about Chrome, but I think it might be the same), you can select the element on the page that displays the time:
Ideally, it has an id already ("disp") in this case. Otherwise you gotta figure out some way to access that specific element (like certain css classes, etc). Once you've done that, you can go ahead and do the following (might take a moment, hang on)
 
@Neil that is amazing , thank you so much but I don't think it will be safe using this method , as the extension may stop but the online stopwatch might keep going or the vise versa if internet connection interupted or something
we must keep using some sort of a loop to keep checking the value
 
1:32 PM
@JRick if you want the counter to continue even when the browser is down, then you need a backend
basically the same example that I give, except the timestamp is on the server somewhere
 
@geisterfurz007 thank you so much , sure take your time
@Neil dude that is not the point , we can stop the function in the extension during the internet interruption or server down or something then but we can't stop the hosted stop watch
so one of them might screw up
i rather keep checking the time every 100 ms or soemthing locally
if it reaches the target the code excuted
 
no, you'd download once from the server the current time
and then the browser would deal with counting up from there
you only need to talk to the server again when you want to stop the time
depending on how specific you want to be, you'd also have to take into account latency from the browser to the server
 
@Neil that is the point i can't talk to the server , otherwise they wont as me to build an extention for them
 
@JRick ok, so let me get this straight. Only server knows what is the current timer.. but you can't talk to that particular server..
how do you think this is going to work?
 
setInterval(() => {
  const element = document.getElementById("disp");
  const time = element.value;
  //get the part we want
  const match = /(?:\d+:){2}(\d+).*/;
  const seconds = Number(match.exec(time)[1]);
  console.log(seconds); //Or check if >20 seconds
}, 1000);
 
1:38 PM
@Neil you are right latency might be a problem too
 
If you paste that into the console here and run it, you should be able to read the seconds in the console when you start the stopwatch
(This does fail after more than a minute but it's just for demo)
Hoping that I understood what you want correctly.
 
Does anyone know if its possible to run a specific Javascript snippet if a public IP is what I specify? Like I want the server to only run specific JS if my Public IP joins.
 
@geisterfurz007 that works GREAT!!! thanks alot !!!
@Neil that is the best out of all others
 
You're welcome! I hope you are able to pull this off with whatever you plan on adding this on :)
 
@geisterfurz007 MutationObserver ...
 
1:43 PM
How do I even get a public IP
3
 
@TaylorSpark Check the headers for x-forwarded-for and client-ip
 
@KarelG Is that really more efficient? If you only want seconds for example, you don't need a MutationObserver telling you something's changed in the last millisecond.
 
per say... how do I detect PUBLIC Ip addresses like whatismyip.com and then detect IF the IP is Blah.Blah.Blah and then run a specific function(s)
@BenFortune Can ya give me a console command to check for public IP? I can make a detection function from that
 
sir, slow down
 
what
 
1:45 PM
I like the console command structure, it makes it easy to convert it to a function.call()
 
omg it's towc
how are you buddy?
 
mostly liquid, with these termperatures
 
omg it's towc ._.
 
did I do something to you? :/
 
@BenFortune Checked for x-forwarded-for and client-ip in the command list / function list built into chrome. Only thing I could see was clientInformation
 
1:47 PM
That's not what I said
 
can you give me a snippet of how to atleast grab the public ip
 
You want to get your IP from client-sided JavaScript?
 
chrome itself doesn't provide you the public ip
 
you'll need to send a request somewhere that responds with your IP
 
1:48 PM
You need to do an AJAX request to something that can serve you the IP
 
I want to detect if the client-ip is "blah.blah.blah" or whatever to run a script (basically I want to detect if the owner of the page is on so only I have access to debug areas of the site)
I dont know much of ajax lol
also its a static site. I cant do php
 
I wouldn't do it at all
 
is it impossible to do with just JS
 
yes
you need a server
 
You know that anyone can modify it to bypass it anyway
Very easily
 
1:49 PM
sigh kinda expected that I guess
Yeah i know, but its just a show of concept
nothing I make is passionately built to do its job to the best extent, like the few anticheats I made were like I said, Just show of concept, and were easily burnt through
Most of my stuff is on github pages, so people can just view its source in the first place lol
 
560
Q: How to get client's IP address using JavaScript?

FlySwatI need to somehow retrieve the client's IP address using JavaScript; no server side code, not even SSI. However, I'm not against using a free 3rd party script/service.

 
Oh lovely another question that didnt come up when i used the search bar
 
hmm maybe you can use WebRTC tho
 
^
Works surprisingly well if it's actually supported
 
That answer is very interesting, alot of options, EXCEPT... All do about 2 requests per second OR WAY MORE... and pull out wayy more info than i need, I only need the IP address.
 
1:54 PM
@towc You care about me ;-;
 
@geisterfurz007 don't get too emotional now
 
No worries.
 
Perfect
 
1 message moved to Trash can
@TaylorSpark Please don't post unformatted code - hit Ctrl+K before sending, use up-arrow to edit messages, and see the faq.
 
Wow people answer better than i expected
OOps forgot that js snippet
 
1:55 PM
oh, if only you were able to google use a search engine
 
I hate google lol
So much garbage and youtube ads and fake websites... its just tiring sometimes
 
Use ecosia! shameless plug
 
Ok, so im using IPify, but 1 issue, it returns a text output
$.getJSON('https://api.ipify.org?format=jsonp&callback=?', function(data) {
  console.log(JSON.stringify(data, null, 2));
});
Is there a way to seperate that into a value? of just the ip?
and... NOT place it in the html
 
yes
 
Right now it just returns {"ip":"12.12.123.12"} (fake ip btw)
and places it as a text in the html
Nevermind... "$" is not defined
Im assuming I need jquery to run this script then?
 
2:01 PM
if you couldn't notice, people are ignoring you because you could search much more than you are, and you're tiring to deal with
that said, you're welcome to hang out and ask questions
but lower your expectations
 
I dont have any expectations
 
great
 
Yeah, that's too many
 
nice
 
Honestly Ive heard people say im forcing them to answer my questions, Yet I am not?
 
2:02 PM
Just use fetch
 
the people that hang out here feel compelled to help
 
fetch? Sorry still trying to understand https atm
 
a common issue is people abusing that
@TaylorSpark ecosia it
 
@TaylorSpark you don't need jQuery. It just request a json response from a server (in that situation, ipify.org)
 
lol that still makes 0 sense, im sorry. For some reason I have a hard time understanding the simple "definitions of things" and rather I try looking at actual code
Oh
 
2:04 PM
95% of coding is understanding things
 
just use Fetch API, get the response, parse it into an object and read the ip key
 
and nobody asked you to look at definitions
 
Well for some reason the request it doesnt log the valye
 
just use https://api.ipify.org/?format=json
 
@KarelG Can you help me out here? Sorry if im rather slow, like I said I dont understand the parsing and responsing, rather I just go off of actual code...

So uhh, do you perhaps maybe have an example code?
Parents call me a tactile learner, they say I learn by seeing what others make and editing it myself..
 
2:07 PM
it is just
 
I understand that this is getting the json:
$.getJSON('https://api.ipify.org?format=jsonp&callback=?', function(data) {
 
fetch('https://api.ipify.org/?format=json')
  .then(response => response.json())
  .then(obj => obj.ip)
  .then(ip => console.log(`my ip is ${ip}!`));
 
the fetch function is built into js correct? or do I need a seperate API for that too lol
 
built into
 
ok, awesome
 
2:08 PM
KarelG. The G stands for "Great coder, nice, friendly and always ready to help"
 
Hmm for some reason it doesnt identify, im no longer getting fetch errors, but its not showing the HTTPS request in the console, and isnt logging the 'my ip is ${ip}!' piece.
Javascript can be quite vague sometimes. It works on some occasions, and other times doesnt work and has NO rendering problems or console errors, making it seem like it doesnt exist.
@KarelG Am I missing something or am I too slow to get why it isnt logging lol
 
what do you mean?
I just tried that and it gives me the ip
 
Hmm it seems the console wasnt rendering correctly, chromes console wont render it. Yet the console in codepen and jsfiddle did.
strange.
 
... I tried that in chrome.
don't spark me boi 😛
 
So if I made a script like this and called the variable "ip", then it should print a raw text of the IP.
document.getElementsByid("thing").innerHTML = ${ip};
replacing ${ip} with simply ip didnt work either
fricking Element(s), me and my spelling errors
 
2:15 PM
 
Yeah, don't use template literals outside of backticks, but yeah, typo
 
So how would I call the json variable "ip" outside of its function
document.getElementByid("thing").innerHTML = ip;
doesnt recognize "ip" as a variable
 
You'll have to assign it to a higher scoped variable
Since you said JSON variable, is it safe to assume it's coming from an async method?
 
@KarelG I rewrote your final function to an innerhtml replacer, and it didnt function correctly
.then(ip => document.getElementByid("thing").innerHTML = ${ip};
 
don't use those ${} there
 
2:17 PM
or does it not work that way lol. It seems to work with console.log perfectly
I tried it without ${} already
 
that is for with the backticks (template literal). Just use the variable itself
 
didnt show up in the html
 
that ip gives you a string
shrug
 
final code
fetch('https://api.ipify.org/?format=json')
  .then(response => response.json())
  .then(obj => obj.ip)
  .then(ip => document.getElementByid("thing").innerHTML = ip;
 
You're missing a closing ) on the then function
 
2:18 PM
Nope, still not recognizing the <a id="thing"></a> tag
Oh no im not, I didnt copy the whole thing by accident
Wups.
does it not support innerHTML?
 
that should work. And use .textContent the next time.
no console errors?
and yoour getbyId is incorrect as well
 
Here is an online Ternary to If-Else converter - converter.website-dev.eu - does anyone know of an If-Else to Ternary converter?
 
can you not do it manually?
 
FINALLY
fetch('https://api.ipify.org/?format=json')
  .then(response => response.json())
  .then(obj => obj.ip)
  .then(ip => document.getElementById("thing").textContent = ip)
that seemed to do it... apparently innerHTML doesnt like the code, I changed it to textcontent and it finally showed up
I can work with that
Thanks
 
Hi Sterling
 
2:21 PM
Well, innerHTML would have worked, but getElementByid isn't a function
 
I had an Archer face at that moment tho ^
 
but textContent is indeed better
@KarelG hai :D
 
Oh, it probably autofixed it to capital Id when i refreshed LOL. My editor tends to do small fixes like that which i appreciate
anyone else use visual studio code
I love the dark theme mixed with their syntax highlighting
 
@TaylorSpark I've used it a bit, mostly for PowerShell stuff
since the PowerShell ISE is not developed anymore
 
I find it useful for making websites/github pages. having it as the main editor, along with github desktop, and your repo / github page open in chrome. its the perfect editing solution honestly.
it has that awesome plus feature of the folder structures... Its unfortunate it doesnt have built in formatting features for squished code
PowerShell... honestly I dont even have it on my computer, I thought its supposed to be built in, but isnt it like a "better" version of the original shell cmd.exe for windows? I find cmd.exe easier to use
Hey I was wondering if anyone knows how to append css filters to images in a way that allows them to be saved WITH the filters on them?
Like this bookmarklet allows you to invert the colors of websites and iframes. Problem is, if you try to save any of the images without using a snipping tool, it doesnt really save them correctly. hatebin.com/dfmadkqlrb
Just saves them when they didnt have the filter
Rip, Im always ignored.
 
2:35 PM
@TylerH I like PS but eventually I have a feeling that it is somewhat garbage
well, when comparing to bash
especially when piping ... if you want to process it, you have to use ForEach-Object
that takes time to write. And accessing the supplied object? Did you see that monstrosity ?
 
Why use powershell in the first place, stick with bash or any basic shell program
 
@0xPrateek Welcome to the JavaScript chat! Please review the room rules. If you have a question, just post it, and if anyone's free and interested they'll help. If you want to report an abusive user or a problem in this room, visit our meta.
 
this $_ ... 🤨
I want to b-slap the person that came with this idea with my plastic axe
@TaylorSpark no windows env?
 
env?
Does not compute...
 
2:39 PM
then you are not a shell guy.
 
oh environment
nvm
I only do basic bash/shell commands for my personal use (Python/php mini webservers, large scale website shortcuts, large scale .bat runnings (useful when using decryption programs on multiple folders))
 
@KarelG Which feels like "something garbage" comparing to python scripts..
I'm honestly waiting for a linux distro which use python shell as its native shell.
 
If your wondering about the decryption stuff, I work with some cemu (wiiu emulator) files and tend to find game files encrypted as useless .h3 and .app files (You cant emulate straight from those, more or less you require a wiiu executable (rpx, iso, etc))
So in shell, should I move to using python rather than JS
some say its more "efficient" in ways
I dont see how
Javascript is light and native to browser code
 
You managed to put words in such a way it creates sentences, but it still doesn't make sense at all.
 
why waiting for that? just start a py CLI
 
2:49 PM
@KarelG Is it possible to run a website purely off of Python? Honestly Ive only really ever seen python being used in browsers when in 3D Scenes or things relative to rendering
similar to how I only see JSON as a rendering tool in websites
I dont really notice python or json in website code often nowadays
mostly JS based
Like is python able to render text and colors and such things as html elements? or is it just another rendering tool.
 
@KarelG Well it ought to then make docker creation faster. Instead of either doing things in shell, or first installing python, running the scripts, uninstalling python you could do it directly in python. So it's one less "language" you have to take into account.
@TaylorSpark Flask, django (bottle).
 
oh. right
 
And if you mean "rendering" as in rendering HTML (instead of serving data): there's beautifulsoup which can render almost anything.
 
Well atleast I got a little progress, I managed to get that IP retreiver working, but now I have to figure out how to make it work with IF statements (I already tried and it didnt work too well) codepen.io/SkylerSpark/pen/RzLVKg
 
@paul23 ah right docker. The native implementation of it is a neat feature
 
2:52 PM
trying to compile a binary of a node app with zeit's pkg but it won't run on my linux sbc with 32bit architecture- any ideas?
 
so you are working with docker/kubernetes as well?
 
Yeah, isn't everyone nowadays though?
 
I wrote var ip as a public variable to make it global. And then after that i have the getip script. It gets the ip and tags it to variable ip. but when i try to detect it with an IF statement, it fails and says the value is 0 or 1
do I have to set the variable to string to it recognizes values such as 12.12.123.12
if so, how would i do that
 
@paul23 depends of the workplace.
> as a public variable to make it global.
that is something you should not do.
there are < 1% use cases for that
 
Well if I dont make it a global var, then everything that calls it outside of the script will not recoginize it
 
2:55 PM
@TaylorSpark First, using globals is a terrible practice. Secondly: you are never setting it. Thirdly that's not the way to do it in async land.
 
refactor your code then
 
var ip = 0;

fetch('https://api.ipify.org/?format=json')
  .then(response => response.json())
  .then(obj => obj.ip)
  .then(ip => document.getElementById("thing").textContent = ip)
I dont see whats wrong here
 
You ignore global, and refactor your "synchronouse code" inside the then.
 
ip is always 0 there ...
 
I thought the code below it would get ran, and would override the 0 and set it to the value of the ipify
 
2:56 PM
js is an event driven code. Don't write procedural code like in java or whatever procedural language you are using
@TaylorSpark lookup about javascript scoping
 
so is there a way to reference the ip variable outside of the fetch() script and be able to use it in an if statement like the one below:
if (ip = 12.12.123.12) {
 // do something
} else {
 // do nothing or something
}
 
 ...
 .then(ip => {
   document.getElementById("thing").textContent = ip
   //code here, "ip" is set as function parameter
   //this code is ran after the promise has retrieved data
})
//this code might run before the promise has finished (will probably if it's retrieving data from a website
 
Oh, so i should probably try placing my if statement inside of the fetch command
 
Inside the "then" where you actually "have" the ip.
 
  .then(ip => {
 document.getElementById("thing").textContent = ip
  if (ip = 12.12.123.12) {
   // do something
  } else {
   // do nothing or something
  }
})
something like that?
 
2:59 PM
Why do you have 3 "thens" though.
 
Ask @KarelG she made the code lol
  .then(response => response.json())
  .then(obj => obj.ip)
  .then(ip => {
as far as i knew they were for seperating the exit value into the base IP adress
because normally it would output like this: { "ip": "blahblahIPhere" }
@Paul23
if successful, would my code above I posted work? or would the If statement need to be somewhere else
nevermind it didnt even render the ip anymore
BaCk To ThE dRaWiNg BoArD
 
@TaylorSpark ... I hope you can see what goes wrong yourself. Otherwise the console gives a clear error message.
 
oh sorry, my console wasnt open in my editor, it takes up a bit of space
@paul23 so how do I change that to detect a string? Because obviously that fetch command is SOMEHOW able to write the variable as an Ip, yet I cant detect that same very value
 
What you did was almost correct - it's just that you shouldn't compare values the way you do in above code.
You really need to get a book about basic programming principles.
 
sadly this is more of a hobby, and my brain doesnt have the patience to tongue a book or a course on coding. Ive been teaching myself to code for the last 2 years. If I started an actual course now, it would be below my standards, but also too hard for me in areas because I think of it in a completely different manner
 
3:09 PM
if (ip = 12.12.123.12 is an assignment of .... nvm just read the above.
 
i wish people would rather give me direct answers to my problems, rather than trying to teach me what I did wrong, if i made a mistake, id compare the two and see the differences
 
The problem is: you come with really mundane things, and consistently come with the simple faults and announce them as "major dealbreakers, crimes of the world".
 
Lol that was funny
well your right
 
you're*
 
but, I have my ways of learning.
Euw grammar police
bad bad bad bad person
 
3:13 PM
It's quite tiresome to constantly explain simple things, and when you ask some more involved things it comes back to explaining the simple things again.
But to just finish it while I have to rush to the grocery store:
 
it wouldnt be tiresome if you didnt explain it to me, simply dont explain things to me, in a way, I learn by looking at things. So explaining to me to figure things out myself or give me "hints" really breaks me down mentally
 
A number in javascript is just that: a mathematic number. anything else (telephone numbers, ips mac addresses) are all "strings".
Secondly you compare equality using the === (or sometimes ==) comparison.
so the if statement would be: if (ip === "12.12.123.12")
 
oh... I forgot... strings use quotation marks
kms
see its so much simpler with simple answers lol
 
Well the problem is (again): those things are explained in any programming book/online tutorial. So the explanation/answer shouldn't even be necessary (especially since console gives the exact line where the problem occurs).
 
Maybe im just lazy and I like people doing things for me when i dont know how.... The simple answer
wait that sounded bad..
rip
 
3:23 PM
@KarelG you know you can tab complete in PowerShell?
 
3:38 PM
@TaylorSpark Aside from the fact that I'm on Windows, not Unix, I use PowerShell because cmd is inadequate (e.g. the same reason anyone uses a full scripting language vs a subset of one). PS has access to the full WinAPI and .NET library and is required for some things, like if you want to manage something in SharePoint, for example.
 
ah ok
I only use cmd.exe because its minimal and simple, easy to use with .bat and python scripts
 
Probably the biggest difference is that PS is a scripting language, not just a CLI tool
 
well yeah that too
 
although WRT Bash, PowerShell does include a lot of aliases (think ls) that work in it
 
That's why I like OSX terminal vs windows cmd
 
3:50 PM
Could anyone help me with this bit of code?
fetch('https://api.ipify.org/?format=json')
  .then(response => response.json())
  .then(obj => obj.ip)
  .then(ip => {
  if (ip === "47.35.233.45") {
   document.getElementsByClassName("a7").style.display = "initial";
  } else {
   document.getElementsByClassName("a7").style.display = "none";
  }
})
I have the error saying display none is undefined
but none is a value for display
which is why Im confused.
Im basically trying to hide an element unless the owner of the webpage is connected
is everyone afk?
AFAIK The program should be detecting none as a valid value for display
 
ElementsByClassName
 
Key letter "s" meaning multiple, it's returning a nodelist
wait
 
It returns an error even if i dont use s
s is apparently how its meant to be written
 
well, yes
but it's a collection of nodes
not one node
 
3:55 PM
does style apply to an entire nodelist?
 
And Id like to NOT have to go into all 15 of my index files and add an ID to each a7 element
 
you cant set a property on an entire collection the same way you set a property on one node.
it just doesn't work that way
 
this is my website: https://skylerspark.github.io/index.html
Im basically trying to make it so Page_Debug is hidden unless my ip joins
 
use a konami code instead
 
No idea what that is
a library?
 
3:57 PM
it's a joke
 
:/
Im not looking for jokes
 
err
no it's not
 
You're telling someone to add "up, up, down, down, left, right, left, right, B, A" to their code?
 
Someone put an upvote bot on my questions and got me question banned again for "cheating"
2
 
that or any other combination, to show/hide the debug info.
rather than an ip address check
 
3:58 PM
Yeah im not happy
Kevin, How would I even do that
Ive never made keypresses in js before
 
google.com is quite useful for finding things
 
omfg I thought this was a place for finding things
 
we aren't going to use google for you
3
 

« first day (3175 days earlier)      last day (1777 days later) »