Get value of remote JS var with Jurassic Script Engine - javascript

My remote js file as below
(function(window,document){
var config = {
'placeHolder' : 'content_div'
};
var html = "blaaa blaaa";
})(window,document);
I would likte to get value of html.
I have tried as below but I have got error.
string _JsVars = this._HttpWebRequestRemoteUrl(#"http://www.remotewebpage.com");
var engine = new Jurassic.ScriptEngine();
var result = engine.(_JsVars);
var var1 = engine.GetGlobalValue<string>("html");
MessageBox.Show(var1.ToString());

Related

I have an error code in my getBody() function and I dont know why

So I'm creating this code where the template is selected through a series of If statements. so it is a changing variable. I am simply trying to now replace text in the selected template and I keep getting the same error that getBody() is not a function. Any help is greatly appreciated!
var doc = DriveApp.getFileById(templateId);
var copy = doc.makeCopy();
var destination = DriveApp.getFolderById('1mGCx4yXX_NnLHsHsGWBGkzwAVhG-cTrc');
destination.addFile(copy);
copy.setName(regno + ' statistical analysis');
var copiedTemplateId = copy.getId();
var body = doc.getBody();
var header = doc.getHeader();
DriveApp.getFileById returns a File.
So, doc is of type File.
There is no "getBody" function for a File, at least it doesn't exist in the documentation: https://developers.google.com/apps-script/reference/drive/file
This works:
function myfunk() {
const regno = "test";
var file = DriveApp.getFileById("fileid");
var destination = DriveApp.getFolderById("folderid");
let name = regno + ' statistical analysis';
var copy = file.makeCopy(name, destination);
var copiedTemplateId = copy.getId();
let doc = DocumentApp.openById(copiedTemplateId);
var body = doc.getBody();
var header = doc.getHeader();
Logger.log('id: %s, body: %s, header: %s',copiedTemplateId,body,header);
}
File was a Google Document and a copied was created in the appropriate directory and renamed correctly.

Invalid argument - root element

I'm trying to modify an XML file on my Google Drive using :
var file = DriveApp.getFilesByName('keyWordsList.xml').next();
var xml = file.getBlob().getDataAsString();
var document = XmlService.parse(xml);
var root = document.getRootElement();
var child = XmlService.createElement('keyword');
var childName = XmlService.createElement('label').setText(name);
root.addContent(child);
document = XmlService.createDocument(root);
xml = XmlService.getPrettyFormat().format();
DriveApp.createFile("keyWordsList.xml", xml);
This is a simplified example.
But XmlService.createDocument(root); throws an error :
Invalid argument: rootElement
I found a solution if someone get the same problem.
You dont need to create the document for being accept by Google Drive
var root = document.getRootElement();
var child= XmlService.createElement('keyword');
var childName = XmlService.createElement('label').setText(name);
var childKeyWord = child.addContent(childName);
for(var x=0;x<keywords.length;x++)
{
childKeyWord = XmlService.createElement('motcle').setText(keywords[x]);
child.addContent(childKeyWord);
}
root.addContent(child);
var xml = XmlService.getPrettyFormat().format(root);
DriveApp.createFile("keyWordsList.xml",xml,"text/xml");

bug:ReferenceError: self is not defined exif-js

Am getting an error while finding the exif information of an image (base64 image data):
Exif.getData(path, () => {
const tag = Exif.getTag(this, 'Orientation');
console.log(tag);
});
ReferenceError: self is not defined
/usr/local/lib/node_modules/exif-js/exif.js:931
if ((self.Image && img instanceof self.Image)
^
can anyone help
Are you executing this snippet in Client side JS or Node.js ?
Currently exif.js is developed based on the self object. It supports only client side Javascript.
Register exif.js after window load, Attached sample snippet for reference.
window.onload=getExif;
function getExif() {
var img1 = document.getElementById("img1");
EXIF.getData(img1, function() {
var make = EXIF.getTag(this, "Make");
var model = EXIF.getTag(this, "Model");
var makeAndModel = document.getElementById("makeAndModel");
makeAndModel.innerHTML = `${make} ${model}`;
});
var img2 = document.getElementById("img2");
EXIF.getData(img2, function() {
var allMetaData = EXIF.getAllTags(this);
var allMetaDataSpan = document.getElementById("allMetaDataSpan");
allMetaDataSpan.innerHTML = JSON.stringify(allMetaData, null, "\t");
});
}
Exif parser works perfectly in server side.
https://www.npmjs.com/package/exif-parser

angularjs with nodejs functions

My problem is that I need in the key_client variable is loaded variable md5 obtained through a module called nodejs get-mac.
The way I'm working it can not get it work.
Always runs before key_client to get mac.
//Get Mac Machine for request
var md5;
node.mac.getMac(function(err, mac){
var hash = node.crypt.createHash('md5').setEncoding('hex');
hash.write(mac);
hash.end();
md5 = hash.read();
});
//Define host and set keys
var host = 'https://service.herokuapp.com/'
var namespace = 'api/v1'
var api = host + namespace
var key_server = '432565454'
var key_client = md5;
console.log(key_client);
Try:
//Get Mac Machine for request
var md5;
node.mac.getMac(function(err, mac){
var hash = node.crypt.createHash('md5').setEncoding('hex');
hash.write(mac);
hash.end();
md5 = hash.read();
someFunction();
});
function someFunction() {
//Define host and set keys
var host = 'https://service.herokuapp.com/'
var namespace = 'api/v1'
var api = host + namespace
var key_server = '432565454'
var key_client = md5;
console.log(key_client);
}

mocha import external script failed

I have this opcode.js file and need to test it with mocha.An example can be seen here :
var opcode = {
'0': {
decode: function (data) {
var ocBuf = new OpcodeBuffer(data);
var kpo = {};
kpo.opcode = 0x00;
ocBuf.setIndex(1);
kpo.sid = ocBuf.readUInt16();
return kpo;
},
encode: function (kpo) {
var ocBuf = new OpcodeBuffer(opcode['0'].encodeLength(kpo));
ocBuf.writeUInt8(0x00);
ocBuf.writeUInt16(kpo.sid);
return ocBuf.buf;
}
module.exports = opcode;
and the write in my test_ack.js file:
var op = require('./ack.js');
var assert = require('assert');
opcode = op.opcode;
var decode = require('opcode').decode();
var encode = require('opcode').encode();
the problem is that i keep having this encode and decode not defined error messages.I still cannot get how can i import them in my directory.
Given the code you show us, this would be the way you could import your two functions:
var decode = require('opcode')["0"].decode;
var encode = require('opcode')["0"].encode;
I'd suggest additionally avoiding calling require twice. Among other things, the code you currently have calls the functions instead of just importing them.

Categories