Skip to content

Commit 5b5a652

Browse files
committed
fix: improve style appending
1 parent ed9f407 commit 5b5a652

File tree

7 files changed

+14
-17
lines changed

7 files changed

+14
-17
lines changed

src/base/chat/context.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import each from 'src/utils/each.js';
77
import * as fnUser from 'src/utils/user.js';
88
import ignoreUser from 'src/utils/ignoreUser.js';
99
import decode from 'src/utils/decode.js';
10-
import css from 'src/utils/css.js';
1110
import { buttonCSS, window } from 'src/utils/1.variables.js';
1211
import Translation from 'src/structures/constants/translation';
1312

@@ -17,7 +16,7 @@ const setting = settings.register({
1716
page: 'Chat',
1817
});
1918

20-
style.add(css`
19+
style.add(`
2120
.chatContext {
2221
background-color: #F4F4F4;
2322
margin: 10px;

src/base/styles/toast.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import css from 'src/utils/css.js';
21
import style from 'src/utils/style.js';
32

4-
style.add(css`
3+
style.add(`
54
#AlertToast {
65
height: 0;
76
}

src/base/underscript/changelog.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import axios from 'axios';
33
import { scriptVersion } from 'src/utils/1.variables.js';
44
import style from 'src/utils/style.js';
55
import * as menu from 'src/utils/menu.js';
6-
import css from 'src/utils/css.js';
76
import Translation from 'src/structures/constants/translation';
87

98
const changelog = {};
@@ -17,7 +16,7 @@ const keys = {
1716
};
1817

1918
// Change log :O
20-
style.add(css`
19+
style.add(`
2120
.us-changelog h2 {
2221
font-size: 24px;
2322
}

src/base/underscript/patchnotes.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import wrap from 'src/utils/2.pokemon.js';
33
import { noop, scriptVersion } from 'src/utils/1.variables.js';
44
import style from 'src/utils/style.js';
55
import { toast } from 'src/utils/2.toasts.js';
6-
import css from 'src/utils/css.js';
76
import Translation from 'src/structures/constants/translation';
87
import eventManager from 'src/utils/eventManager';
98
import * as changelog from './changelog.js';
@@ -33,7 +32,7 @@ wrap(function patchNotes() {
3332
installed.value() === scriptVersion
3433
) return;
3534

36-
style.add(css`
35+
style.add(`
3736
#AlertToast div.uschangelog span:nth-of-type(2) {
3837
max-height: 300px;
3938
overflow-y: auto;

src/base/underscript/updates.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import debugToast from 'src/utils/debugToast';
44
import { toast as Toast } from 'src/utils/2.toasts.js';
55
import semver from 'src/utils/version.js';
66
import { buttonCSS, scriptVersion, window } from 'src/utils/1.variables.js';
7-
import css from 'src/utils/css.js';
87
import createParser from 'src/utils/parser';
98
import eventManager from 'src/utils/eventManager';
109
import {
@@ -18,7 +17,7 @@ import Translation from 'src/structures/constants/translation';
1817

1918
// Check for script updates
2019
wrap(() => {
21-
style.add(css`
20+
style.add(`
2221
#AlertToast h2,
2322
#AlertToast h3 {
2423
margin: 0;

src/utils/settings/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import DialogHelper from '../DialogHelper.js';
1717

1818
const defaultSetting = new RegisteredSetting();
1919

20-
style.add(styles.split('\n\n'));
20+
style.add(styles);
2121

2222
/**
2323
* @type {{[key: string]: RegisteredSetting}}

src/utils/style.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import eventManager from './eventManager.js';
2+
import last from './last.js';
23

34
// Custom CSS classes are great.
45
export function newStyle(plugin = false) {
@@ -15,17 +16,18 @@ export function newStyle(plugin = false) {
1516
});
1617

1718
function add(...styles) {
18-
const hasChildren = styles.length || el.children.length;
19-
if (loaded && hasChildren) appendStyle();
20-
else if (!loaded) eventManager.once(':preload', () => appendStyle());
19+
const hasChildren = styles.length + el.children.length;
20+
if (hasChildren) {
21+
if (loaded) appendStyle();
22+
else eventManager.once(':preload', () => appendStyle());
23+
}
2124
return wrapper(append(styles));
2225
}
2326

2427
function append(styles = [], nodes = []) {
2528
styles.flat().forEach((s) => {
26-
const node = document.createTextNode(s);
27-
nodes.push(node);
28-
el.appendChild(node);
29+
el.append(s);
30+
nodes.push(last(el.childNodes));
2931
});
3032
return nodes;
3133
}

0 commit comments

Comments
 (0)