Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- window.onload = function () {
- var elements = document.querySelectorAll(".markdown-body *");
- var lastHighlighted = null;
- // Notifikačný box (ako predtým)
- var notifyDiv = document.createElement("div");
- notifyDiv.style.position = "fixed";
- notifyDiv.style.top = "20px";
- notifyDiv.style.left = "50%";
- notifyDiv.style.transform = "translateX(-50%)";
- notifyDiv.style.backgroundColor = "#0080ff";
- notifyDiv.style.color = "#ffd700";
- notifyDiv.style.padding = "10px 15px";
- notifyDiv.style.borderRadius = "5px";
- notifyDiv.style.boxShadow = "0 2px 6px rgba(0,0,0,0.3)";
- notifyDiv.style.fontFamily = "'Manrope', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif";
- notifyDiv.style.fontWeight = "600";
- notifyDiv.style.fontSize = "18px";
- notifyDiv.style.zIndex = "9999";
- notifyDiv.style.opacity = "0";
- notifyDiv.style.filter = "alpha(opacity=0)";
- document.body.appendChild(notifyDiv);
- var notificationTimeout = null;
- var fadeOutInterval = null;
- function showNotification(message) {
- if (notificationTimeout) clearTimeout(notificationTimeout);
- if (fadeOutInterval) clearInterval(fadeOutInterval);
- notifyDiv.innerText = message;
- notifyDiv.style.opacity = "1";
- notifyDiv.style.filter = "alpha(opacity=100)";
- notificationTimeout = setTimeout(function () {
- var opacity = 1;
- fadeOutInterval = setInterval(function () {
- opacity -= 0.1;
- if (opacity <= 0) {
- clearInterval(fadeOutInterval);
- notifyDiv.style.opacity = "0";
- notifyDiv.style.filter = "alpha(opacity=0)";
- } else {
- notifyDiv.style.opacity = opacity;
- notifyDiv.style.filter = "alpha(opacity=" + (opacity * 100) + ")";
- }
- }, 100);
- }, 2000);
- }
- function blinkText(element) {
- var originalColor = element.style.color;
- element.style.color = "transparent";
- setTimeout(function () {
- element.style.color = originalColor;
- setTimeout(function () {
- element.style.color = "transparent";
- setTimeout(function () {
- element.style.color = originalColor;
- }, 150);
- }, 150);
- }, 150);
- }
- // Vyčisti predchádzajúce zvýraznenie
- function clearPreviousHighlight() {
- if (lastHighlighted) {
- lastHighlighted.style.backgroundColor = lastHighlighted.getAttribute("data-original-bg") || "";
- }
- lastHighlighted = null;
- }
- // Hlavné zvýraznenie
- for (var i = 0; i < elements.length; i++) {
- (function (element) {
- element.addEventListener("mouseenter", function () {
- clearPreviousHighlight();
- this.setAttribute("data-original-bg", this.style.backgroundColor || "");
- this.style.backgroundColor = "#3B4855";
- this.style.cursor = "pointer";
- lastHighlighted = this;
- });
- element.addEventListener("mouseleave", function () {
- // nezrušíme zvýraznenie, len ak sa myš vzdiali úplne
- // inak by nám to blikalo
- });
- })(elements[i]);
- }
- // Kliknutie kdekoľvek – použije posledný zvýraznený element
- document.addEventListener("click", function (event) {
- if (!lastHighlighted) return;
- event.preventDefault();
- var text = lastHighlighted.innerText || lastHighlighted.textContent;
- if (!text.trim()) return;
- var charCount = text.length;
- var tempInput = document.createElement("textarea");
- tempInput.style.position = "absolute";
- tempInput.style.left = "-9999px";
- tempInput.style.top = "0";
- tempInput.setAttribute("readonly", "");
- tempInput.value = text;
- document.body.appendChild(tempInput);
- var scrollX = window.scrollX || document.documentElement.scrollLeft;
- var scrollY = window.scrollY || document.documentElement.scrollTop;
- tempInput.select();
- try {
- var successful = document.execCommand("copy");
- if (successful) {
- blinkText(lastHighlighted);
- showNotification("Skopírovaných " + charCount + " znakov");
- } else {
- console.error("Kopírovanie zlyhalo");
- }
- } catch (err) {
- console.error("Chyba pri kopírovaní: ", err);
- }
- document.body.removeChild(tempInput);
- window.scrollTo(scrollX, scrollY);
- });
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement