diff --git a/appinfo/info.xml b/appinfo/info.xml index e941e33..c9a3817 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.0 + 1.0.4 AGPL Your Name MinimalProfile diff --git a/appinfo/routes.xml b/appinfo/routes.xml index 8265282..82ed7e7 100644 --- a/appinfo/routes.xml +++ b/appinfo/routes.xml @@ -1,4 +1,7 @@ - + MinimalProfile + + + \ No newline at end of file diff --git a/js/minimalprofile.js b/js/minimalprofile.js index ab3e31e..6637d83 100644 --- a/js/minimalprofile.js +++ b/js/minimalprofile.js @@ -1,53 +1,64 @@ (function() { 'use strict'; + console.log('MinimalProfile: Loading...'); var fieldSelectors = { - 'pronouns': 'input[id="account-property-pronouns"]', - 'role': 'input[id="account-property-role"]', - 'headline': 'input[id="account-property-headline"]', - 'biography': 'input[id="account-property-biography"]', - 'organisation': 'input[id="account-property-organisation"]', - 'phone': 'input[id="account-property-phone"]', - 'address': 'input[id="account-property-address"]', - 'birthdate': 'input[id="account-property-birthdate"]', - 'website': 'input[id="account-property-website"]', - 'twitter': 'input[id="account-property-twitter"]', - 'fediverse': 'input[id="account-property-fediverse"]', - 'location': 'input[id="account-property-location"]' + 'pronouns': '#account-property-pronouns', + 'role': '#account-property-role', + 'headline': '#account-property-headline', + 'biography': '#account-property-biography', + 'organisation': '#account-property-organisation', + 'phone': '#account-property-phone', + 'address': '#account-property-address', + 'birthdate': '#account-property-birthdate', + 'website': '#account-property-website', + 'twitter': '#account-property-twitter', + 'fediverse': '#account-property-fediverse', + 'location': '#account-property-location' }; - function hideFields(hiddenFields) { + 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) { - var elements = document.querySelectorAll(selector); - elements.forEach(function(el) { - var parent = el.parentElement; - while (parent && !parent.classList.contains('personal-settings-setting-box')) { - parent = parent.parentElement; - if (!parent) return; - } - if (parent && parent.classList.contains('personal-settings-setting-box')) { - parent.style.display = 'none'; - } - }); + css += selector + ' { display: none !important; } '; + console.log('MinimalProfile: Hiding', field, selector); } - }); + })); + + var style = document.createElement('style'); + style.id = 'minimalprofile-style'; + style.textContent = css; + document.head.appendChild(style); + console.log('MinimalProfile: CSS applied', css); } - OCP.registerLoadEndpoint(function() { - var req = new XMLHttpRequest(); - req.onload = function() { - if (req.status === 200) { - try { - var data = JSON.parse(req.responseText); - if (data.hiddenFields && data.hiddenFields.length > 0) { - hideFields(data.hiddenFields); - } - } catch (e) {} + 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); } - }; - 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); })(); \ No newline at end of file