<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta charset="utf-8" />
<title>NPM 包版本检测更新</title>
<link rel="stylesheet" href="https://netnr.eu.org/bootstrap@5.3.3/dist/css/bootstrap.min.css" />
</head>
<body>
<div class="container-fluid p-lg-3 pb-lg-0 py-4 pb-0">
<div class="row">
<div class="col-md-12">
<textarea class="form-control nr-txt1" placeholder="NPM 包版本检测更新"></textarea>
</div>
</div>
</div>
<iframe src="https://ss.netnr.com/diff#hide-menu" scrolling="no" frameborder="0"
style="width:100%;visibility:hidden;"></iframe>
</body>
</html>
var cv = {
de: document.querySelector('iframe'),
title: document.title,
init: function () {
document.querySelector('.nr-txt1').oninput = function () {
cv.parse(this.value)
}
window.onload = window.onresize = function () {
cv.resize()
};
},
resize: function () {
var ch = document.documentElement.clientHeight - cv.de.getBoundingClientRect().top - 10;
cv.de.style.height = Math.max(100, ch) + "px";
},
parse: function (txt) {
cv.otext = txt;
cv.odata = [];
txt.replace(/\/(\S+)@(\d+.\d+.\d+)\/(\S+)['|"]/gm, function (uri, pn, pv, pp) {
var obj = {
uri: uri.substring(0, uri.length - 1),
package: pn.split('/').pop(),
v0: pv,
v1: null,
error: null
};
if (obj.uri.includes('"')) {
obj.uri = obj.uri.split('"')[0];
}
if (obj.uri.includes("'")) {
obj.uri = obj.uri.split("'")[0];
}
if (cv.hosts == null) {
cv.hosts = obj.uri.split('/' + obj.package)[0]
}
var vp = obj.uri.replace(cv.hosts, '').substring(1).split(obj.v0)[0];
vp = vp.substring(0, vp.length - 1);
if (obj.package != vp) {
console.log(`已修正匹配模式包名异常:${obj.package} => ${vp}`)
obj.package = vp;
}
cv.odata.push(obj);
});
console.table(cv.odata);
cv.check();
},
check: function (i) {
i = i || 0;
if (i < cv.odata.length) {
let obj = cv.odata[i];
let uri = `https://data.jsdelivr.com/v1/package/npm/${obj.package}`;
uri = `https://cors.zme.ink/${encodeURIComponent(uri)}`;
fetch(uri).then(x => x.json()).then(res => {
let latest = res["tags"].latest;
console.log(`${i + 1}/${cv.odata.length} ${obj.package} latest: ${latest}`);
obj.v1 = latest;
cv.odata[i] = obj;
cv.check(i + 1);
}).catch(err => {
obj.error = err;
cv.odata[i] = obj;
cv.check(i + 1);
})
} else {
var txt2 = cv.otext;
cv.odata.forEach(obj => {
if (obj.v1 != null) {
txt2 = txt2.replace(obj.uri, obj.uri.replace(obj.package + '@' + obj.v0, obj.package + '@' + obj.v1));
}
})
document.title = cv.title;
cv.setDiff(cv.otext, txt2);
}
},
setDiff: function (origin, vary) {
var iframe = cv.de;
iframe.style.visibility = "visible";
iframe.contentWindow.postMessage(JSON.stringify({ origin, vary }), iframe.src);
}
}
cv.init();