#3 improved performance of language display update in lists

Only tries to update if the node is a list element and only updates the single node instead of fetching and updating all nodes each time the page changes
This commit is contained in:
Serraniel 2020-09-27 12:01:35 +02:00
parent d3f633f559
commit 378389863a
Signed by: Serraniel
GPG key ID: 3690B4E7364525D3

View file

@ -10,7 +10,6 @@ export function init() {
}, "^/anime/[0-9]*$"); }, "^/anime/[0-9]*$");
} }
function updateLanguageDisplay(node) {
const langPrefix = 'ep.lang.'; const langPrefix = 'ep.lang.';
const dubSuffix = 'dub'; const dubSuffix = 'dub';
const subSuffix = 'sub'; const subSuffix = 'sub';
@ -19,13 +18,19 @@ function updateLanguageDisplay(node) {
const subIcon = 'closed_caption'; const subIcon = 'closed_caption';
const zeroWidthSpace = ''; // ​ const zeroWidthSpace = ''; // ​
let listItems = document.querySelectorAll('md-list-item'); function updateLanguageDisplay(node) {
const listNodeName = 'MD-LIST-ITEM';
listItems.forEach(item => { if (node.nodeName === listNodeName) {
updateLanguageDisplayListMode(node);
}
}
function updateLanguageDisplayListMode(node) {
// last column with flags // last column with flags
let col = item.querySelector('h3.layout-align-end-center'); let col = node.querySelector('h3.layout-align-end-center');
if (col.eaManipulated) { if (typeof col === 'undefined' || col.eaManipulated) {
return; return;
} }
@ -181,15 +186,14 @@ function updateLanguageDisplay(node) {
col.appendChild(div); col.appendChild(div);
}); });
item.querySelectorAll('.layout-column:not(:last-child)').forEach(div => { node.querySelectorAll('.layout-column:not(:last-child)').forEach(div => {
div.style.borderRight = '1px solid rgba(155,155,155, 0.2)'; div.style.borderRight = '1px solid rgba(155,155,155, 0.2)';
}) })
item.querySelectorAll('.layout-column').forEach(div => { node.querySelectorAll('.layout-column').forEach(div => {
div.style.paddingLeft = '2px'; div.style.paddingLeft = '2px';
div.style.paddingRight = '2px'; div.style.paddingRight = '2px';
}) })
col.eaManipulated = true; col.eaManipulated = true;
});
} }