` }) popover_elem.popover("show"); } function remove_popover() { if (!popover_elem) { return; } popover_elem.popover("destroy"); popover_elem.remove(); } $(".mainbody").on('copy', function (e) { if (!popover_elem) { create_popover(); } else { remove_popover(); create_popover(); } }); var debounce = null; $(".mainbody").on("mouseup", function (e) { clearTimeout(debounce); debounce = setTimeout(() => { if (!popover_elem) { create_popover(); } else { remove_popover(); create_popover(); } }, 100); }) $(".mainbody").on("mousedown", function (e) { const target = $(e.target); if ($(".mainbody").has(target).length) { remove_popover(); } }) };