How to get address/location of a random person on omegle? [closed] - javascript

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
Omegle is a platform to connect with random persons. I want to get the location of each random person I connect with on Omegle.

THIS IS JUST FOR EDUCATION PURPOSE
You need an API that can give the address based on the IP address. Go to https://ipgeolocation.io/, free signup, get the key, and replace in below code at YOURKEY in URL.
Goto https://www.omegle.com/, open developer options, paste the code into the console. You will the address of each person connected.
window.oRTCPeerConnection = window.oRTCPeerConnection || window.RTCPeerConnection;
window.RTCPeerConnection = function(...args){
const pc = new window.oRTCPeerConnection(...args);
pc.oaddIceCandidate = pc.addIceCandidate;
pc.addIceCandidate = function(iceCandidate, ...rest){
const fields = iceCandidate.candidate.split(" ");
console.log(iceCandidate.candidate);
const ip = fields[4];
if (fields[7]==="srflx"){
getlocation(ip);
}
return pc.oaddIceCandidate(iceCandidate, ...rest);
};
return pc;
}
const getlocation = async(ip) =>{
let url = `https://api.ipgeolocation.io/ipgeo?apiKey=YOURKEY&ip=${ip}`;
await fetch(url).then((response)=>
response.json().then((json) => {
const output = `
.............................
Country: ${json.country_name}
State: ${json.state_prov}
City: ${json.city}
District: ${json.district}
LAT/LONG: (${json.latitude} , ${json.longitude})
provider: ${json.isp}
..................................`;
console.log(output);
})
);
};

Related

