fork download
  1. //【登録場所】レス表示、全体
  2. //【ラベル】ランダムで開く
  3. //【更新日】2013/01/25 (version 1.11 stable)
  4. //【コマンド】${SCRIPT:S} random.js
  5. //【コマンド】${SCRIPT:S} random.js $BOARDBASE
  6. //【コマンド】${SCRIPT:S} random.js $BOARDBASE $BOARDVIEW
  7. // コマンドの書式
  8. // ${SCRIPT:S} random.js 引数1 引数2 (半角スペースを開けて以下の引数を書く)
  9. // ■引数 $BOARDBASE … 以下のbdlistの板の中からランダムで開くようにする
  10. // ■引数 $BOARDVIEW … ランダムに選択したスレを開く前にそのスレの板(スレ一覧)を開きます
  11. //【内容】 レスビューで開いているスレの板(スレ一覧)からランダムにスレ開く
  12. //【スクリプト】
  13. // [設定]____________________________________
  14. var bdlist = [
  15. "news4vip", // ← 2chの板の場合URLを省略できる
  16. "http://a...content-available-to-author-only...h.net/software/", // ← 省略しないでも書ける
  17. "hgame", // ← PINKちゃんねるも同様
  18. "http://j...content-available-to-author-only...r.jp/computer/43680/", // ← 2ch、bbspink以外の板の場合は板URLを指定する
  19. // 「 "板URL", 」の形式でこの行以降に追加
  20. ];
  21. // ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
  22.  
  23. var mes = "";
  24. var BOARDBASE = false;
  25. var BOARDVIEW = false;
  26. if (v2c.context.args.length > 0) {
  27. var argLine = v2c.context.argLine;
  28. if (/\$BOARDBASE/i.test(argLine) && bdlist.length > 0) {
  29. BOARDBASE = true;
  30. }
  31. if (/\$BOARDVIEW/i.test(argLine)) {
  32. BOARDVIEW = true;
  33. }
  34. }
  35. var global = [];
  36. if (BOARDBASE && ((bdlist != v2c.getProperty('bdlist')) || (!(global = v2c.getProperty('randomBoards'))))) {
  37.  
  38. global = [];
  39. for (var i = 0; i < bdlist.length; i++) {
  40. var bd = v2c.bbs2ch.getBoard(bdlist[i]) || v2c.getBoard(bdlist[i]) || null;
  41. if (bd) { global.push(bd.url); }
  42. }
  43. if (global.length > 0) {
  44. v2c.putProperty('randomBoards', global);
  45. v2c.putProperty('bdlist', bdlist);
  46. }
  47. }
  48. function getRandom()
  49. {
  50. if (!v2c.online) { return; }
  51. if (!BOARDBASE) {
  52. var th = v2c.resPane.selectedThread;
  53. if (!th) { mes = "[random.js] スレッドが開かれてないので板が取得できません。"; return; }
  54. global.push(th.board.url);
  55. }
  56. while(global.length > 0) {
  57. var idx = Math.floor(Math.random() * global.length);
  58. if (detectThread(v2c.getBoard(global[idx]))) { return; }
  59. global.splice(idx, 1);
  60. }
  61. mes = "[random.js] ランダムで開くための未取得スレッドがありませんでした。";
  62. }
  63. function detectThread(bd)
  64. {
  65. if (!bd) { return false; }
  66. if (BOARDVIEW) { v2c.openURL(bd.url); }
  67. if (v2c.interrupted) { return false; }
  68.  
  69. var bs = bd.url + 'subject.txt';
  70. var ss = v2c.readURL(bs);
  71. if (v2c.interrupted) { return false; }
  72. if (!ss) { mes = bs+'の取得に失敗'; return false; }
  73.  
  74. var lines = ss.split('\n');
  75. var count = lines.length;
  76. while (count) {
  77. v2c.println(count);
  78. var idx = Math.floor(Math.random() * count);
  79. var key = '';
  80. var bbs = bd.bbs;
  81. if (bbs.is2ch || bbs.is2cheq) {
  82. key = /^(\d+)\.dat<>.+ \(\d+\)/.exec(lines[idx])[1];
  83. } else if (bbs.shitaraba || bbs.machi) {
  84. key = /^(\d+)\.cgi,.+\(\d+\)/.exec(lines[idx])[1];
  85. } else {
  86. return false; // twitter は除外
  87. }
  88. var th = bd.getThread(key);
  89. if (th && th.localResCount == 0) {
  90. th.open();
  91. return true;
  92. }
  93. lines.splice(idx, 1);
  94. count--;
  95. }
  96. return false;
  97. }
  98.  
  99. getRandom();
  100. if (mes != "") { v2c.context.setStatusBarText(mes); }
  101.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty