erweitern um notizfeld, hinzufügen des Nachorder Portals
This commit is contained in:
parent
1034caefd4
commit
1acfd5e991
1 changed files with 117 additions and 46 deletions
|
@ -1,21 +1,44 @@
|
||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name SportWanninger OrderNotes
|
// @name SportWanninger OrderNotes
|
||||||
// @namespace http://sportwanninger.de/
|
// @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
|
// @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
|
// @downloadURL https://git.sportwanninger.de/Public/UserScripts/raw/branch/master/SportWanninger_OrderNotes.user.js
|
||||||
// @description Vordefinierte Notizen für Smart.Order
|
// @description Vordefinierte Notizen für Smart.Order
|
||||||
// @author Christian Schmied <cs@sport-wanninger.de>
|
// @author Christian Schmied <cs@sport-wanninger.de>
|
||||||
// @match https://vororder.intersport.de/*
|
// @match https://vororder.intersport.de/*
|
||||||
|
// @match https://nachorder.intersport.de/*
|
||||||
// @icon https://www.google.com/s2/favicons?sz=64&domain=intersport.de
|
// @icon https://www.google.com/s2/favicons?sz=64&domain=intersport.de
|
||||||
// @grant none
|
// @grant none
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
|
|
||||||
const ISWOptions = [
|
const DEBUG = false;
|
||||||
{name: "NO_ONLINE"},
|
|
||||||
{name: "NO_MARKET"},
|
const ISWOptions = [{
|
||||||
{name: "Z-FLYER"},
|
name: "NOTE",
|
||||||
{name: "HausPreis", type: "price"}
|
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() {
|
var observeDOM = (function() {
|
||||||
|
@ -31,7 +54,10 @@ var observeDOM = (function() {
|
||||||
var mutationObserver = new MutationObserver(callback);
|
var mutationObserver = new MutationObserver(callback);
|
||||||
|
|
||||||
// have the observer observe for changes in children
|
// have the observer observe for changes in children
|
||||||
mutationObserver.observe(obj, {childList: true, subtree: true});
|
mutationObserver.observe(obj, {
|
||||||
|
childList: true,
|
||||||
|
subtree: true
|
||||||
|
});
|
||||||
return mutationObserver;
|
return mutationObserver;
|
||||||
} else if (window.addEventListener) { // browser support fallback
|
} else if (window.addEventListener) { // browser support fallback
|
||||||
obj.addEventListener('DOMNodeInserted', callback, false);
|
obj.addEventListener('DOMNodeInserted', callback, false);
|
||||||
|
@ -53,20 +79,26 @@ function debounce(func, timeout = 300) {
|
||||||
|
|
||||||
var debouncedEvaluate = debounce(evaluateForNoteFields)
|
var debouncedEvaluate = debounce(evaluateForNoteFields)
|
||||||
|
|
||||||
function evaluateForNoteFields(){
|
function evaluateForNoteFields() {
|
||||||
let noteContainer = document.getElementsByClassName("note-container");
|
let noteContainer = document.getElementsByClassName("note-container");
|
||||||
console.log(`found ${noteContainer.length} note Containers`);
|
console.log(`found ${noteContainer.length} note Containers`);
|
||||||
|
|
||||||
if(noteContainer.length !== 1){
|
if (noteContainer.length !== 1) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let textArea = noteContainer[0].getElementsByClassName("note-input");
|
let textArea = noteContainer[0].getElementsByClassName("note-input");
|
||||||
let selectionList = noteContainer[0].getElementsByClassName("isw-note-selection");
|
let selectionList = noteContainer[0].getElementsByClassName("isw-note-selection");
|
||||||
|
|
||||||
if(selectionList.length === 0) {
|
if (selectionList.length === 0) {
|
||||||
//textArea[0].style.display="none";
|
if (!DEBUG) {
|
||||||
textArea[0].addEventListener("change", (e)=>console.log("Hi ;D", e));
|
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]);
|
addSelectionList(noteContainer[0], textArea[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,18 +109,27 @@ const templateFoot = '</div>';
|
||||||
function addSelectionList(parent, textArea) {
|
function addSelectionList(parent, textArea) {
|
||||||
const template = document.createElement('template');
|
const template = document.createElement('template');
|
||||||
var tBody = "";
|
var tBody = "";
|
||||||
for(const option of ISWOptions) {
|
for (const option of ISWOptions) {
|
||||||
if(option.type === "price") {
|
if (option.type === "price") {
|
||||||
tBody += `<div>${option.name}<input type="number" min="0" step="0.01" style="margin-left: .5em; border: 1px solid #c6c6c6; border-radius: 0.25em;" name="isw-option-${option.name}" data-name="${option.name}"/></label>`
|
tBody += `<label>${option.name}<input class="isw-input" type="number" min="0" step="0.01" style="margin-left: .5em; border: 1px solid #c6c6c6; border-radius: 0.25em;" name="isw-option-${option.name}" data-name="${option.name}" data-type="${option.type}"/></label>`
|
||||||
|
} else if (option.type === "text") {
|
||||||
|
tBody += `<label>${option.name}<input class="isw-input" type="text" style="margin-left: .5em; border: 1px solid #c6c6c6; border-radius: 0.25em;" name="isw-option-${option.name}" data-name="${option.name}" data-type="${option.type}"/></label>`
|
||||||
|
} else if (option.type === "textarea") {
|
||||||
|
tBody += `<label>${option.name}
|
||||||
|
<textarea class="isw-input" style="margin-left: .5em; border: 1px solid #c6c6c6; border-radius: 0.25em;"
|
||||||
|
name="isw-option-${option.name}" data-name="${option.name}" data-type="${option.type}" data-body="true"
|
||||||
|
>
|
||||||
|
</textarea>
|
||||||
|
</label>`
|
||||||
} else {
|
} else {
|
||||||
tBody += `<label><input type="checkbox" style="margin-right: .5em;" name="isw-option-${option.name}" data-name="${option.name}"/>${option.name}</label>`
|
tBody += `<label><input class="isw-input" type="checkbox" style="margin-right: .5em;" name="isw-option-${option.name}" data-name="${option.name}" data-type="${option.type}"/>${option.name}</label>`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
template.innerHTML = templateHead + tBody + templateFoot;
|
template.innerHTML = templateHead + tBody + templateFoot;
|
||||||
var allInputs = template.content.firstChild.getElementsByTagName("input");
|
var allInputs = template.content.firstChild.getElementsByClassName("isw-input");
|
||||||
for(const input of allInputs) {
|
for (const input of allInputs) {
|
||||||
input.onchange=handleIswChange(textArea);
|
input.onchange = handleIswChange(textArea);
|
||||||
input.oninput=handleIswChange(textArea);
|
input.oninput = handleIswChange(textArea);
|
||||||
}
|
}
|
||||||
parent.insertBefore(template.content.firstChild, textArea.parent);
|
parent.insertBefore(template.content.firstChild, textArea.parent);
|
||||||
updateFromTextArea(textArea, parent.getElementsByClassName("isw-note-selection")[0]);
|
updateFromTextArea(textArea, parent.getElementsByClassName("isw-note-selection")[0]);
|
||||||
|
@ -99,32 +140,42 @@ function handleIswChange(textArea) {
|
||||||
console.log(event);
|
console.log(event);
|
||||||
|
|
||||||
const name = event.target.getAttribute("data-name");
|
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;
|
var value = event.target.value;
|
||||||
|
|
||||||
if(type === "checkbox") {
|
if (type === "checkbox") {
|
||||||
value = event.target.checked;
|
value = event.target.checked;
|
||||||
}else if(type === "number"){
|
} else if (type === "price") {
|
||||||
value = parseFloat(value);
|
value = parseFloat(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("handleIswChange", name, 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){
|
function updateFromTextArea(textArea, fieldSet) {
|
||||||
const {obj} = parseTextArea(textArea);
|
const { obj, other } = parseTextArea(textArea);
|
||||||
const inputs = fieldSet.getElementsByTagName("input");
|
const inputs = fieldSet.getElementsByClassName("isw-input");
|
||||||
for (const input of inputs) {
|
for (const input of inputs) {
|
||||||
const name = input.getAttribute("data-name");
|
const name = input.getAttribute("data-name");
|
||||||
const type = input.getAttribute("type");
|
const type = input.getAttribute("data-type");
|
||||||
if(type === "checkbox") {
|
const body = input.getAttribute("data-body");
|
||||||
input.checked = obj[name]||false;
|
if (body === "true") {
|
||||||
}else {
|
input.value = other
|
||||||
input.value = obj[name]||"";
|
} 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");
|
const split = textArea.value.split("\n");
|
||||||
var jsonString = split[0];
|
var jsonString = split[0];
|
||||||
var obj = {};
|
var obj = {};
|
||||||
if(jsonString.length>0 && jsonString.charAt(0) == "{") {
|
if (jsonString.length > 0 && jsonString.charAt(0) == "{") {
|
||||||
obj = JSON.parse(jsonString);
|
obj = JSON.parse(jsonString);
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
obj: obj,
|
||||||
|
other: textArea.value.trim()
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
var other = "";
|
var other = "";
|
||||||
if(split.length>1){
|
if (split.length > 1) {
|
||||||
other = split.slice(1).join('\n');
|
other = split.slice(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -148,27 +204,41 @@ function parseTextArea(textArea) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function setPropertyValue(textArea,name,value){
|
function setPropertyValue(textArea, name, value) {
|
||||||
const {obj, other} = parseTextArea(textArea);
|
const {
|
||||||
|
obj,
|
||||||
|
other
|
||||||
|
} = parseTextArea(textArea);
|
||||||
|
console.log("PropValue: other:" + other);
|
||||||
|
|
||||||
if(value === false || value === 0){
|
if (value === false || value === 0) {
|
||||||
obj[name]=undefined;
|
obj[name] = undefined;
|
||||||
}else{
|
} else {
|
||||||
obj[name]=value;
|
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);
|
var jsonString = JSON.stringify(obj);
|
||||||
|
|
||||||
if(jsonString==="{}") {
|
if (jsonString === "{}") {
|
||||||
jsonString = "";
|
jsonString = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
var fullString = jsonString;
|
var fullString = jsonString;
|
||||||
if(other.length>0){
|
if (other.length > 0) {
|
||||||
fullString+="\n"+other;
|
fullString += "\n" + other;
|
||||||
}
|
}
|
||||||
|
|
||||||
textArea.value = fullString;
|
textArea.value = fullString.trim();
|
||||||
|
|
||||||
var e = new Event('input', {
|
var e = new Event('input', {
|
||||||
bubbles: true,
|
bubbles: true,
|
||||||
|
@ -177,6 +247,7 @@ function setPropertyValue(textArea,name,value){
|
||||||
textArea.dispatchEvent(e);
|
textArea.dispatchEvent(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue