diff --git a/appinfo/info.xml b/appinfo/info.xml index 5886d3a..fd491f3 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -4,7 +4,7 @@ Minimal Profile Hides profile fields to create a minimal user profile Allows administrators to hide profile fields like pronouns, social links, etc. - 1.0.12 + 1.0.13 AGPL Your Name MinimalProfile diff --git a/js/minimalprofile.js b/js/minimalprofile.js index 6637d83..f316242 100644 --- a/js/minimalprofile.js +++ b/js/minimalprofile.js @@ -4,10 +4,10 @@ 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', + organisation': '#account-property-organisation', 'phone': '#account-property-phone', 'address': '#account-property-address', 'birthdate': '#account-property-birthdate', @@ -17,48 +17,52 @@ 'location': '#account-property-location' }; - function updateCss(hiddenFields) { + function applyCss(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); + css += '.personal-settings-setting-box:has(' + selector + ') { display: none !important; } '; + console.log('MinimalProfile: Hiding', field); } - })); + }); - var style = document.createElement('style'); - style.id = 'minimalprofile-style'; - style.textContent = css; - document.head.appendChild(style); - console.log('MinimalProfile: CSS applied', css); + if (css) { + var style = document.createElement('style'); + style.id = 'minimalprofile-style'; + style.textContent = css; + document.head.appendChild(style); + console.log('MinimalProfile: CSS applied'); + } } - 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); + applyCss(data.hiddenFields || []); + } catch (e) { + console.error('MinimalProfile: Parse error', e); + } } - } - }; - req.onerror = function() { - console.error('MinimalProfile: Request failed'); - }; - req.open('GET', OC.generateUrl('/apps/minimalprofile/api/v1/hidden-fields')); - req.send(); + }; + req.onerror = function() { + console.error('MinimalProfile: Request failed'); + }; + 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