Getting Android device locale with JavaScript in Tasker - javascript

I'm trying to get the device locale by running the JavaScript in Tasker, the script should assign the locale to variable.
The whole JavaScript file looks like following:
var locale = Locale.getDefault();
But variable locale is empty.
I've also tried
var locale = Resources.getSystem().getConfiguration().getLocales().get(0);
with the same result.
Also tried to use String instead of var but that gave me an error.

Found a workaround.
In Tasker, you can run a Shell command, so I ran
getprop persist.sys.locale
and passed its result to a global value.

Related

Javascript create array from local words.txt 2021

I have a txt file called test.txt.
Inside of it there are words that are basically laid out like this.
ability
able
about
above
accept
according
account
across
act
action
activity
actually
add
address
administration
admit
adult
affect
after
again
against
age
agency
agent
ago
I want to use these words turn them into an array and store into one variable.
Something like this.
var words = ["ability", "about", "above", "action"...];
I am only using javascript and nothing else how do I do this?
Assuming you are using node.js since you are accessing a file.
const fs = require('fs');
let array = fs.readFile('./test.txt').split(/\r?\n/g);
Otherwise the answer is: JavaScript is executed client-side and won't handle files.
try it:
file.split(/\r\n|\r|\n/g)

Nodejs not recognizing string(Input in Japanese)

I am trying to take an input in Japanese language and pass the value as parameter to another function to retrieve data from the function but whenever I run node app.js it doesn't recognize the input. But in the browser it is working just fine.
So it is accessing data from json const innerArray = { Name : 'Test', Prefecture: '東京都' }
While accessing it:
let prefectureName = innerArray.Prefecture
console.log(prefectureName)
The output is ???
When I use the input in english it also works. Then I also tried to convert the japanese input into english. then again the same problem remains as it can not read the input.
Can anyone help me regarding this matter?
I suspect this is only a problem in your log console. Node.js uses UTF-16 internally, so Japanese characters are fully supported.
I'd suggest trying the following:
const fs = require("fs");
const innerArray = { Name : 'Test', Prefecture: '東京都' }
fs.writeFileSync("test.json", JSON.stringify(innerArray), "utf8");
console.log("innerArray:", innerArray);
Then open test.json in something like Notepad++, you should see the characters rendered correctly.
If I try this example in Visual Studio Code, the output is fine too since the console or output font has support for Japanese Characters.

Reading windows registry Reg_SZ in javascript

first time posting here!:)
As title says I have a win reg fie (reg_sz) which contains "name" and "value"
this.reg = new Registry.Key(Registry.windef.HKEY.HKEY_CURRENT_USER, 'Path\Path\Path', Registry.windef.KEY_ACCESS.KEY_READ);
funct read(this.reg){
var value;
var pushes = [];
[
"food",
"veggy",
"etc",
"etc"].forEach(function(name) {
try {
value = key.getValue(name);
entries.push({name: name, value: value});
} catch (e) {
}
});
return pushes;
};
example: "food"="apple"
Which my code reads properly, however I came across a issue with special characters, example "ä"
"food"="äpple"
which my code reads as �pple.
My question is what kind of decoding/encoding should i use and what is with this win registry, what exactly are they using? Can it be raw JS preferably and if not what else? I tried using decodeURI/encodeURI but seems like its not the correct approach(dont know what encoding they are using and which decoding should I use)
TLDR: How can i type in "äpple" in win registry and when reading that file with JS get same "äpple" instead of "�pple"
It looks like you're using windows-registry-node. This is unfortunately a bug in that, #44. The reporter says:
If i return the raw buffer and use iconv to convert from "ISO-8859-1" to "UTF-8" i get the correct characters
Note that this is assuming the current code page of the system, though, and might not always be correct. (It might be possible to tell iconv to detect and use the current code page?)
The exact problem is in registry.js:
// READ VALUE
result = advApi.RegQueryValueExA(key.handle.deref(), valueName, null, pKeyType, value,
pKeyDataLength);
Here it uses RegQueryValueExA, which means fetch strings as the current Windows code page, as opposed to RegQueryValueExW which would use UTF-16. So value, which is a Node.JS Buffer, does not contain UTF-8. The code then calls Buffer.toString(), which assumes UTF-8 by default:
if (value.type === types.LPTSR) {
// TODO not sure why buffer's utf8 parsing leaves in the unicode null
// escape sequence. This is a work-around (at least on node 4.1)
value = value.toString().replace('\u0000', '');
}
So this is going to need a fix in windows-registry-node. The best fix is probably to set the code up for UTF-16, using the -W version of the function and value.toString('utf16le');

Jint+JSfuck - 'Index was outside the bounds of the array'

I'm trying to run the following code in jint:
Jint.Engine engine = new Jint.Engine();
var result = engine.SetValue("data", data).Execute("(/\\n(.+)/.exec(eval(data.replace(/\\s+/, \"\").slice(0, -2)))[1]);").GetCompletionValue();
Which, when unescaped, is executing the following javascript:
(/\n(.+)/.exec(eval(data.replace(/\s+/, "").slice(0, -2)))[1]);
the data variable corresponds to a JSfuck string, similar to this: https://pastebin.com/vmGAebW5
The problem is that I always get a 'Index was outside the bounds of the array' exception, even though the javascript works fine when run in a browser. Any ideas as to what is causing the issue?
windows.location is not available in Jint as the window object is provided by the browser. If you wanted to be able to run this kind of code then you would need to mock all the browser exposed objects, which is a huge task.
Also you are using SetValue('window.location', "") which I assume is not a valid call. The property name should not contain dots.

js-ctypes from javascript objects

I'm working on a Firefox extension that receives binary images as ArrayBuffers of uint8_t.
In my extension I load a .dll file that has a function that I need to use on that received image. The function takes a ctype.uint8_t.ptr parameter and returns a ctype.uint8_t.ptr value.
I can't seem to find a way of converting the ArrayBuffer to this particular ctype so that I can pass it along to the function. Is there a correct way to do this?
Using ImplicitConvert() gives an Error: argument must be a nonnegative integer.
You should be able to do just:
var a = new Uint8Array(1<<10);
var ptr = new ctypes.uint8_t.ptr(a.buffer);
The stuff is not documented it seems, but there are some tests that demonstrate this.

Categories

Resources