From 1acfd5e991147860426f4db82ef9716a1a20d00e Mon Sep 17 00:00:00 2001 From: "christian.schmied" Date: Tue, 25 Mar 2025 10:14:23 +0100 Subject: [PATCH] =?UTF-8?q?erweitern=20um=20notizfeld,=20hinzuf=C3=BCgen?= =?UTF-8?q?=20des=20Nachorder=20Portals?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SportWanninger_OrderNotes.user.js | 163 +++++++++++++++++++++--------- 1 file changed, 117 insertions(+), 46 deletions(-) diff --git a/SportWanninger_OrderNotes.user.js b/SportWanninger_OrderNotes.user.js index f408a20..5f1e3b7 100644 --- a/SportWanninger_OrderNotes.user.js +++ b/SportWanninger_OrderNotes.user.js @@ -1,21 +1,44 @@ // ==UserScript== // @name SportWanninger OrderNotes // @namespace http://sportwanninger.de/ -// @version 2024-11-28 +// @version 2025-03-25 // @updateURL https://git.sportwanninger.de/Public/UserScripts/raw/branch/master/SportWanninger_OrderNotes.user.js // @downloadURL https://git.sportwanninger.de/Public/UserScripts/raw/branch/master/SportWanninger_OrderNotes.user.js // @description Vordefinierte Notizen für Smart.Order // @author Christian Schmied // @match https://vororder.intersport.de/* +// @match https://nachorder.intersport.de/* // @icon https://www.google.com/s2/favicons?sz=64&domain=intersport.de // @grant none // ==/UserScript== -const ISWOptions = [ - {name: "NO_ONLINE"}, - {name: "NO_MARKET"}, - {name: "Z-FLYER"}, - {name: "HausPreis", type: "price"} +const DEBUG = false; + +const ISWOptions = [{ + name: "NOTE", + type: "textarea", + body: true + }, + { + name: "NO_ONLINE", + type: "checkbox" + }, + { + name: "NO_MARKET", + type: "checkbox" + }, + { + name: "Z-FLYER", + type: "checkbox" + }, + { + name: "HausPreis", + type: "price" + }, + { + name: "OriginalPreis", + type: "price" + }, ]; var observeDOM = (function() { @@ -31,7 +54,10 @@ var observeDOM = (function() { var mutationObserver = new MutationObserver(callback); // have the observer observe for changes in children - mutationObserver.observe(obj, {childList: true, subtree: true}); + mutationObserver.observe(obj, { + childList: true, + subtree: true + }); return mutationObserver; } else if (window.addEventListener) { // browser support fallback obj.addEventListener('DOMNodeInserted', callback, false); @@ -53,20 +79,26 @@ function debounce(func, timeout = 300) { var debouncedEvaluate = debounce(evaluateForNoteFields) -function evaluateForNoteFields(){ +function evaluateForNoteFields() { let noteContainer = document.getElementsByClassName("note-container"); console.log(`found ${noteContainer.length} note Containers`); - if(noteContainer.length !== 1){ + if (noteContainer.length !== 1) { return } let textArea = noteContainer[0].getElementsByClassName("note-input"); let selectionList = noteContainer[0].getElementsByClassName("isw-note-selection"); - if(selectionList.length === 0) { - //textArea[0].style.display="none"; - textArea[0].addEventListener("change", (e)=>console.log("Hi ;D", e)); + if (selectionList.length === 0) { + if (!DEBUG) { + textArea[0].parentNode.style.height = "0px"; + textArea[0].parentNode.style.padding = "0px"; + textArea[0].parentNode.style.border = "0px"; + textArea[0].style.height = "0px"; + } + textArea[0].disabled = true; + textArea[0].addEventListener("change", (e) => console.log("Hi ;D", e)); addSelectionList(noteContainer[0], textArea[0]); } } @@ -77,18 +109,27 @@ const templateFoot = ''; function addSelectionList(parent, textArea) { const template = document.createElement('template'); var tBody = ""; - for(const option of ISWOptions) { - if(option.type === "price") { - tBody += `
${option.name}` + for (const option of ISWOptions) { + if (option.type === "price") { + tBody += `` + } else if (option.type === "text") { + tBody += `` + } else if (option.type === "textarea") { + tBody += `` } else { - tBody += `` - } + tBody += `` + } } template.innerHTML = templateHead + tBody + templateFoot; - var allInputs = template.content.firstChild.getElementsByTagName("input"); - for(const input of allInputs) { - input.onchange=handleIswChange(textArea); - input.oninput=handleIswChange(textArea); + var allInputs = template.content.firstChild.getElementsByClassName("isw-input"); + for (const input of allInputs) { + input.onchange = handleIswChange(textArea); + input.oninput = handleIswChange(textArea); } parent.insertBefore(template.content.firstChild, textArea.parent); updateFromTextArea(textArea, parent.getElementsByClassName("isw-note-selection")[0]); @@ -99,32 +140,42 @@ function handleIswChange(textArea) { console.log(event); const name = event.target.getAttribute("data-name"); - const type = event.target.getAttribute("type"); + const type = event.target.getAttribute("data-type"); + const body = event.target.getAttribute("data-body"); var value = event.target.value; - if(type === "checkbox") { + if (type === "checkbox") { value = event.target.checked; - }else if(type === "number"){ + } else if (type === "price") { value = parseFloat(value); } console.log("handleIswChange", name, value); - setPropertyValue(textArea, name, value) + if (body === "true") { + setOtherValue(textArea, value); + } else { + setPropertyValue(textArea, name, value); + } } } -function updateFromTextArea(textArea, fieldSet){ - const {obj} = parseTextArea(textArea); - const inputs = fieldSet.getElementsByTagName("input"); +function updateFromTextArea(textArea, fieldSet) { + const { obj, other } = parseTextArea(textArea); + const inputs = fieldSet.getElementsByClassName("isw-input"); for (const input of inputs) { const name = input.getAttribute("data-name"); - const type = input.getAttribute("type"); - if(type === "checkbox") { - input.checked = obj[name]||false; - }else { - input.value = obj[name]||""; + const type = input.getAttribute("data-type"); + const body = input.getAttribute("data-body"); + if (body === "true") { + input.value = other + } else { + if (type === "checkbox") { + input.checked = obj[name] || false; + } else { + input.value = obj[name] || ""; + } } } } @@ -133,13 +184,18 @@ function parseTextArea(textArea) { const split = textArea.value.split("\n"); var jsonString = split[0]; var obj = {}; - if(jsonString.length>0 && jsonString.charAt(0) == "{") { + if (jsonString.length > 0 && jsonString.charAt(0) == "{") { obj = JSON.parse(jsonString); + } else { + return { + obj: obj, + other: textArea.value.trim() + }; } var other = ""; - if(split.length>1){ - other = split.slice(1).join('\n'); + if (split.length > 1) { + other = split.slice(1); } return { @@ -148,27 +204,41 @@ function parseTextArea(textArea) { }; } -function setPropertyValue(textArea,name,value){ - const {obj, other} = parseTextArea(textArea); +function setPropertyValue(textArea, name, value) { + const { + obj, + other + } = parseTextArea(textArea); + console.log("PropValue: other:" + other); - if(value === false || value === 0){ - obj[name]=undefined; - }else{ - obj[name]=value; + if (value === false || value === 0) { + obj[name] = undefined; + } else { + obj[name] = value; } + updateTextAreaValue(textArea, obj, other); +} + +function setOtherValue(textArea, newOther) { + const { obj } = parseTextArea(textArea); + + updateTextAreaValue(textArea, obj, newOther); +} + +function updateTextAreaValue(textArea, obj, other) { var jsonString = JSON.stringify(obj); - if(jsonString==="{}") { + if (jsonString === "{}") { jsonString = ""; } var fullString = jsonString; - if(other.length>0){ - fullString+="\n"+other; + if (other.length > 0) { + fullString += "\n" + other; } - textArea.value = fullString; + textArea.value = fullString.trim(); var e = new Event('input', { bubbles: true, @@ -177,6 +247,7 @@ function setPropertyValue(textArea,name,value){ textArea.dispatchEvent(e); } + (function() { 'use strict';