var copyToClipboard = function (element, str) { var el = document.createElement('textarea'); el.value = str; el.setAttribute('readonly', ''); el.style.position = 'absolute'; el.style.left = '-9999px'; document.body.appendChild(el); el.select(); document.execCommand('copy'); document.body.removeChild(el); $(element).focus(); }; $(document).ready(function () { var checkExist = setInterval(function () { if ($(".st-btn").length) { $("[class*='-share-buttons']").each(function () { $(this).find('div[data-network="email"]').replaceWith($(this).find('div[data-network="email"]').clone()); $(this).find('div[data-network="email"]').on("click", function () { var emailSubject = document.title; var emailBody = window.location.href; window.location.href = "mailto:?subject=" + emailSubject + "&body=" + emailBody; }); $(this).find(".st-btn").each(function () { $(this).attr("tabindex", "0"); }); $(this).find(".st-btn").on('keypress', function (e) { if (e.which === 13) { $(this).click(); } }); }); if ($("[class*='-share-buttons']").find('.custom-st-btn').length === 0) { $("[class*='-share-buttons']").each(function () { $(this).find(".st-last").after( '
' + 'copy link sharing button' + '
' + ''); }); $("[class*='-share-buttons']").each(function () { $(this).find(".custom-st-btn").on("click", function () { var copyText = document.querySelector("link[rel='canonical']"); if (copyText == null) { copyToClipboard($(this), document.location.href); } else { copyToClipboard($(this), copyText.getAttribute("href")); } var copiedLink = $(this).siblings(".link-copied"); copiedLink.css('display', 'block'); setTimeout(function () { copiedLink.css('display', 'none'); }, 3000); }); $(this).find(".custom-st-btn").on('keypress', function (e) { if (e.which === 13) { $(this).click(); } }); }); } clearInterval(checkExist); } }, 100); });