function createDatUrls(url)
{
var pattern = "htt"+"p:/+([^/]+)/.*read[^/]+/([^/]+)/(\\d+).*$";
return [
{ name: "mimizun", url: url.replaceAll(pattern, "htt"+"p://mimizun.com/log/2ch/$2/$3.dat") },
{ name: "unkar", url: url.replaceAll(pattern, "htt"+"p://unkar.org/convert.php/$2/$3") }
];
}
function getDat(thread)
{
if(!thread.bbs.is2ch)
return null;
var services = createDatUrls(thread.url.toString());
var retrievedResCount = thread.localResCount;
var dat = null;
for(var i = 0; retrievedResCount < 1001 && i < services.length; i++)
{
v2c.setStatus("過去ログを取得中........( ´∀`)つ旦 " + services[i].name);
var content = getThreadLog(services[i].url);
if(!content)
continue;
var resCount = content.split("\n").length;
printlnLog("{0} ({1}): {2}", services[i].name, resCount, services[i].url);
// 既得レス数と一致した場合は、1000に達しなかったスレと解釈して終了
if(resCount != 1 && retrievedResCount == resCount)
break;
if(retrievedResCount < resCount)
{
dat = { service: services[i], content: content };
retrievedResCount = resCount;
}
}
var found = dat ? "retrieved from " + dat.service.name : "not found";
printlnLog("{0}: {1} (+{2})", found, thread.title, retrievedResCount - thread.localResCount);
return dat ? dat.content : null;
}
function getThreadLog(url)
{
var req = v2c.createHttpRequest(url);
var content = req.getContentsAsString();
if(!content || req.responseCode != 200)
return null;
return content;
}
function printlnLog(format /*, ...*/)
{
var args = arguments;
var message = format.replace(/\{(\d)\}/g, function(m, c) { return args[parseInt(c) + 1] });
v2c.println("[getdat.js] " + message);
}
CmZ1bmN0aW9uIGNyZWF0ZURhdFVybHModXJsKQp7CiAgICB2YXIgcGF0dGVybiA9ICJodHQiKyJwOi8rKFteL10rKS8uKnJlYWRbXi9dKy8oW14vXSspLyhcXGQrKS4qJCI7CglyZXR1cm4gWwoJCXsgbmFtZTogIm1pbWl6dW4iLCB1cmw6IHVybC5yZXBsYWNlQWxsKHBhdHRlcm4sICJodHQiKyJwOi8vbWltaXp1bi5jb20vbG9nLzJjaC8kMi8kMy5kYXQiKSB9LAoJCXsgbmFtZTogIn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