Fix: Add debug logging and better JS loading

This commit is contained in:
2026-04-16 14:11:20 +02:00
parent 8a0431f9e7
commit a445c08d8a
3 changed files with 55 additions and 41 deletions

View File

@@ -4,7 +4,7 @@
<name>Minimal Profile</name>
<summary>Hides profile fields to create a minimal user profile</summary>
<description>Allows administrators to hide profile fields like pronouns, social links, etc.</description>
<version>1.0.0</version>
<version>1.0.4</version>
<licence>AGPL</licence>
<author>Your Name</author>
<namespace>MinimalProfile</namespace>

View File

@@ -1,4 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<routes>
<route url="/api/v1/hidden-fields" method="GET" controller="OCA\MinimalProfile\Controller\ApiController:getHiddenFields"/>
<name>MinimalProfile</name>
<routes>
<route url="/api/v1/hidden-fields" methods="GET" controller="\OCA\MinimalProfile\Controller\ApiController::getHiddenFields"/>
</routes>
</routes>

View File

@@ -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;
css += selector + ' { display: none !important; } ';
console.log('MinimalProfile: Hiding', field, selector);
}
if (parent && parent.classList.contains('personal-settings-setting-box')) {
parent.style.display = 'none';
}
});
}
});
}));
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() {
console.log('MinimalProfile: Response status', req.status);
if (req.status === 200) {
try {
var data = JSON.parse(req.responseText);
if (data.hiddenFields && data.hiddenFields.length > 0) {
hideFields(data.hiddenFields);
console.log('MinimalProfile: Data', data);
updateCss(data.hiddenFields);
} catch (e) {
console.error('MinimalProfile: Error', e);
}
} catch (e) {}
}
};
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);
})();