add fake header before linking to USW
This commit is contained in:
parent
cda606e7cc
commit
527d7c0fbc
|
@ -35,7 +35,7 @@ const uswApi = (() => {
|
||||||
const maxKeyLen = meta.reduce((res, [k]) => Math.max(res, k.length), 0);
|
const maxKeyLen = meta.reduce((res, [k]) => Math.max(res, k.length), 0);
|
||||||
return [
|
return [
|
||||||
'/* ==UserStyle==',
|
'/* ==UserStyle==',
|
||||||
...meta.map(([k, v]) => `${k}${' '.repeat(maxKeyLen - k.length + 2)}${v || ''}`),
|
...meta.map(([k, v]) => v && `${k}${' '.repeat(maxKeyLen - k.length + 2)}${v}`).filter(Boolean),
|
||||||
'==/UserStyle== */',
|
'==/UserStyle== */',
|
||||||
].join('\n') + '\n\n';
|
].join('\n') + '\n\n';
|
||||||
}
|
}
|
||||||
|
@ -77,14 +77,15 @@ const uswApi = (() => {
|
||||||
*/
|
*/
|
||||||
async publish(id, sourceCode) {
|
async publish(id, sourceCode) {
|
||||||
const style = await API.styles.get(id);
|
const style = await API.styles.get(id);
|
||||||
|
const code = style.usercssData ? sourceCode
|
||||||
|
: fakeUsercssHeader(style) + sourceCode;
|
||||||
const data = (style._usw || {}).token
|
const data = (style._usw || {}).token
|
||||||
? style._usw
|
? style._usw
|
||||||
: await linkStyle(style, sourceCode);
|
: await linkStyle(style, code);
|
||||||
const header = style.usercssData ? '' : fakeUsercssHeader(style);
|
|
||||||
return uswFetch(`style/${data.id}`, data.token, {
|
return uswFetch(`style/${data.id}`, data.token, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
body: JSON.stringify({code: header + sourceCode}),
|
body: JSON.stringify({code}),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user