Current Path : /storage/v11800/testtest/public_html/wp-content/plugins/microsoft-clarity/js/ |
Linux v11800 5.3.0-1023-aws #25~18.04.1-Ubuntu SMP Fri Jun 5 15:19:18 UTC 2020 aarch64
|
Current File : /storage/v11800/testtest/public_html/wp-content/plugins/microsoft-clarity/js/add_window_listeners.js |
const MessageOperation = {
PROJECT_ID_CHANGE: 1,
};
const isValidProjectId = (id) => {
if (id === null || id === undefined || typeof id !== 'string') {
return false;
}
const pattern = /^[a-zA-Z0-9]*$/;
return pattern.test(id);
}
const projectActionCallback = (event) => {
if (event.origin !== "https://clarity.microsoft.com") return;
const postedMessage = event?.data;
if (
postedMessage?.operation !== MessageOperation.PROJECT_ID_CHANGE ||
!isValidProjectId(postedMessage?.id)
) {
return;
}
const isRemoveRequest = postedMessage?.id === "";
jQuery
.ajax({
method: "POST",
url: ajaxurl,
data: {
action: "edit_clarity_project_id",
new_value: isRemoveRequest ? "" : postedMessage?.id,
user_must_be_admin: postedMessage?.userMustBeAdmin,
nonce: postedMessage?.nonce,
},
dataType: "json",
})
.done(function (json) {
if (!json.success) {
console.log(
`Failed to ${isRemoveRequest ? "remove" : "add"} Clarity snippet${
isRemoveRequest ? "." : ` for project ${postedMessage?.id}.`
}`
);
} else {
console.log(
`${isRemoveRequest ? "Removed" : "Added"} Clarity snippet${
isRemoveRequest ? "." : ` for project ${postedMessage?.id}.`
}`
);
}
})
.fail(function () {
console.log(
`Failed to ${isRemoveRequest ? "remove" : "add"} Clarity snippet${
isRemoveRequest ? "." : ` for project ${postedMessage?.id}.`
}`
);
});
};
window.addEventListener("message", projectActionCallback, false);