Found this code on a public institution's website and have some concerns. Seeking opinions - pixel

I found this code on a clients website, loaded the URL which returned the attached script. This appears to me (and I could be wrong) to be some sport of dataLayer info capture to spreadsheet auto-fill script. Naturally, what concerned my was the "userInfo", "user", "password" sections of this. I'm not overly versed in this level of code so I am reaching out here! Thanks!
! function(r, e, t) {
var n = function(e) {
return "string" == typeof e
},
o = function() {
return function(e) {
for (var n = {
strictMode: !1,
key: ["source", "protocol", "authority", "userInfo", "user", "password", "host", "port", "relative", "path", "directory", "file", "query", "anchor"],
q: {
name: "queryKey",
parser: /(?:^|&)([^&=]*)=?([^&]*)/g
},
parser: {
strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:#]*)(?::([^:#]*))?)?#)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
loose: /^(?:(?![^:#]+:[^:#\/]*#)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:#?]*)(?::([^:#]*))?)?#)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
}
}, r = n.parser[n.strictMode ? "strict" : "loose"].exec(e), o = {}, t = 14; t--;) o[n.key[t]] = r[t] || "";
o[n.q.name] = {}, o[n.key[12]].replace(n.q.parser, function(e, r, t) {
r && (r = decodeURIComponent(r), o[n.q.name][r] && o[n.q.name][r].constructor === Array ? o[n.q.name][r].push(decodeURIComponent(t)) : o[n.q.name][r] ? o[n.q.name][r] = [o[n.q.name][r], decodeURIComponent(t)] : o[n.q.name][r] = decodeURIComponent(t))
});
var s = o.host.split(".");
return o.rootDomain = 2 <= s.length ? s[s.length - 2] + "." + s[s.length - 1] : "", o.href = e, o
}(r.location.href)
},
s = function() {
if (r.rl_widget_cfg) return r.rl_widget_cfg.id;
if (r.rl_siteid) return r.rl_siteid;
var e = o().queryKey.rl_siteid;
return e || ((e = localStorage.getItem("capture_previous_site_id")) || null)
},
c = e.createElement("script");
if (r.rl_widget_cfg || r.test_mode) c.src = "https://cdn.rlets.com/capture_static/mms/capture.js";
else {
var i = function() {
var e, r, t = s();
if (t && n(t) && 32 === (t = (e = t, n(e) ? !1 !== r && e.trim ? e.trim() : e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, "") : e).replace(/-/g, "")).length) return "/" + t.substr(0, 3) + "/" + t.substr(3, 3) + "/" + t.substr(6, 3) + "/" + t.substr(9) + ".js"
}();
i && (c.src = "https://cdn.rlets.com/capture_configs" + i)
}
e.head.appendChild(c)
}(window, document);

cdn.rlets.com is for a tracking pixel for reachlocal.com. It's used for marketing purposes. (I've seen it used specifically as an integration with Facebook ads.)
It's minified, so hard to say exactly what it's doing, but I don't think it's malicious (any more than marketing pixels in general are).

Related

Captcha comes out at any time in a test

I am doing a test in which a capchat can come out at any time but I cannot know the exact moment. I just need to grab it and run my script at that point *
cy.get('.captcha-modal', { timeout: 60000 }).then(($loading) => {
expect($loading).length > 0
cy.get('.captcha-modal', { timeout: 60000 }).click({ force: true })
cy.get('.captcha-modal__content .captcha-modal__question').invoke('text').then((text) => {
let textop = text
let finaltx = textop.trim()
let finaladd = 0
let newtext = finaltx.split(" ")
if (newtext[1] == '+') {
finaladd = parseInt(newtext[0]) + parseInt(newtext[2].trim())
// cy.log(finaladd + " plus")
} else if (newtext[1] == '-') {
finaladd = parseInt(newtext[0]) - parseInt(newtext[2].trim())
// cy.log(finaladd + " minus")
}
cy.get('[name="captchaVal"]').first().type(finaladd)
cy.get("[type='Submit']").click()
})
})

How detect change into arrays of object for each element?

I have an object array. I want to get for each element in the array the difference with the others.
For example thi is my object array:
array= [{id:1, name= 'test', isAdmin: true, userMail:'test#test.com', userTel: '+12555555'},
{id:1, name= 'test', isAdmin: false, userMail:'test#test.com', userTel: '+12555555'}, {id:1,
name= 'test', isAdmin: false, userMail:'test#test.com', userTel: '+12555785444'}]
the result is :
result = [isAdmin, userMail, userTel]
I tried this solution but not working :
for (let index = 0; index < this.array.length; index++) {
const e = this.array[index];
let j = index + 1;
let t;
while (index !== j && j <= (this.array.length - 1) && t === undefined) {
t = this.difference(array);
j++;
}
let y;
if (t !== null && t !== undefined) {
Object.keys(t).forEach(key => {
if (key !== 'idTrace') {
y = key;
}
});
}
this.result.push(y);
}
difference(object, base) {
return transform(object, (result, value, key) => {
if (!isEqual(value, base[key])) {
result[key] = isObject(value) && isObject(base[key]) ?
this.difference(value, base[key]) : value;
}
});
}
Any help, thanks in advance.
you can do it like this.
Please note that this is not the most performant solution, but it is understandable (readable) solution on which you can make optimisations as needed.
const objects = [{
"id": 1,
"name": "test",
"isAdmin": true,
"userMail": "test#test.com",
"userTel": "+12555555"
},
{
"id": 1,
"name": "test",
"isAdmin": false,
"userMail": "test#test123.com",
"userTel": "+12555555"
},
{
"id": 1,
"name": "test",
"isAdmin": false,
"userMail": "test#test.com",
"userTel": "+12555785444"
}
];
// Finds all the keys that are different in two objects.
const difference = (obj1, obj2) => {
let foundKeys = [];
Object.keys(obj1).forEach(key => {
if (obj1[key] !== obj2[key]) {
foundKeys.push(key);
}
});
return foundKeys;
};
let differentKeys = [];
// Compares every object with all objects and pushes to one array all differences in keys.
for (let i = 0; i < objects.length; i++) {
for (let j = i + 1; j < objects.length; j++) {
differentKeys = differentKeys.concat(difference(objects[i], objects[j]));
}
}
// Removes duplicates.
differentKeys = differentKeys.filter(function(value, index, differentKeys) {
return differentKeys.indexOf(value) === index;
});
console.log(differentKeys);
Let me know if you have any questions.

Kendo Grid Sorting issues for numeric

I am using kendo grid to display data, but while sorting(ascending or descending) it's sorting perfectly for string values. But for numeric it's not sorting properly it's taking only first character to do sorting, not taking as string values even it's in numeric. How to solve this issue ?
You can use the gird column sortable.compare property to assign your own compare function.
Then what you are looking for is a Natural sort, like the one described here: http://web.archive.org/web/20130826203933/http://my.opera.com/GreyWyvern/blog/show.dml/1671288 and implemented here: http://www.davekoelle.com/files/alphanum.js
Here is a demo using a case insensitive version of the natural sort:
https://dojo.telerik.com/eReHUReH
function AlphaNumericCaseInsensitive(a, b) {
if (!a || a.length < 1) return -1;
var anum = Number(a);
var bnum = Number(b);
if (!isNaN(anum) && !isNaN(bnum)) {
return anum - bnum;
}
function chunkify(t) {
var tz = new Array();
var x = 0, y = -1, n = 0, i, j;
while (i = (j = t.charAt(x++)).charCodeAt(0)) {
var m = (i == 46 || (i >= 48 && i <= 57));
if (m !== n) {
tz[++y] = "";
n = m;
}
tz[y] += j;
}
return tz;
}
var aa = chunkify(a ? a.toLowerCase() : "");
var bb = chunkify(b ? b.toLowerCase() : "");
for (x = 0; aa[x] && bb[x]; x++) {
if (aa[x] !== bb[x]) {
var c = Number(aa[x]), d = Number(bb[x]);
if (!isNaN(c) && !isNaN(d)) {
return c - d;
} else return (aa[x] > bb[x]) ? 1 : -1;
}
}
return aa.length - bb.length;
}
var dataSource = new kendo.data.DataSource({
data: [
{ id: 1, item: "item101" },
{ id: 2, item: "item2" },
{ id: 3, item: "item11" },
{ id: 4, item: "item1" }
]
});
$("#grid").kendoGrid({
dataSource: dataSource,
sortable: true,
columns: [{
field: "item",
sortable: {
compare: function(a, b) {
return AlphaNumericCaseInsensitive(a.item, b.item);
}
}
}]
});

Rollupjs tree-shaking with typescript decorator modules

When I am using typescript decorators with modules in my script, rollupjs bundles entire modules instead of imported module.
main.js
import { outter } from './index.js';
let a = new outter();
index.js
export * from './display';
export * from './form';
display.js
export var outter = (function (_super) {
console.log();
})();
form.js
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
export var err;
(function (err) {
err[err["name"] = 0] = "name";
err[err["error"] = 1] = "error";
})(err || (err = {}));
export var formV = (function (_super) {
__extends(formV, _super);
function formV(element, options) {
_super.call(this, options, element);
}
__decorate([
Property(err.name)
], formV.prototype, "err", void 0);
return formV;
}());
The formV module is not imported in the main.js file, but it also bundled with the output file.
rollup.config.js
import nodeResolve from 'rollup-plugin-node-resolve';
export default {
entry: 'main.js',
plugins: [
nodeResolve({ jsnext: true })
],
targets: [
{ dest: 'dist/rollup.js', format: 'cjs' },
{ dest: 'dist/rollup.es.js', format: 'es' },
{ dest: 'dist/rollup.amd.js', format: 'amd' }
],
treeshake: true
};

solve in passing parameter to jquery plugin file

I have live filter mike merritt plugin and I passing parameter to it in my inline javascript like this:
$("ul#course-group-list").LiveFilter('basic');
but it have JavaScript runtime error: Object doesn't support property or method 'LiveFilter'
jquery.livefilter plugin is:
(function (a) {
a.fn.liveFilter = function (d) {
var c = a(this);
var g;
if (a(this).is("ul")) {
g = "li"
} else {
if (a(this).is("ol")) {
g = "li"
} else {
if (a(this).is("table")) {
g = "tbody tr"
}
}
}
var e;
var b;
var f;
a("input.filter").keyup(function () {
f = a(this).val();
e = a(c).find(g + ':not(:Contains("' + f + '"))');
b = a(c).find(g + ':Contains("' + f + '")');
if (d == "basic") {
e.hide();
b.show()
} else {
if (d == "slide") {
e.slideUp(500);
b.slideDown(500)
} else {
if (d == "fade") {
e.fadeOut(400);
b.fadeIn(400)
}
}
}
});
jQuery.expr[":"].Contains = function (j, k, h) {
return jQuery(j).text().toLowerCase().indexOf(h[3].toLowerCase()) >= 0
}
}
})(jQuery);

Resources