More attributes

This commit is contained in:
Jiiks 2018-03-10 14:27:17 +02:00
parent da6aecc3f2
commit 2952331998
3 changed files with 49 additions and 2 deletions

View File

@ -43,7 +43,7 @@ export default class extends EventListener {
constructor() {
super();
window.injectAc = this.injectAutocomplete;
window.r = Reflection;
const messageFilter = function (m) {
return m.addedNodes && m.addedNodes.length && m.addedNodes[0].classList && m.addedNodes[0].classList.contains('message-group');
}
@ -74,6 +74,40 @@ export default class extends EventListener {
this.setChannelIds();
Events.emit('ui:loadedmorechannels', mutations.map(m => m.addedNodes[0]));
}, 'filter');
const popoutFilter = function(m) {
return m.addedNodes &&
m.addedNodes.length &&
m.addedNodes[0].className &&
m.addedNodes[0].className.includes('popout');
}
DOM.observer.subscribe('userpopout-manip', popoutFilter, mutations => {
const userPopout = document.querySelector('[class*=userPopout]');
if (!userPopout) return;
const user = Reflection(userPopout).prop('user');
if (!user) return;
userPopout.setAttribute('data-user-id', user.id);
if (user.id === TempApi.currentUserId) userPopout.setAttribute('data-currentuser', true);
}, 'filter');
const modalFilter = function(m) {
return m.addedNodes &&
m.addedNodes.length &&
m.addedNodes[0].className &&
m.addedNodes[0].className.includes('modal');
}
DOM.observer.subscribe('modal-manip', modalFilter, mutations => {
const userModal = document.querySelector('[class*=modal] > [class*=inner]');
if (!userModal) return;
const user = Reflection(userModal).prop('user');
if (!user) return;
const modal = userModal.closest('[class*=modal]');
if (!modal) return;
modal.setAttribute('data-user-id', user.id);
if (user.id === TempApi.currentUserId) modal.setAttribute('data-currentuser', true);
});
}
bindings() {

View File

@ -91,7 +91,7 @@ export default class extends EventListener {
inject(userid) {
const c = this.contributors.find(c => c.id === userid);
if (!c) return;
setTimeout(() => {
let hasBadges = false;
let root = document.querySelector('[class*="profileBadges"]');

View File

@ -21,6 +21,8 @@ class Reflection {
if (!ii) return null;
const fir = this.findInReturn(ii, prop);
if (fir) return fir;
const fim = this.findInChildProps(ii, prop);
if (fim) return fim;
return null;
}
@ -46,6 +48,17 @@ class Reflection {
return this.findPropIn(obj, prop);
}
static findInChildProps(obj, prop) {
try {
const f = obj.children || obj.memoizedProps.children;
if (!f.props) return null;
if (!f.props.hasOwnProperty(prop)) return null;
return f.props[prop];
} catch (err) {
return null;
}
}
static findPropIn(obj, prop) {
if (obj && !(obj instanceof Array) && obj instanceof Object && obj.hasOwnProperty(prop)) return obj[prop];
if (obj && obj instanceof Array) {