Add: valid url
This commit is contained in:
parent
3730a4e483
commit
41f0174362
|
@ -263,12 +263,26 @@ var usercss = (function () {
|
|||
// validate version
|
||||
semverCompare(style.version, '0.0.0');
|
||||
|
||||
// validate URLs
|
||||
validUrl(style.url);
|
||||
validUrl(style.supportURL);
|
||||
|
||||
// validate vars
|
||||
for (const key of Object.keys(style.vars)) {
|
||||
validVar(style.vars[key]);
|
||||
}
|
||||
}
|
||||
|
||||
function validUrl(url) {
|
||||
if (!url) {
|
||||
return;
|
||||
}
|
||||
url = new URL(url);
|
||||
if (url.protocol !== 'http:' && url.protocol !== 'https:') {
|
||||
throw new Error(`${url.protocol} is not a valid protocol`);
|
||||
}
|
||||
}
|
||||
|
||||
function validVar(va, value = 'default') {
|
||||
if (va.type === 'select' && !va.select[va[value]]) {
|
||||
throw new Error(chrome.i18n.getMessage('styleMetaErrorSelectMissingKey', va[value]));
|
||||
|
|
Loading…
Reference in New Issue
Block a user