fork download
  1.  
  2. function createDatUrls(url)
  3. {
  4. var pattern = "htt"+"p:/+([^/]+)/.*read[^/]+/([^/]+)/(\\d+).*$";
  5. return [
  6. { name: "mimizun", url: url.replaceAll(pattern, "htt"+"p://mimizun.com/log/2ch/$2/$3.dat") },
  7. { name: "unkar", url: url.replaceAll(pattern, "htt"+"p://unkar.org/convert.php/$2/$3") }
  8. ];
  9. }
  10.  
  11. function getDat(thread)
  12. {
  13. if(!thread.bbs.is2ch)
  14. return null;
  15.  
  16. var services = createDatUrls(thread.url.toString());
  17.  
  18. var retrievedResCount = thread.localResCount;
  19. var dat = null;
  20. for(var i = 0; retrievedResCount < 1001 && i < services.length; i++)
  21. {
  22. v2c.setStatus("過去ログを取得中........( ´∀`)つ旦 " + services[i].name);
  23.  
  24. var content = getThreadLog(services[i].url);
  25. if(!content)
  26. continue;
  27.  
  28. var resCount = content.split("\n").length;
  29.  
  30. printlnLog("{0} ({1}): {2}", services[i].name, resCount, services[i].url);
  31.  
  32. // 既得レス数と一致した場合は、1000に達しなかったスレと解釈して終了
  33. if(resCount != 1 && retrievedResCount == resCount)
  34. break;
  35.  
  36. if(retrievedResCount < resCount)
  37. {
  38. dat = { service: services[i], content: content };
  39. retrievedResCount = resCount;
  40. }
  41. }
  42.  
  43. var found = dat ? "retrieved from " + dat.service.name : "not found";
  44. printlnLog("{0}: {1} (+{2})", found, thread.title, retrievedResCount - thread.localResCount);
  45.  
  46. return dat ? dat.content : null;
  47. }
  48.  
  49. function getThreadLog(url)
  50. {
  51. var req = v2c.createHttpRequest(url);
  52.  
  53. var content = req.getContentsAsString();
  54. if(!content || req.responseCode != 200)
  55. return null;
  56.  
  57. return content;
  58. }
  59.  
  60. function printlnLog(format /*, ...*/)
  61. {
  62. var args = arguments;
  63. var message = format.replace(/\{(\d)\}/g, function(m, c) { return args[parseInt(c) + 1] });
  64.  
  65. v2c.println("[getdat.js] " + message);
  66. }
  67.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty