69 lines
1.6 KiB
JavaScript
69 lines
1.6 KiB
JavaScript
|
// ==UserScript==
|
||
|
// @name New script - spalena53.cz
|
||
|
// @namespace Violentmonkey Scripts
|
||
|
// @match https://www.spalena53.cz/hledat/dostojevskij
|
||
|
// @grant none
|
||
|
// @version 1.0
|
||
|
// @author -
|
||
|
// @description 04/03/2023, 07:42:56
|
||
|
// ==/UserScript==
|
||
|
|
||
|
/**
|
||
|
* @param {string} type
|
||
|
* @param {object} props
|
||
|
* @param {...(string|HTMLElement)} children
|
||
|
* @return {HTMLElement}
|
||
|
*/
|
||
|
function elt(type, props, ...children) {
|
||
|
let dom = document.createElement(type);
|
||
|
if (props) Object.assign(dom, props);
|
||
|
for (let child of children) {
|
||
|
if (typeof child != "string") dom.appendChild(child);
|
||
|
else dom.appendChild(document.createTextNode(child));
|
||
|
}
|
||
|
return dom;
|
||
|
}
|
||
|
|
||
|
let bookElements = document.querySelectorAll(".product.book");
|
||
|
let outOfStockElements = Array.from(bookElements).filter(
|
||
|
(node) => node.querySelector(".availability_info.black") != null
|
||
|
);
|
||
|
|
||
|
/**
|
||
|
*
|
||
|
* @param {HTMLElement} element
|
||
|
*/
|
||
|
function toggleDisplay(element) {
|
||
|
if (element.style.display != "none") element.style.display = "none";
|
||
|
else element.style.display = "";
|
||
|
}
|
||
|
|
||
|
let toggleOutOfStockLabel = elt(
|
||
|
"label",
|
||
|
{
|
||
|
for: "out-of-stock",
|
||
|
className: "change_number",
|
||
|
},
|
||
|
"Toggle out of stock"
|
||
|
);
|
||
|
toggleOutOfStockLabel.cssText = `
|
||
|
height: 38px;
|
||
|
margin-right: 1rem;
|
||
|
`;
|
||
|
|
||
|
let toggleOutOfStockCheckbox = elt("input", {
|
||
|
onclick: (event) => {
|
||
|
outOfStockElements.forEach((element) => toggleDisplay(element));
|
||
|
},
|
||
|
id: "out-of-stock",
|
||
|
type: "checkbox",
|
||
|
className: "change_number",
|
||
|
});
|
||
|
|
||
|
toggleOutOfStockCheckbox.style.cssText = `
|
||
|
height: 33px;
|
||
|
`;
|
||
|
|
||
|
let pageHead = document.querySelector(".page_head");
|
||
|
pageHead.append(toggleOutOfStockLabel, toggleOutOfStockCheckbox);
|