Fix check for previously added style sheet

Although it is possible to use the "title" attribute of a style sheet as
an ID that is totally wrong and a complete misuse of the attribute.
Moreover, that only works when only a single style sheet has a title
set.

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
This commit is contained in:
Daniel Calviño Sánchez 2020-01-10 04:25:21 +01:00
Родитель e48c75913d
Коммит c6a3816902
1 изменённых файлов: 17 добавлений и 3 удалений

Просмотреть файл

@ -271,16 +271,30 @@ export default {
addCustomAtWhoStyleSheet() {
for (let i = 0; i < document.styleSheets.length; i++) {
const sheet = document.styleSheets[i]
if (sheet.title === 'at-who-custom') {
return
// None of the default properties of a style sheet can be used
// as an ID. Adding a "data-id" attribute would work in Firefox,
// but not in Chromium, as it does not provide a "dataset"
// property in styleSheet objects. Therefore it is necessary to
// check the rules themselves, but as the order is undefined a
// matching rule needs to be looked for in all of them.
if (sheet.cssRules.length !== 3) {
continue
}
for (const cssRule of sheet.cssRules) {
if (cssRule.cssText === '.atwho-view { max-width: unset; }') {
return
}
}
}
const style = document.createElement('style')
style.setAttribute('title', 'at-who-custom')
document.head.appendChild(style)
// "insertRule" calls below need to be kept in sync with the
// condition above.
// Override "max-width: 180px", as that makes the autocompletion
// panel too narrow.
style.sheet.insertRule('.atwho-view { max-width: unset; }', 0)