Javascript - Seperate all IPs on page and use them as strings - javascript
I'm trying to grab all IPs on a specific page and run a function on each of them; however I can only find (through research) how to grab all IP's on the page as a single string. Not very proficient in JS, as you may be able to tell.
Grab as single string:
var markup = document.getElementsByClassName('border_wrapper')[0].innerHTML;
alert(markup.match(/\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/g).join("\n"))
I'm assuming I'll need a for loop to run them in a function. resolve(newstring);
The .join makes a string, remove it;
var markup = document.getElementsByClassName('border_wrapper')[0].innerHTML;
var list = markup.match(/\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/g);
if (list != null) {
for (var i = 0; i < list.length; i++)
alert(list[i]);
}
Using a cache to prevent repeats;
var markup = document.getElementsByClassName('border_wrapper')[0].innerHTML;
var list = markup.match(/\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/g);
if (list != null) {
var processed = {};
for (var i = 0; i < list.length; i++) {
if (!processed[list[i]])
{
processed[list[i]] = true;
alert(list[i]);
}
}
}
Related
Javascript file isn't appending to a filtered list
As the title reads, my javascript file won't append to a filtered list via a random generator function, for context it's being built in replit so perhaps its just a buggy bit of software on replits end, though I'm certain I've done something wrong and can't for the life of me figure out what. The main idea for this project is to have it randomly select an item from a list, append it to an empty list, then pass that string to an HTML textarea tag to be displayed as text. Code in question: var LowercaseList = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]; var NumList = ["1","2","3","4","5","6","7","8","9","0"]; var SpecialCharList = ["`","~","!","#","$","%","^","&","*","_","-","+","=","<",">","?","/"]; // Letter list ID's since I couldn't figure out how to run this using a database var LetterIDList = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]; // Number list ID's since I couldn't figure out how to run this using a database var NumIDList = [1,2,3,4,5,6,7,8,9,10]; // Special character list ID's since I couldn't figure out how to run this using a database var SpecialID = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17]; // Filtered Lists var UpperFiltered = []; var LowerFiltered = []; var NumFiltered = []; var SpecialFiltered = []; // Global declarations of random number variables to grab values from intial lists var UpperGenVariable; var LowerGenVariable; var NumGenVariable; var SpecialGenVariable; // Creates a basic password with 2 of each kind of character function Basic () { for (var i = 1; i < 2; i++) { UppercaseGenerate(); } for (var i = 1; i < 2; i++) { LowercaseGenerate(); } for (var i = 1; i < 2; i++) { NumGenerate(); } for (var i = 1; i < 2; i++) { SpecialGenerate(); } }; let passwordGen = document.getElementById("PasswordDisplay") function UppercaseGenerate () { var UpperFiltered = []; UpperGenVariable = Math.random(0, LetterIDList.length); for (var i = 0; i < LetterIDList.length - 1; i++) { if (LetterIDList[i] == UpperGenVariable) { appendItem(UpperFiltered, UppercaseList[i]); } }; console.log(UpperFiltered); passwordGen.value = UpperFiltered }; HTML textarea code: <label style = "color:white;" for="PasswordDisplay">Your generated password ----></label> <textarea readonly id="PasswordDisplay" name="PasswordDisplay" rows="10" cols="50"> Please select a password complexity setting </textarea>
I changed how you generate the random number. Also added the UppercaseList, added i <= 2 rather then i < 2 in the cycles so the yould really run 2 times, added += to passwordGen.value += UpperFiltered so the value would add up. I guess that is it. var UppercaseList = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]; var LowercaseList = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]; var NumList = ["1","2","3","4","5","6","7","8","9","0"]; var SpecialCharList = ["`","~","!","#","$","%","^","&","*","_","-","+","=","<",">","?","/"]; // Letter list ID's since I couldn't figure out how to run this using a database var LetterIDList = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]; // Number list ID's since I couldn't figure out how to run this using a database var NumIDList = [1,2,3,4,5,6,7,8,9,10]; // Special character list ID's since I couldn't figure out how to run this using a database var SpecialID = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17]; // Filtered Lists var UpperFiltered = []; var LowerFiltered = []; var NumFiltered = []; var SpecialFiltered = []; // Global declarations of random number variables to grab values from intial lists var UpperGenVariable; var LowerGenVariable; var NumGenVariable; var SpecialGenVariable; // Creates a basic password with 2 of each kind of character function Basic () { for (var i = 1; i <= 2; i++) { UppercaseGenerate(); } for (var i = 1; i <= 2; i++) { LowercaseGenerate(); } for (var i = 1; i <= 2; i++) { NumGenerate(); } for (var i = 1; i <= 2; i++) { SpecialGenerate(); } }; let passwordGen = document.getElementById("PasswordDisplay") function UppercaseGenerate() { var UpperFiltered = []; UpperGenVariable = Math.floor(Math.random() * LetterIDList.length); for (var i = 0; i < LetterIDList.length; i++) { if (LetterIDList[i] == UpperGenVariable) { UpperFiltered.push(UppercaseList[i]); } }; passwordGen.value += UpperFiltered };
Looping through a table rows with comparisons using VUgen
I have a table I need to compare each of the values within to an existing parameter. I have this Xpath here: //*[#id="maincontent"]/messages/div/div[1]/div[1]/table/tbody/tr[1]/td[4]/div/span and would like to insert an increment variable from the loop to go through the /tr/ in the table only. Here is what i have so far: var i; var max = 10; var xpathleft = `*[#id="maincontent"]/messages/div/div[1]/div[1]/table/tbody/tr[`; var xpathright = `]/td[4]/div/span`; for (i = 1; i < max, i++) { var currentXpath = string.concat(xpathleft, i, xpathright); } if (currentXpath.innerHTML == PartnerIDs) { lr_log_message("Match Found!"); } This is currently sitting in an Evaluate Javascript step in TruClient/VUgen and is giving me Syntax Error: Unexpected Token ) The element here doesn't have any ID I can reference and looks like this: Partner ID and has been difficult to pull the needed Partner ID text within code.
Some of your JavaScript syntax is incorrect. Try this: var i; var max = 10; var xpathleft = `*[#id="maincontent"]/messages/div/div[1]/div[1]/table/tbody/tr[`; var xpathright = `]/td[4]/div/span`; for (i = 1; i < max; i++){ var currentXpath = `${xpathleft}${i}${xpathright}`; if (currentXpath.innerHTML == PartnerIDs) { lr_log_message("Match Found!"); } }
Returning XML node values
I need to return all XML values from a URL. I have previously used the URL and it works fine. This is what I have so far: function displayXML(xml) { var devices = xml.getElementsByTagName("device"); for (var i = 0; i < devices.length; i++) { var deviceDetails = devices[i].children; for (j = 0; j < deviceDetails.length; j++) { console.log(devices[i].childNodes[j].nodeValue); } } } It manages to return the right amount of values: 33 tags 33 values but it's returning null for each one. However, the XML file contains values for each tag. Thanks
Based on an answer to this question The nodeValue property of XML elements is always null. The value of the element is actually stored within text nodes inside the element so you will need to go down one more child to get it. Try this var devices = xml.getElementsByTagName("device")[i].firstChild.nodeValue; I think your script should look something like this with firstChild inserted when trying to get the value: function displayXML(xml) { var devices = xml.getElementsByTagName("device"); for (var i = 0; i < devices.length; i++) { var deviceDetails = devices[i].children; for (j = 0; j < deviceDetails.length; j++) { console.log(devices[i].childNodes[j].firstChild.nodeValue); } } }
How to save every object inside an array using for loop in parse.com + AngularJS?
I am using AngularJS and Parse.com. I want to save all of the objects inside an array. But why not all elements on the array are save? var ActivityContact = Parse.Object.extend("ActivityContact"); var ActivityContactObject = new ActivityContact(); var count = $scope.addContList.length; if(count > 0){ for (var i = 0; i < count; i++) { $scope.addContList[i].activityId = actObj.id; ActivityContactObject.save( JSON.parse( angular.toJson($scope.addContList[i]))).then(function (ActContObj) { console.log("ActivityContact Saved - Object: "); console.dir(ActContObj); }); } } This is what I get on the inspector: https://db.tt/fDFuC83f Only one element is save and then is update it. +++ Off topic, but in case you know, isJSON.parse(angular.toJson($scope.addContList[i])) the only way to get rid of the $$hashKey injected by Angular?
I solve it in this way, I don't know if this is the best method but it worked. I accept suggestions to improve it. var ActivityContact = Parse.Object.extend("ActivityContact"); var list = []; var count = $scope.addContList.length; if(count > 0){ for (var i = 0; i < count; i++) { var ActivityContactObject = new ActivityContact(); $scope.addContList[i].activityId = actObj.id; ActivityContactObject.set(JSON.parse(angular.toJson($scope.addContList[i]))); list.push(ActivityContactObject); } Parse.Object.saveAll(list).then(function(results){ console.log("Objects were saved!"); },function(eerror){ console.log(eerror); }); } off topic: I'm still wondering if this (JSON.parse(angular.toJson($scope.addContList[i]))) the best method to solve $$hashKey...
Retrieve all DOM elements in javascript
My application needs to retrieve all DOM elements in javascript and and put there values into one variable i.e if my application is having three text boxes then i want there values in comma separated form in javascript variable
If you want all DOM elements, which you probably don't, but if you do... document.getElementsByTagName('*'); What I think you want is something like this var form = document.getElementById('my-form'). var inputs = form.getElementsByTagName('input'); var inputsCsv = []; for (var i = 0, length = inputs.length; i < length; i++) { if (inputs[i].type === 'text') { inputsCsv.push(inputs[i].value); } } inputsCsv = inputsCsv.join(',');
in below example i am taking values of all textboxes of a table. you can pass form name there. var frm = document.getElementById('tblemail').getElementsByTagName("input"); var len = frm.length; var myval=''; for (i=0;i< len;i++) { if (frm[i].type == "text") { if(myval =='') { myval = frm[i].value; }else{ myval += ',' + frm[i].value; } } }