diff --git a/index.html b/index.html index 7f698b258..fb92252c5 100644 --- a/index.html +++ b/index.html @@ -11,13 +11,7 @@ - - - - - - - + diff --git a/src/services/style_setter/style_setter.js b/src/services/style_setter/style_setter.js index 3d85db3aa..5b696185a 100644 --- a/src/services/style_setter/style_setter.js +++ b/src/services/style_setter/style_setter.js @@ -8,34 +8,45 @@ import localforage from 'localforage' // Otherwise it will return an array const supportsAdoptedStyleSheets = !!document.adoptedStyleSheets +const stylesheets = {} + const createStyleSheet = (id) => { - if (supportsAdoptedStyleSheets) { - return { - el: null, - sheet: new CSSStyleSheet(), - rules: [] + const newStyleSheet = { + rules: [], + ready: false, + addRule (rule) { + this.rules.push( + rule + .replace(/backdrop-filter:[^;]+;/g, '') // Remove backdrop-filter + .replace(/var\(--shadowFilter\)[^;]*;/g, '') // Remove shadowFilter references + ) } } - const el = document.getElementById(id) - // Clear all rules in it - for (let i = el.sheet.cssRules.length - 1; i >= 0; --i) { - el.sheet.deleteRule(i) - } - - return { - el, - sheet: el.sheet, - rules: [] - } + stylesheets[id] = newStyleSheet + return newStyleSheet } -const EAGER_STYLE_ID = 'pleroma-eager-styles' -const LAZY_STYLE_ID = 'pleroma-lazy-styles' -const adoptStyleSheets = (styles) => { +export const adoptStyleSheets = () => { if (supportsAdoptedStyleSheets) { - document.adoptedStyleSheets = styles.map(s => s.sheet) + document.adoptedStyleSheets = Object + .values(stylesheets) + .filter(x => x.ready) + .map(x => { + const css = new CSSStyleSheet() + x.rules.forEach(r => css.insertRule(r, css.cssRules.length)) + return css + }) + } else { + const holder = document.getElementById('custom-styles-holder') + + Object + .values(stylesheets) + .forEach(sheet => { + sheet.rules.forEach(r => holder.sheet.insertRule(r)) + }) + } // Some older browsers do not support document.adoptedStyleSheets. // In this case, we use the