Обновить Tampermonkey_email.js
This commit is contained in:
@@ -0,0 +1,129 @@
|
|||||||
|
// ==UserScript==
|
||||||
|
// @name Плашка оператора (Новые договоры)
|
||||||
|
// @namespace http://192.168.254.38/
|
||||||
|
// @version 1.0.0
|
||||||
|
// @description Показывает плашку с именем оператора из папки "Новые договоры"
|
||||||
|
// @author yasu
|
||||||
|
// @match https://admin2.gtn.ru/diagnostics/index.php?*search=*
|
||||||
|
// @grant GM_xmlhttpRequest
|
||||||
|
// @connect 192.168.254.38
|
||||||
|
// @updateURL http://192.168.254.38:8766/script.user.js
|
||||||
|
// @downloadURL http://192.168.254.38:8766/script.user.js
|
||||||
|
// ==/UserScript==
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const BANNER_ID = 'contract-operator-banner';
|
||||||
|
let bannerShownOnThisPage = false;
|
||||||
|
|
||||||
|
function getContractNumberFromUrl() {
|
||||||
|
const url = window.location.href;
|
||||||
|
const match = url.match(/[?&]search=(\d+)/);
|
||||||
|
return match ? match[1] : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkBanner(contractNumber, callback) {
|
||||||
|
GM_xmlhttpRequest({
|
||||||
|
method: 'GET',
|
||||||
|
url: `http://192.168.254.38:8766/get-banner?contract=${contractNumber}`,
|
||||||
|
timeout: 5000,
|
||||||
|
onload: function(response) {
|
||||||
|
try {
|
||||||
|
callback(null, JSON.parse(response.responseText));
|
||||||
|
} catch(e) {
|
||||||
|
callback(e, null);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onerror: callback,
|
||||||
|
ontimeout: function() { callback(new Error('Timeout'), null); }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function closeBanner(contractNumber, callback) {
|
||||||
|
GM_xmlhttpRequest({
|
||||||
|
method: 'POST',
|
||||||
|
url: 'http://192.168.254.38:8766/close-banner',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
data: JSON.stringify({ contract_number: contractNumber }),
|
||||||
|
timeout: 5000,
|
||||||
|
onload: function() { callback(null); },
|
||||||
|
onerror: callback
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatDate(dateString) {
|
||||||
|
if (!dateString) return '';
|
||||||
|
const parts = dateString.split(' ');
|
||||||
|
if (parts.length < 2) return dateString;
|
||||||
|
const dateParts = parts[0].split('-');
|
||||||
|
if (dateParts.length === 3) {
|
||||||
|
return `${dateParts[2]}.${dateParts[1]}.${dateParts[0]} ${parts[1].substring(0, 5)}`;
|
||||||
|
}
|
||||||
|
return dateString;
|
||||||
|
}
|
||||||
|
|
||||||
|
function showBanner(operatorName, contractNumber, receivedDate) {
|
||||||
|
const oldBanner = document.getElementById(BANNER_ID);
|
||||||
|
if (oldBanner) oldBanner.remove();
|
||||||
|
|
||||||
|
const banner = document.createElement('div');
|
||||||
|
banner.id = BANNER_ID;
|
||||||
|
banner.style.cssText = `
|
||||||
|
position: fixed;
|
||||||
|
top: 10px;
|
||||||
|
right: 10px;
|
||||||
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||||
|
color: white;
|
||||||
|
padding: 12px 18px;
|
||||||
|
border-radius: 8px;
|
||||||
|
box-shadow: 0 4px 12px rgba(0,0,0,0.2);
|
||||||
|
z-index: 99999;
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
font-size: 14px;
|
||||||
|
cursor: pointer;
|
||||||
|
min-width: 200px;
|
||||||
|
border-left: 3px solid #ffd700;
|
||||||
|
`;
|
||||||
|
|
||||||
|
banner.innerHTML = `
|
||||||
|
<div style="display: flex; justify-content: space-between; align-items: center;">
|
||||||
|
<div>
|
||||||
|
<div style="font-weight: bold; font-size: 15px;">📋 ${operatorName}</div>
|
||||||
|
<div style="font-size: 11px; opacity: 0.8; margin-top: 4px;">Договор №${contractNumber}</div>
|
||||||
|
${formatDate(receivedDate) ? `<div style="font-size: 10px; opacity: 0.6; margin-top: 2px;">${formatDate(receivedDate)}</div>` : ''}
|
||||||
|
</div>
|
||||||
|
<div style="margin-left: 12px; font-size: 18px; font-weight: bold;">×</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
banner.onclick = () => {
|
||||||
|
banner.remove();
|
||||||
|
closeBanner(contractNumber, function(err) {
|
||||||
|
if (err) console.error('Ошибка при закрытии плашки:', err);
|
||||||
|
else console.log(`Плашка для договора ${contractNumber} закрыта`);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
document.body.appendChild(banner);
|
||||||
|
bannerShownOnThisPage = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function init() {
|
||||||
|
if (bannerShownOnThisPage) return;
|
||||||
|
|
||||||
|
const contractNumber = getContractNumberFromUrl();
|
||||||
|
if (!contractNumber) return;
|
||||||
|
|
||||||
|
checkBanner(contractNumber, function(err, data) {
|
||||||
|
if (err || !data || data.show !== true) return;
|
||||||
|
showBanner(data.operator_name, data.contract_number, data.received_date);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (document.readyState === 'loading') {
|
||||||
|
document.addEventListener('DOMContentLoaded', init);
|
||||||
|
} else {
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
})();
|
||||||
Reference in New Issue
Block a user