Skip to content

Commit 127dfff

Browse files
committed
Support subtree mutations (htmx). Multiple copies will no longer clash.
1 parent c13dde1 commit 127dfff

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

script.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ new MutationObserver((mutations, observer) => {
44
var cssScopePattern = new RegExp('(\\.me|\\.this|\\.self)(?![A-Za-z0-9\_\-])', 'g') // Can use: .me .this .self
55
for (var mutation of mutations) {
66
if (mutation.type !== "childList") continue
7-
var nodes = [...mutation.addedNodes] // For subtree mutations (ex: htmx) we check all added nodes.
7+
var nodes = [...mutation.addedNodes] // Check new nodes.
88
for (var node = nodes.shift(); node != null; node = nodes.shift()) {
9-
nodes.push(...node.childNodes) // Add all child nodes, too.
9+
nodes.push(...node.childNodes) // Check children of this new node (subtree).
1010
if (node.nodeName !== 'STYLE') continue // Not a <style>
1111
if (!node.parentNode || node.parentNode.nodeName === 'HEAD') continue // Must have parent. Don't style <head>
1212
var scope = 'self_'+(window.cssScopeCount++) // Ready. Make unique scope, example: .self_1234

0 commit comments

Comments
 (0)