-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathindex.js
More file actions
26 lines (25 loc) 路 763 Bytes
/
Copy pathindex.js
File metadata and controls
26 lines (25 loc) 路 763 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
document.addEventListener('DOMContentLoaded', () => {
let els = document.querySelectorAll('div[is]');
do {
swapDivs(els);
els = document.querySelectorAll('div[is]');
} while (els.length > 0);
});
const swapDivs = (els) => {
console.log('Bye bye divs! 馃帀');
els.forEach(el => {
try {
const newEl = document.createElement(el.getAttribute('is'));
[...el.attributes].forEach(at =>
// avoid the endless loop of <div is="div"></div>
!(at.name === 'is' && at.value === 'div')
? newEl.setAttribute(at.name, at.value)
: void 0
);
newEl.innerHTML = el.innerHTML;
el.replaceWith(newEl);
} catch (error) {
console.error(`Cannot convert element: ${el.outerHTML}`);
}
})
}