From 732c553245fd5e1d740971a805448c656b473a70 Mon Sep 17 00:00:00 2001 From: Guy Van Sanden Date: Thu, 16 Apr 2026 15:05:53 +0200 Subject: [PATCH] Final clean version --- js/minimalprofile.js | 75 ++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 41 deletions(-) diff --git a/js/minimalprofile.js b/js/minimalprofile.js index 6637d83..cf07683 100644 --- a/js/minimalprofile.js +++ b/js/minimalprofile.js @@ -1,10 +1,12 @@ +/** + * Minimal Profile - Show fields based on config + */ (function() { 'use strict'; - console.log('MinimalProfile: Loading...'); var fieldSelectors = { 'pronouns': '#account-property-pronouns', - 'role': '#account-property-role', + 'role': '#account-property-role', 'headline': '#account-property-headline', 'biography': '#account-property-biography', 'organisation': '#account-property-organisation', @@ -17,48 +19,39 @@ 'location': '#account-property-location' }; - function updateCss(hiddenFields) { - if (!hiddenFields || hiddenFields.length === 0) { - console.log('MinimalProfile: No hidden fields'); - return; - } - var css = ''; - hiddenFields.forEach(function(field) { - var selector = fieldSelectors[field]; - if (selector) { - css += selector + ' { display: none !important; } '; - console.log('MinimalProfile: Hiding', field, selector); + function showFields(hiddenFields) { + var allFields = Object.keys(fieldSelectors); + allFields.forEach(function(field) { + if (!hiddenFields.includes(field)) { + var selector = fieldSelectors[field]; + var el = document.querySelector(selector); + if (el) { + var box = el.closest('.personal-settings-setting-box'); + if (box) { + box.style.display = ''; + } + } } - })); - - var style = document.createElement('style'); - style.id = 'minimalprofile-style'; - style.textContent = css; - document.head.appendChild(style); - console.log('MinimalProfile: CSS applied', css); + }); } - var req = new XMLHttpRequest(); - req.onload = function() { - console.log('MinimalProfile: Response status', req.status); - if (req.status === 200) { - try { - var data = JSON.parse(req.responseText); - console.log('MinimalProfile: Data', data); - updateCss(data.hiddenFields); - } catch (e) { - console.error('MinimalProfile: Error', e); + function init() { + var req = new XMLHttpRequest(); + req.onload = function() { + if (req.status === 200) { + try { + var data = JSON.parse(req.responseText); + showFields(data.hiddenFields || []); + } catch (e) {} } - } - }; - req.onerror = function() { - console.error('MinimalProfile: Request failed'); - }; - req.open('GET', OC.generateUrl('/apps/minimalprofile/api/v1/hidden-fields')); - req.send(); + }; + req.open('GET', OC.generateUrl('/apps/minimalprofile/api/v1/hidden-fields')); + req.send(); + } - setTimeout(function() { - var el = document.querySelector('#account-property-pronouns'); - console.log('MinimalProfile: Pronouns element found?', !!el); - }, 3000); + if (document.readyState === 'loading') { + document.addEventListener('DOMContentLoaded', init); + } else { + init(); + } })(); \ No newline at end of file