fix(widget): 完善自动回复与新会话进线提醒
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
console.warn('[kefu-widget] missing data-id on script tag');
|
||||
return;
|
||||
}
|
||||
var autoOpen = !(script && /^(false|0)$/i.test(script.getAttribute('data-auto-open') || ''));
|
||||
|
||||
var src = script && script.src ? script.src : '';
|
||||
var base = '';
|
||||
@@ -139,6 +140,15 @@
|
||||
}
|
||||
}
|
||||
|
||||
function shouldAutoOpenOnce() {
|
||||
var key = 'kefu_widget_auto_opened_' + channelKey;
|
||||
try {
|
||||
if (window.sessionStorage.getItem(key) === '1') return false;
|
||||
window.sessionStorage.setItem(key, '1');
|
||||
} catch (e) { /* privacy mode: fall back to opening on each page load */ }
|
||||
return true;
|
||||
}
|
||||
|
||||
btn.addEventListener('click', function () { setOpen(true); });
|
||||
|
||||
window.addEventListener('message', function (event) {
|
||||
@@ -188,6 +198,11 @@
|
||||
function mount() {
|
||||
document.body.appendChild(btn);
|
||||
document.body.appendChild(panel);
|
||||
if (autoOpen) {
|
||||
window.setTimeout(function () {
|
||||
if (!open && shouldAutoOpenOnce()) setOpen(true);
|
||||
}, 600);
|
||||
}
|
||||
}
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', mount);
|
||||
|
||||
Reference in New Issue
Block a user