This question already has answers here:
De-obfuscate Javascript code to make it readable again [duplicate]
(5 answers)
Closed 7 years ago.
I try to work with javascript from Chrome extension, and have some problems.
Big parts of code including in encode array
var _0x6790 = ["\x44\x4F\x4D\x53\x75\x62\x74\x72\x65\x65\x4D\x6F\x64\x69\x66\x69\x65\x64", "\x67\x65\x74", "\x3A\x76\x69\x73\x69\x62\x6C\x65", "\x69\x73", "\x24\x61\x70\x70\x6C\x79\x46\x6F\x72\x4C\x6F\x6F\x74\x42\x75\x74\x74\x6F\x6E", "\x65\x6E\x61\x62\x6C\x65\x64", "\x61\x75\x74\x6F\x63\x6C\x69\x63\x6B\x69\x6E\x67", "\x73\x65\x74\x74\x69\x6E\x67\x73", "\x6D\x61\x67\x69\x63", "\x63\x6C\x69\x63\x6B", "\x5F\x62\x69\x64\x49\x6E\x74\x65\x72\x6E\x61\x6C\x44\x65\x6C\x61\x79", "\x61\x75\x74\x6F\x62\x69\x64\x64\x69\x6E\x67", "\x23\x67\x6F\x6C\x64\x73\x6C\x69\x64\x65\x72", "\x73\x65\x74\x42\x69\x64", "\x6F\x6E", "\x5F\x69\x6E\x73\x74\x61\x6E\x63\x65"];
and is used like this:
$(document)[_0x6790[14]](_0x6790[0], function() {
How can I decode the values in the array?
this is a worked demo that can help you:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
<script>
function hex2a(hex) {
var str = '';
for (var i = 0; i < hex.length; i += 2) str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
document.getElementById('result').innerHTML=str;
}
</script>
</head>
<body>
<h1><u>Hex Decoder</u></h1><br>
<h3><u>Hex code</u></h3>
<textarea id="hexcode" rows="4" cols="50"></textarea><br>
<button type="button" onclick="hex2a(document.getElementById('hexcode').value)">decode</button><br>
<h3><u>Result</u></h3>
<textarea id="result" rows="4" cols="50"></textarea>
</body>
</html>
Related
This question already has answers here:
What is the difference between client-side and server-side programming?
(3 answers)
Closed 3 years ago.
I have a problem with php.
I was trying to make a button that changes its text into random numbers every time I click, but it only worked for once.
My Code:
<!DOCTYPE html>
<html>
<body>
<?php
function yeet(){
return rand(1, 100);
}
?>
<script type="text/javascript">
function yeeb(){
let randNum = <?php echo yeet();?>;
document.getElementById("co").innerHTML = randNum.toString();
}
</script>
<button onclick = "yeeb()" id="co">click</button>
</body>
</html>
Any help would be grateful.
Why are you doing it using php?
You can make that function by javascript only
function yeeb(){
let randNum = Math.floor(Math.random() * 100) + 1;
document.getElementById("co").innerHTML = randNum.toString();
}
<html>
<head>
<!--Wei Wu Section A-->
<title>This is the 4th extra credit</title>
</head>
<body>
<script type="text/javascript">
function toUpper(stringFromUser){
var arrayOfStrings = [];
arrayOfStrings = stringFromUser.split(" ");
for(i=0;i<arrayOfStrings.length;i++){
//if (char(arrayOfStrings[i][0]) <= 122 && char(arrayOfStrings[i][0]) >= 97){
if (arrayOfStrings[i].charCodeAt(0) <=122 && arrayOfStrings[i].charCodeAt(0) >=97){
arrayOfStrings[i] = arrayOfStrings[i].charAt(0).toUpperCase() + arrayOfStrings[i].slice(1);
}
}
var afterTitle = "";
afterTitle = arrayOfStrings.join(" ");
document.getElementById('afterChange').innerHTML = afterTitle;
}
</script>
<p>Enter a sentence and I will turn it into Title Case!<input id="textInput" value=""></p>
<button onclick="toUpper(textInput.value)">Change case!</button>
<p id="afterChange"></p>
</body>
</html>
Hi thank you in advance for all your help. this is one of the code that I was working on. the purpose of this code is to "Title Case" the first letter of each word in the sentence. My code runs quite well after some work.
But I have one question: On line 14, I was trying to directed assign the uppercase letter to arrayOfString[i][0], it didn't work. Instead, I changed the whole element, AKA the element in the array. Why didn't that work? Thank you very much!
Strings are immutable - you cannot change individual characters in them by assigning to their [] indicies. So, you have to slice them apart and put them back together, as you did.
You can use this code to Title Case
<html>
<head>
<!--Wei Wu Section A-->
<title>This is the 4th extra credit</title>
</head>
<body>
<script type="text/javascript">
function toUpper(stringFromUser){
var afterTitle = toTitleCase(stringFromUser);
document.getElementById('afterChange').innerHTML = afterTitle;
}
function toTitleCase(str)
{
return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
}
</script>
<p>Enter a sentence and I will turn it into Title Case!<input id="textInput" value=""></p>
<button onclick="toUpper(textInput.value)">Change case!</button>
<p id="afterChange"></p>
</body>
</html>
This question already has answers here:
how do I set input from user to the value of an input?
(2 answers)
Closed 6 years ago.
I am not exactly new at coding,
But I am definitely an amateur (especially in Javascript), and I have just started a new project for personal purpose.
I can not seem to get my Javascript to print out my answer, and I do not want to move on with the project until I figure it out, because it is going to have more complicated calculations as I work on it.
My code is as below:
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<p>Enter Your Macros</p>
<p>Fats</p>
<input type="number" name="fats" id="fatInput"/><br>
<button onclick="myFunction()">Calculate</button><br>
<p id="todaysFat"></p>
<script>
function myFunction() {
var f = document.getElementById("fatInput").innerHTML;
document.getElementById("todaysFat").innerHTML = f;
}
</script>
</body>
</html>
Thank you for all of the help
try;
function myFunction() {
var f = document.getElementById("fatInput").value;
document.getElementById("todaysFat").innerHTML = f;
}
I don't think it's the innerHTML your want but the value of the INPUT.
So that's .value not innerHTML.
eg..
var f = document.getElementById("fatInput").value;
Change the innerhtml to value in the first line.
See the below code:
function myFunction() {
var f = document.getElementById("fatInput").value;
document.getElementById("todaysFat").innerHTML = f;
}
<p>Enter Your Macros</p>
<p>Fats</p>
<input type="number" name="fats" id="fatInput" />
<br>
<button onclick="myFunction()">Calculate</button>
<br>
<p id="todaysFat"></p>
This question already has answers here:
Finding matches between multiple JavaScript Arrays
(13 answers)
Closed 7 years ago.
// HTML
// Some Html content
<div class="class--1 common-class otherClass2">…</div>
// Some Html content
<div class="otherdiv"></div>
<div class="common-class class--2">…</div>
<div class="common-class class--3 otherClass">…</div>
// Some Html content
i'm trying to iterate between 2 arrays;
one with className stored and the other with html elements targeted
// JAVASCRIPT
var arrayOfClasses = ["class--5", "class--10", "class--1", "class--2"];
var arrayOfElements = document.getElementsByClassName("common-class");
// This return the following array
// [<div class="common-class class--1">…</div>, <div class="common-class class--2>…</div>, <div class="common-class class--3>…</div>];
How i get true value for the element with class--1 and class--2 and false for class--3 class--5 and class--10
I iterate throw the arrayOfElements[i].className
and after use the indexOf commented below
but found another problem here :S
"common-class class--10".indexOf("class--1")
// Return > 13 but i want -1 because is 10 no 1
Better without jQuery
Thanks in advance.
var array1 = ["Hello", 5, "Hola", 27, 'otherValue'];
var array2 = [27, "Hello"];
var intersection = [];
var intersectionObj = {};
for(var i=0; i<array1.length; i++) {
if(array2.indexOf(array1[i]) > -1) {
intersection.push(array1[i]);
}
}
alert(intersection);
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
</body>
</html>
This question already has answers here:
Generate random string/characters in JavaScript
(93 answers)
Closed 9 years ago.
I need to connect the webpage with a 'random.js' file which I hope I have already correctly done, as well as creating a function named 'GenerateSequence' that generates 3 random letters. I have inserted 3 'RandomChar' into the body but am not entirely sure where exactly they go. In the end the page needs to look like this
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='utf-8'>
<title>Random Letter Sequence</title>
<script type="text/javascript" src="random.js"></script>
<script type="text/javascript">
function GenerateSequence()
{
}
</script>
</head>
<body>
<h2>Generate 3-Letter Sequence</h2>
sequence = RandomChar('abcdefghijklmnopqrstuvwxyz') +
RandomChar('abcdefghijklmnopqrstuvwxyz') +
RandomChar('abcdefghijklmnopqrstuvwxyz');
<hr>
<h3>You Random 3-Letter Sequence<h3>
<div id="outputDiv"></div>
</body>
</html>
function GenerateSequence(){
var result = "";
var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
for(var i=0;i<3;i++){
result += alphabet.charAt(Math.floor(Math.random() * alphabet.length));
}
return result;
}
window.onload = function(){
document.getElementById('goButton').onclick=function() {
document.getElementById('outputDiv').innerHTML = GenerateSequence();
}
}