Advertisement
Guest User

myscripts.js - v2

a guest
Apr 15th, 2025
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. window.onload = function () {
  2.     var elements = document.querySelectorAll(".markdown-body *");
  3.     var lastHighlighted = null;
  4.  
  5.     // Notifikačný box (ako predtým)
  6.     var notifyDiv = document.createElement("div");
  7.     notifyDiv.style.position = "fixed";
  8.     notifyDiv.style.top = "20px";
  9.     notifyDiv.style.left = "50%";
  10.     notifyDiv.style.transform = "translateX(-50%)";
  11.     notifyDiv.style.backgroundColor = "#0080ff";
  12.     notifyDiv.style.color = "#ffd700";
  13.     notifyDiv.style.padding = "10px 15px";
  14.     notifyDiv.style.borderRadius = "5px";
  15.     notifyDiv.style.boxShadow = "0 2px 6px rgba(0,0,0,0.3)";
  16.     notifyDiv.style.fontFamily = "'Manrope', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif";
  17.     notifyDiv.style.fontWeight = "600";
  18.     notifyDiv.style.fontSize = "18px";
  19.     notifyDiv.style.zIndex = "9999";
  20.     notifyDiv.style.opacity = "0";
  21.     notifyDiv.style.filter = "alpha(opacity=0)";
  22.     document.body.appendChild(notifyDiv);
  23.  
  24.     var notificationTimeout = null;
  25.     var fadeOutInterval = null;
  26.  
  27.     function showNotification(message) {
  28.         if (notificationTimeout) clearTimeout(notificationTimeout);
  29.         if (fadeOutInterval) clearInterval(fadeOutInterval);
  30.  
  31.         notifyDiv.innerText = message;
  32.         notifyDiv.style.opacity = "1";
  33.         notifyDiv.style.filter = "alpha(opacity=100)";
  34.  
  35.         notificationTimeout = setTimeout(function () {
  36.             var opacity = 1;
  37.             fadeOutInterval = setInterval(function () {
  38.                 opacity -= 0.1;
  39.                 if (opacity <= 0) {
  40.                     clearInterval(fadeOutInterval);
  41.                     notifyDiv.style.opacity = "0";
  42.                     notifyDiv.style.filter = "alpha(opacity=0)";
  43.                 } else {
  44.                     notifyDiv.style.opacity = opacity;
  45.                     notifyDiv.style.filter = "alpha(opacity=" + (opacity * 100) + ")";
  46.                 }
  47.             }, 100);
  48.         }, 2000);
  49.     }
  50.  
  51.     function blinkText(element) {
  52.         var originalColor = element.style.color;
  53.         element.style.color = "transparent";
  54.         setTimeout(function () {
  55.             element.style.color = originalColor;
  56.             setTimeout(function () {
  57.                 element.style.color = "transparent";
  58.                 setTimeout(function () {
  59.                     element.style.color = originalColor;
  60.                 }, 150);
  61.             }, 150);
  62.         }, 150);
  63.     }
  64.  
  65.     // Vyčisti predchádzajúce zvýraznenie
  66.     function clearPreviousHighlight() {
  67.         if (lastHighlighted) {
  68.             lastHighlighted.style.backgroundColor = lastHighlighted.getAttribute("data-original-bg") || "";
  69.         }
  70.         lastHighlighted = null;
  71.     }
  72.  
  73.     // Hlavné zvýraznenie
  74.     for (var i = 0; i < elements.length; i++) {
  75.         (function (element) {
  76.             element.addEventListener("mouseenter", function () {
  77.                 clearPreviousHighlight();
  78.                 this.setAttribute("data-original-bg", this.style.backgroundColor || "");
  79.                 this.style.backgroundColor = "#3B4855";
  80.                 this.style.cursor = "pointer";
  81.                 lastHighlighted = this;
  82.             });
  83.  
  84.             element.addEventListener("mouseleave", function () {
  85.                 // nezrušíme zvýraznenie, len ak sa myš vzdiali úplne
  86.                 // inak by nám to blikalo
  87.             });
  88.         })(elements[i]);
  89.     }
  90.  
  91.     // Kliknutie kdekoľvek – použije posledný zvýraznený element
  92.     document.addEventListener("click", function (event) {
  93.         if (!lastHighlighted) return;
  94.  
  95.         event.preventDefault();
  96.  
  97.         var text = lastHighlighted.innerText || lastHighlighted.textContent;
  98.         if (!text.trim()) return;
  99.  
  100.         var charCount = text.length;
  101.  
  102.         var tempInput = document.createElement("textarea");
  103.         tempInput.style.position = "absolute";
  104.         tempInput.style.left = "-9999px";
  105.         tempInput.style.top = "0";
  106.         tempInput.setAttribute("readonly", "");
  107.         tempInput.value = text;
  108.         document.body.appendChild(tempInput);
  109.  
  110.         var scrollX = window.scrollX || document.documentElement.scrollLeft;
  111.         var scrollY = window.scrollY || document.documentElement.scrollTop;
  112.  
  113.         tempInput.select();
  114.  
  115.         try {
  116.             var successful = document.execCommand("copy");
  117.             if (successful) {
  118.                 blinkText(lastHighlighted);
  119.                 showNotification("Skopírovaných " + charCount + " znakov");
  120.             } else {
  121.                 console.error("Kopírovanie zlyhalo");
  122.             }
  123.         } catch (err) {
  124.             console.error("Chyba pri kopírovaní: ", err);
  125.         }
  126.  
  127.         document.body.removeChild(tempInput);
  128.         window.scrollTo(scrollX, scrollY);
  129.     });
  130. };
  131.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement