parseMeta
function parseMetadata(code) {
if(code===undefined){
code=GM_info.scriptMetaStr
}
let issub = false;
let regex = /\/\/\s*==UserScript==([\s\S]+?)\/\/\s*==\/UserScript==/m;
let header = regex.exec(code);
if (!header) {
regex = /\/\/\s*==UserSubscribe==([\s\S]+?)\/\/\s*==\/UserSubscribe==/m;
header = regex.exec(code);
if (!header) {
return null;
}
issub = true;
}
regex = /\/\/\s*@([\S]+)((.+?)$|$)/gm;
const ret = {};
let meta = regex.exec(header[1]);
while (meta !== null) {
const [key, val] = [meta[1].toLowerCase().trim(), meta[2].trim()];
let values = ret[key];
if (values == null) {
values = [];
}
values.push(val);
ret[key] = values;
meta = regex.exec(header[1]);
}
if (ret.name === undefined) {
return null;
}
if (Object.keys(ret).length < 3) {
return null;
}
if (!ret.namespace) {
ret.namespace = [""];
}
if (issub) {
ret.usersubscribe = [];
}
return ret;
}