Last active
October 27, 2023 15:32
-
-
Save ajmeese7/61b85e493dd830c26c7035b3a4dd5930 to your computer and use it in GitHub Desktop.
Improved Kinopio highlighting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<style> | |
.no-select { | |
user-select: none; | |
} | |
</style> | |
<script> | |
document.addEventListener("DOMContentLoaded", function() { | |
const body = document.querySelector("body"); | |
const textElements = document.querySelectorAll("p, h1, h2, h3, h4, h5, h6, a, span, li, blockquote"); | |
let activeElement = null; | |
body.addEventListener("mousemove", function(e) { | |
for (const textElement of textElements) { | |
const rect = textElement.getBoundingClientRect(); | |
if ( | |
e.clientX >= rect.left && | |
e.clientX <= rect.right && | |
e.clientY >= rect.top && | |
e.clientY <= rect.bottom | |
) { | |
if (textElement !== activeElement) { | |
// Remove no-select class from the previously active element | |
if (activeElement) { | |
activeElement.classList.add("no-select"); | |
} | |
// Allow text selection for the currently interacted text element | |
textElement.classList.remove("no-select"); | |
activeElement = textElement; | |
} | |
return; | |
} | |
} | |
// Mouse is not interacting with any text element, prevent text selection | |
if (activeElement) { | |
activeElement.classList.add("no-select"); | |
activeElement = null; | |
} | |
}); | |
}); | |
</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function redrawAllStrokes () { | |
if (allStrokes.length === 0) { return } | |
allStrokes = allStrokes.filter(stroke => { | |
return stroke.length | |
}) | |
allStrokes.forEach(stroke => { | |
currentPaintStroke = stroke | |
drawCurrentStroke() | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment