Updated javascript to also work when the Agent raises a ticket on behalf of a customer;
(function() {
console.log("Zammad Interceptor v9 (Agent UI + Payload Scraper) loaded.");
let checkJquery = setInterval(function() {
if (window.jQuery) {
clearInterval(checkJquery);
window.jQuery.ajaxPrefilter(function(options, originalOptions, jqXHR) {
if (options.url && options.url.indexOf('external_data_source') !== -1) {
try {
let smuggledPrefix = "";
// --- 1. AGENT VIEW: Check Customer Information Sidebar ---
let agentCustomerEmail = "";
document.querySelectorAll('.sidebar-content .sidebar-block').forEach(block => {
let label = block.querySelector('label');
if (label && label.innerText.trim() === 'Email') {
// Extract the raw text nodes inside the block (ignoring the label itself)
let textNodes = Array.from(block.childNodes).filter(node => node.nodeType === Node.TEXT_NODE);
let emailText = textNodes.map(n => n.nodeValue.trim()).join('');
if (emailText.includes('@swale.at')) {
agentCustomerEmail = emailText;
}
}
});
if (agentCustomerEmail) {
// Smuggle the customer's username!
smuggledPrefix = "USER:" + agentCustomerEmail.split('@')[0];
}
// --- 2. CUSTOMER VIEW: Check Org Dropdown ---
else {
const orgInput = document.querySelector('div[data-attribute-name="organization_id"] input.searchableSelect-main');
let currentOrg = orgInput ? (orgInput.getAttribute('title') || orgInput.value || "").trim() : "";
if (currentOrg) {
smuggledPrefix = "ORG:" + currentOrg;
}
// --- 3. CUSTOMER VIEW: Check Profile Avatar ---
else {
const profileAvatar = document.querySelector('a[href="#current_user"]');
if (profileAvatar) {
let email = profileAvatar.getAttribute('title') || "";
if (email && email.includes('@swale.at')) {
smuggledPrefix = "USER:" + email.split('@')[0];
}
}
}
}
// --- 4. Inject into the jQuery Data Payload ---
if (smuggledPrefix) {
if (options.data && typeof options.data === 'string') {
let params = new URLSearchParams(options.data);
let currentQuery = params.get('query') || '';
if (!currentQuery.includes('||')) {
params.set('query', smuggledPrefix + '||' + currentQuery);
options.data = params.toString();
console.log("Interceptor: Smuggled perfectly ->", options.data);
}
}
}
} catch (e) {
console.error("Interceptor Error:", e);
}
}
});
}
}, 100);
})();