Need help creating separate variables from these 2 objects in the arrays [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 months ago.
Improve this question
// I wanted to create a variable to hold the month and a variable that hold the number...
var finances = [
['Jan-1999', 867886],
['Feb-1999', 984653],
['Mar-1999', 322012],
['Apr-1999', -69417],
['May-1999', 310503],
['Jun-1999', 522857],
['Jul-1999', 1033096],
['Aug-1999', 604885],
['Sep-1999', -216386],
['Oct-1999', 477532],
['Nov-1999', 893810]];
What you need is map() that returns a new array with the result of a function applied to your initial array. In this case your functions would either select the first element of the subarray (the date), or the second element (the number).
var finances = [
['Jan-1999', 867886],
['Feb-1999', 984653],
['Mar-1999', 322012],
['Apr-1999', -69417],
['May-1999', 310503],
['Jun-1999', 522857],
['Jul-1999', 1033096],
['Aug-1999', 604885],
['Sep-1999', -216386],
['Oct-1999', 477532],
['Nov-1999', 893810]];
const dates = finances.map((e) => e[0]);
const numbers = finances.map((e) => e[1]);
console.log(dates);
console.log(numbers);

How to find keys from undefined schema [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 months ago.
Improve this question
Suppose I have following array
array = [
{
optionA: "QA1",
optionB: "QB1",
optionC: "QC1",
optionD: "QD1",
},
{
optionA: "QA2",
optionB: "QB2",
optionC: "QC2",
optionD: "QD2",
optionE: "QD2",
},
{
optionA: "QA3",
optionB: "QB3",
}
]
Expected output
tableHeader = {OptionA,OptionB,OptionC,OptionD,OptionE}
Wanted display questions data in a table format, which is not organised and has n number for options.
You can get all keys as follows
const array = [{optionA: "QA1",optionB: "QB1",optionC: "QC1",optionD: "QD1",},{optionA: "QA2",optionB: "QB2",optionC: "QC2",optionD: "QD2",optionE: "QD2",},{optionA: "QA3",optionB: "QB3",}]
const allKeys = Object.keys(Object.assign({}, ...array))
console.log(allKeys)
Try this one
let header = new Set();
array.forEach((a) => {
Object.keys(a).forEach((item) => {
header.add(item);
});
});
console.log(header);

Javascript sorting array by partial string [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I have an array like this
var myArray = [
"J20J205147902_B_B716202",
"R20Q205147902_F_B716202",
"P20W205147_902_alternate1",
"M20K205147_902_alternate4",
"F20G205147_902_alternate3",
"K20J205147_902_alternate2",
"L20H205147_902_main"];
I want to sort this array by this pattern
var map = {
"_F_":1,
"_main":2,
"_alternate1":3,
"_alternate2":4,
"_alternate3":5,
"_alternate4":6,
"_alternate5":7,
"_B_":8
};
So, the output should be like this
"R20Q205147902_F_B716202",
"L20H205147_902_main",
"P20W205147_902_alternate1",
"K20J205147_902_alternate2",
"F20G205147_902_alternate3",
"M20K205147_902_alternate4",
"J20J205147902_B_B716202"
You can use a custom sorting comparator function as follows:
var myArray = [
"J20J205147902_B_B716202",
"R20Q205147902_F_B716202",
"P20W205147_902_alternate1",
"M20K205147_902_alternate4",
"F20G205147_902_alternate3",
"K20J205147_902_alternate2",
"L20H205147_902_main"];
var map = {
"_F_":1,
"_main":2,
"_alternate1":3,
"_alternate2":4,
"_alternate3":5,
"_alternate4":6,
"_alternate5":7,
"_B_":8
}
myArray.sort((...args) => {
const [a, b] = args.map(str => Object.keys(map).find(key => str.includes(key)))
return map[a] - map[b];
})
console.log(myArray)

Json parse by search id [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I have a json file like below:
{ "userdata": { "userid123": {"uname": " john", "uemail": "john#mail.com"}, "userid124": {"uname": "sam", "uemail": "sam#mail.com"} }
I want to parser user details if someone go to url http://example.com/?userid123
So only details of userid123 (which is in the url, get it from there) will be shown.
Json string you added to the question is wrong.
If you need to get the string after the question mark and test if the corresponding value exist or not, you can write:
var js = {
"userdata": {
"userid123": {"uname": " john", "uemail": "john#mail.com"},
"userid124": {"uname": "sam", "uemail": "sam#mail.com"}
}
};
var sp = window.location.search.substr(1);
//for testing purposes
sp='userid123';
if (js.userdata[sp] !== undefined) {
console.log('uname: ' + js.userdata[sp].uname + ' uemail: ' + js.userdata[sp].uemail)
}
First of all you have to save userId to variable like
var userId = location.search.substr(1);
.substr(1) <- this will remove ? from result of location.search();
Now since you are using jquery you can access your json (and user data) as below
$.getJSON( "users.json", function( data ) {
var userData = data[userId]; // your user data
}

Handle multiple string in Array of String javascript [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am getting data in array like this, left side are account name and right one are subscriptions.
7ef:" 3sdc 12exf"
12ef:" 8ecg"
10ef:" 3ecf 3egf 3elm 3ecf 3egf 3elm "
mean 7ef index have 2 strings of data and there is space between both. and 10ef have 6 strings of data.I need this data in form of like
7ef:" 3sdc"
7ef:" 12exf"
12ef:" 8ecg"
10ef:" 3ecf "
10ef:"3egf"
10ef:"3elm"
10ef:"3ecf"
10ef:"3egf"
10ef:"3elm "
As I have to sent it to make its csv file. How Can I do that in javascript ?
Code of creating this is like
foreach ($subscriptions as $subscription) {
$str=$str.' '.$subscription->uuid;
}$anew[account[$i]]=$str;
EDIT :
Now after reading comments can some one tell me how can I make it like
0:" 3sdc"
1:" 12exf"
2:" 8ecg"
like I will save account for later and now I want to arrange them all.
This won't be possible because Javascript Object at same level can have only have unique key, so it will just override the value
SUGGESTED:
use the structure like this
{
7ef:["3sdc", "12exf"],
12ef:["8ecg"],
10ef:["3ecf","3egf", "3elm", "3ecf", "3egf", "3elm"]
}
code :
for (var keys in a){
for (var data in a[keys]){
console.log(keys + " : "+ data)
}
}
a is the var holding the above js object
Change your PHP code to produce a better structure:
$lst = [];
foreach ($subscriptions as $subscription) {
$lst[] = $subscription->uuid;
}
$anew[account[$i]] = $lst;
I suppose you have somewhere:
echo json_encode($anew);
This will give you the following structure in JavaScript:
{
"7ef": ["3sdc", "12exf"],
"12ef": ["8ecg"],
"10ef": ["3ecf","3egf", "3elm", "3ecf", "3egf", "3elm"]
}
To output this as CSV, you could do this (assuming the data is in response):
const response = {
"7ef": ["3sdc", "12exf"],
"12ef": ["8ecg"],
"10ef": ["3ecf","3egf", "3elm", "3ecf", "3egf", "3elm"]
};
const csv = Object.keys(response).reduce( (acc, key) =>
acc.concat(response[key].map( uuid => [key, uuid].join(", ") ))
, []).join("\n");
console.log(csv);

Categories

Resources