Fix: Add debug logging and better JS loading
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
<name>Minimal Profile</name>
|
<name>Minimal Profile</name>
|
||||||
<summary>Hides profile fields to create a minimal user profile</summary>
|
<summary>Hides profile fields to create a minimal user profile</summary>
|
||||||
<description>Allows administrators to hide profile fields like pronouns, social links, etc.</description>
|
<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>
|
<licence>AGPL</licence>
|
||||||
<author>Your Name</author>
|
<author>Your Name</author>
|
||||||
<namespace>MinimalProfile</namespace>
|
<namespace>MinimalProfile</namespace>
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<routes>
|
<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>
|
</routes>
|
||||||
@@ -1,53 +1,64 @@
|
|||||||
(function() {
|
(function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
console.log('MinimalProfile: Loading...');
|
||||||
|
|
||||||
var fieldSelectors = {
|
var fieldSelectors = {
|
||||||
'pronouns': 'input[id="account-property-pronouns"]',
|
'pronouns': '#account-property-pronouns',
|
||||||
'role': 'input[id="account-property-role"]',
|
'role': '#account-property-role',
|
||||||
'headline': 'input[id="account-property-headline"]',
|
'headline': '#account-property-headline',
|
||||||
'biography': 'input[id="account-property-biography"]',
|
'biography': '#account-property-biography',
|
||||||
'organisation': 'input[id="account-property-organisation"]',
|
'organisation': '#account-property-organisation',
|
||||||
'phone': 'input[id="account-property-phone"]',
|
'phone': '#account-property-phone',
|
||||||
'address': 'input[id="account-property-address"]',
|
'address': '#account-property-address',
|
||||||
'birthdate': 'input[id="account-property-birthdate"]',
|
'birthdate': '#account-property-birthdate',
|
||||||
'website': 'input[id="account-property-website"]',
|
'website': '#account-property-website',
|
||||||
'twitter': 'input[id="account-property-twitter"]',
|
'twitter': '#account-property-twitter',
|
||||||
'fediverse': 'input[id="account-property-fediverse"]',
|
'fediverse': '#account-property-fediverse',
|
||||||
'location': 'input[id="account-property-location"]'
|
'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) {
|
hiddenFields.forEach(function(field) {
|
||||||
var selector = fieldSelectors[field];
|
var selector = fieldSelectors[field];
|
||||||
if (selector) {
|
if (selector) {
|
||||||
var elements = document.querySelectorAll(selector);
|
css += selector + ' { display: none !important; } ';
|
||||||
elements.forEach(function(el) {
|
console.log('MinimalProfile: Hiding', field, selector);
|
||||||
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';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
|
|
||||||
|
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();
|
||||||
var req = new XMLHttpRequest();
|
req.onload = function() {
|
||||||
req.onload = function() {
|
console.log('MinimalProfile: Response status', req.status);
|
||||||
if (req.status === 200) {
|
if (req.status === 200) {
|
||||||
try {
|
try {
|
||||||
var data = JSON.parse(req.responseText);
|
var data = JSON.parse(req.responseText);
|
||||||
if (data.hiddenFields && data.hiddenFields.length > 0) {
|
console.log('MinimalProfile: Data', data);
|
||||||
hideFields(data.hiddenFields);
|
updateCss(data.hiddenFields);
|
||||||
}
|
} catch (e) {
|
||||||
} 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);
|
||||||
})();
|
})();
|
||||||
Reference in New Issue
Block a user