26 lines
1.0 KiB
Plaintext
26 lines
1.0 KiB
Plaintext
(function (el) {
|
|
if (!el) {
|
|
console.error("Vui lòng chọn thẻ HTML bên tab Elements trước!");
|
|
return;
|
|
}
|
|
const clone = el.cloneNode(true);
|
|
function applyStyles(original, cloned) {
|
|
const computed = window.getComputedStyle(original);
|
|
let styleString = "";
|
|
for (let i = 0; i < computed.length; i++) {
|
|
const prop = computed[i];
|
|
const val = computed.getPropertyValue(prop);
|
|
if (val && val !== "none" && val !== "normal" && val !== "auto") {
|
|
styleString += `${prop}: ${val}; `;
|
|
}
|
|
}
|
|
cloned.setAttribute("style", styleString);
|
|
// Đệ quy quét qua tất cả các con, cháu bên trong để áp dụng CSS
|
|
for (let i = 0; i < original.children.length; i++) {
|
|
applyStyles(original.children[i], cloned.children[i]);
|
|
}
|
|
}
|
|
applyStyles(el, clone);
|
|
copy(clone.outerHTML);
|
|
console.log("👉 Đã copy thành công cả THẺ CHA & CÁC THẺ CON kèm CSS!");
|
|
})($0); |