PageSourceSearch

https://farming-simulator.com/js/support.js?v=1596877541

js farming-simulator.com collected 2026-10-01 09:12:22 UTC 8,189 bytes, 223 lines download raw bytes

1//Global tag array, sub array per form element
2let supportFilterTagIds = [];
3
4let formElementIndex = 1;
5
6const formElements = document.getElementsByClassName("supportFormElement");
7
8[...formElements].forEach((formelement) => {
9    formelement.addEventListener('change', function () {
10        filterAndShowNextFormElement(formelement);
11    });
12});
13
14const continueButton = document.getElementById("continueButton");
15
16continueButton.addEventListener('click', function () {
17    filterAndShowNextFormElement(continueButton);
18})
19
20//initialize tag array with empty array per form element
21supportFilterTagIds = Array(formElements.length).fill([]);
22
23function filterAndShowNextFormElement(element) {
24
25    // button, input or select
26    let elementType = element.getAttribute('data-input-type').toLowerCase();
27
28    let option;
29    if (elementType === 'select') {
30        let selectedIndex = element.selectedIndex;
31        option = element.options[selectedIndex];
32    } else {
33        option = element;
34    }
35
36    let articleContent = option.getAttribute('data-content')
37
38    //hide form submit input rows if disabled for this issue
39    let showFormSubmit = option.getAttribute("data-show-form-submit");
40    if (showFormSubmit === "0") {
41        return;
42    }
43
44    //current index of the selected input field
45    formElementIndex = element.getAttribute("data-form-element");
46    resetFormElements(formElementIndex);
47
48    //set tags of the selected option
49    supportFilterTagIds[formElementIndex] = parseTagIdsString(option.getAttribute('data-sets-tags'));
50
51    //iterate over the next form Elements
52    let nextFormElement;
53    while (true) {
54        let nextFormElements = document.querySelectorAll("[data-form-element='" + (Number(formElementIndex) + 1) + "']")
55        //reached last form element
56        if (nextFormElements.length !== 1) {
57            break;
58        }
59        nextFormElement = nextFormElements[0];
60        //check if the entire input row should be shown or not
61        let showInput = filterInputElement(nextFormElement);
62        const nextElementType = nextFormElement.getAttribute('data-input-type').toLowerCase();
63        let showOptions = true
64        if (nextElementType === 'select') {
65
66            //checks every option of the select if they are valid and should be visible
67            showOptions = Array.from(nextFormElement.options).slice(1).map((option) => filterInputElement(option));
68
69            // count of still valid options for this select field
70            let countOption = showOptions.reduce(function (acc, currentValue) {
71                return acc + (currentValue ? 1 : 0);
72            }, 0);
73
74            //if only one valid option left then preselect it
75            if (countOption === 1) {
76                showOptions.forEach(function (visible, index) {
77                    if (visible) {
78                        nextFormElement.selectedIndex = index + 1;
79                        if (nextFormElement.id === 'formArticleSelect') {
80                            showArticleContent(nextFormElement);
81                        }
82                    }
83                });
84                let onlyOption = nextFormElement.options[nextFormElement.selectedIndex];
85
86                //set tags of the onlyOption
87                supportFilterTagIds[formElementIndex+1] = parseTagIdsString(onlyOption.getAttribute('data-sets-tags'));
88
89                // hide form submit input rows if disabled for this issue
90                let showFormSubmit = onlyOption.getAttribute("data-show-form-submit");
91                if (showFormSubmit === "0") {
92                    return;
93                }
94                formElementIndex++;
95                continue;
96            }
97            showOptions = showOptions.reduce((acc, curr) => acc || curr, false);
98        }
99        if (showInput && showOptions) {
100            if (nextElementType === 'select') {
101                break;
102            }
103            if (nextElementType === 'button') {
104                if (articleContent) {
105                    startContinueTimer(nextFormElement, 5)
106                    break;
107                } else {
108                    nextFormElement.required = false;
109                    hideFormRow(1 + formElementIndex);
110                }
111            }
112            formElementIndex++;
113        } else {
114            // hide not valid form rows and set to not required
115            hideFormRow(Number(formElementIndex++) + 1);
116            nextFormElement.required = false;
117        }
118    }
119}
120
121function startContinueTimer(button, seconds) {
122    button.disabled = true;
123    // Set initial value on the button
124    let text = button.getAttribute('data-continue-text');
125    button.value = (text + ' ' + seconds);
126    const countdown = setInterval(function () {
127        seconds--;
128        button.value = text + ' ' + seconds;
129        if (seconds <= 0) {
130            clearInterval(countdown);
131            button.value = text;
132            button.disabled = false;
133        }
134    }, 1000);
135}
136
137/**
138 * hides and disables any not valid input fields based on the currently set tags and the input fields required or disallowed tags
139 * @param element
140 * @returns boolean
141 */
142function filterInputElement(element) {
143    let requiredTags = parseTagIdsString(element.getAttribute('data-required-tags'));
144    let disallowedTags = parseTagIdsString(element.getAttribute('data-disallow-tags'));
145    let allRequirements = requiredTags.every(requiredTag => supportFilterTagIds.flat().includes(requiredTag));
146    let notDisallowed = disallowedTags.every(disallowedTag => !supportFilterTagIds.flat().includes(disallowedTag));
147    let rowId = element.getAttribute('data-form-element');
148    if (!allRequirements || !notDisallowed) {
149        hideFormRow(rowId)
150        element.classList.add("hidden");
151        element.disabled = true;
152        return false
153    } else {
154        showFormRow(rowId)
155        element.classList.remove("hidden");
156        element.disabled = false;
157        return true;
158    }
159}
160
161/**
162 * extracts the comma seperated tag ids
163 * @param tagsString
164 * @returns number[]
165 */
166function parseTagIdsString(tagsString) {
167    if (tagsString === null || tagsString === '') {
168        return []
169    }
170    return tagsString.split(',').map(num => parseInt(num))
171}
172
173/**
174 * resets all form element rows with greater or equal form element index
175 * @param dataFormIndex
176 */
177function resetFormElements(dataFormIndex) {
178    for (let i = dataFormIndex; i < supportFilterTagIds.length; i++) {
179        supportFilterTagIds[i] = [];
180    }
181    let appendingFormElement = [...formElements].filter((formElement) => Number(formElement.getAttribute('data-form-element')) > Number(dataFormIndex));
182    appendingFormElement.forEach((formElement) => formElement.selectedIndex = 0);
183    appendingFormElement.forEach((formElement) => {
184        let rowId = formElement.getAttribute('data-form-element')
185        if (formElement.id === 'formArticleSelect') {
186            let articleConentDiv = document.getElementById('articleContentDiv');
187            articleConentDiv.parentElement.classList.add('hidden');
188        }
189        hideFormRow(rowId)
190    })
191
192}
193
194function hideFormRow(rowIndex) {
195    rowIndex = Number.parseInt(rowIndex);
196    if (rowIndex) {
197        let inputRows = document.querySelectorAll("[data-form-element-row='" + (Number(rowIndex)) + "'");
198        [...inputRows].forEach((row) => row.classList.add('hidden'));
199    }
200}
201
202function showFormRow(rowIndex) {
203    rowIndex = Number.parseInt(rowIndex);
204    if (rowIndex) {
205        let inputRows = document.querySelectorAll("[data-form-element-row='" + (Number(rowIndex)) + "'");
206        [...inputRows].forEach((row) => row.classList.remove('hidden'));
207    }
208}
209
210/**
211 * Sets relevant Article  visible for selected Issue
212 * @param selectedArticle
213 */
214function showArticleContent(selectedArticle) {
215    let selectedIndex = selectedArticle.selectedIndex;
216    let option = selectedArticle.options[selectedIndex];
217    let articleContent = option.getAttribute('data-content');
218    let articleConentDiv = document.getElementById('articleContentDiv');
219    if (articleContent) {
220        articleConentDiv.parentElement.classList.remove('hidden');
221        articleConentDiv.innerHTML = articleContent;
222    }
223}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.