印刷をいい感じにするUserScript
code:script.js
const url = new URL(location.href);
if(url.searchParams.get("print")) {
.map((className) => Array.from(document.querySelectorAll(className)))
.flat(Infinity)
.forEach((el) => {
el.style.display = "none";
});
document.body.style.setProperty("--body-bg", "#fff");
document.querySelector(".app").style.paddingTop = "10px";
document.querySelector(".page").style.boxShadow = "none";
document.querySelector(".col-page-side").style.width = "";
document.querySelector(".col-page-side").style.maxWidth = "";
document.querySelectorAll(".container")1.style.display = "none"; }
//const printCssId = setTimeout(printCss, 500);
const printButton = document.createElement("a");
printButton.classList.add("tool-btn");
const printButtonIcon = document.createElement("i");
printButtonIcon.classList.add("kamon");
printButtonIcon.classList.add("kamon-print");
printButton.appendChild(printButtonIcon);
document.querySelector(".page-menu")?.appendChild(printButton);
printButton.addEventListener("click", () => {
url.searchParams.set("print", 1);
location.href = url.toString();
});
/*
function printCss() {
const s = document?.styleSheets;
if(!s) return;
clearTimeout(printCssId);
for (let i = 0; i < s.length; i++) {
const m = e.media;
if (m?.mediaText === "screen") {
m.mediaText = "all";
} else if (m?.mediaText === "print") {
e.disabled = true;
continue;
}
if (!e.cssRules) continue;
for (let j = 0; j < e.cssRules.length; j++) {
if (!r.media) continue;
if (r?.media?.mediaText === "screen") {
r.media.mediaText = "all";
} else if (r?.media?.mediaText === "print") {
e?.deleteRule(j);
}
}
}
if(url.searchParams.get("print")) {
.map((className) => document.querySelector(className))
.forEach((el) => {
el.style.display = "none";
});
document.querySelectorAll(".container")1.style.display = "none"; }
}
*/