futaba_new_res_counter

ふたクロでタブに新着レス数を表示する

  1. // ==UserScript==
  2. // @name futaba_new_res_counter
  3. // @namespace https://github.com/akoya-tomo
  4. // @description ふたクロでタブに新着レス数を表示する
  5. // @include http://*.2chan.net/*/res/*
  6. // @include https://*.2chan.net/*/res/*
  7. // @version 1.1.0
  8. // @require http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. this.$ = this.jQuery = jQuery.noConflict(true);
  14.  
  15. (function ($) {
  16. /*
  17. * 設定
  18. */
  19. // ==================================================
  20. var USE_BOARD_NAME = false; //タブに板名を表示する
  21. // ==================================================
  22.  
  23. var script_name = "futaba_new_res_counter";
  24. var res = 0; //新着レス数
  25. var server_name = document.domain.match(/^[^.]+/);
  26. var board_name = $("#tit").text().match(/^[^@]+/);
  27. var has_boader_area = false;
  28.  
  29. init();
  30.  
  31. function init(){
  32. if (!isFileNotFound()) {
  33. setTitle();
  34. checkFutakuroReload();
  35. checkThreadDown();
  36. }
  37. resetTitle();
  38. }
  39.  
  40. /*
  41. * 404チェック
  42. */
  43. function isFileNotFound() {
  44. if (document.title == "404 File Not Found") {
  45. return true;
  46. }
  47. else {
  48. return false;
  49. }
  50. }
  51.  
  52. /*
  53. * ふたクロの新着の状態を取得
  54. */
  55. function checkFutakuroReload() {
  56. var target = $(".thre").get(0);
  57. var config = { childList: true };
  58. var observer = new MutationObserver(function(mutations) {
  59. var has_new_res = false;
  60. mutations.forEach(function(mutation) {
  61. var $nodes = $(mutation.addedNodes);
  62. //console.log(script_name + ":added nodes =");
  63. //console.dir($nodes);
  64. if ($nodes.length) {
  65. has_new_res = true;
  66. }
  67. });
  68. if (has_new_res) {
  69. changeTitle();
  70. }
  71. if (!has_boader_area) {
  72. checkThreadDown();
  73. }
  74. });
  75. observer.observe(target, config);
  76. }
  77.  
  78. /*
  79. * タブに新着レス数・スレ消滅状態を表示
  80. */
  81. function changeTitle() {
  82. var newres = $(".nb_left:last").text().match(/(\d+)件の新着レス/); // ふたクロの新着レス数取得
  83. if (newres) {
  84. res += parseInt(newres[1]);
  85. }
  86. if (res !== 0) {
  87. document.title = "(" + res + ")" + titleName();
  88. }
  89. }
  90.  
  91. /*
  92. * ふたクロのステータスからスレ消滅状態をチェック
  93. */
  94. function checkThreadDown() {
  95. var target = $("#border_area").get(0);
  96. if (target) {
  97. setThreadDownObserver(target);
  98. has_boader_area = true;
  99. }
  100.  
  101. function setThreadDownObserver(target) {
  102. var config = { childList: true };
  103. var observer = new MutationObserver(function() {
  104. if ($("#thread_down").length) {
  105. document.title = "#" + titleName();
  106. }
  107. });
  108. observer.observe(target, config);
  109. }
  110. }
  111.  
  112. function titleName() {
  113. var title = document.title;
  114. var title_num = title.match(/^(#|\(\d+\))/);
  115. var title_num_length;
  116. if (!title_num) {
  117. title_num_length = 0;
  118. }
  119. else {
  120. title_num_length = title_num[0].length;
  121. }
  122. var act_title_name = title.substr(title_num_length);
  123. return act_title_name;
  124. }
  125.  
  126. /*
  127. * 新着レスをリセット
  128. */
  129. function resetTitle() {
  130. // ページ末尾でホイールダウンした時
  131. window.onwheel = function(event){
  132. // Windowsで拡大率使用時にwindow_yが小数点以下でずれる対応
  133. var window_y = Math.ceil($(window).height() + $(window).scrollTop());
  134. var window_ymax = $(document).height();
  135. //console.log(script_name + ": window_y,yamx,deltaY: " + window_y +',' + window_ymax + ',' + event.deltaY);
  136. if (event.deltaY > 0 && window_y >= window_ymax ) {
  137. resetTitlename();
  138. }
  139. return;
  140. };
  141.  
  142. function resetTitlename() {
  143. res = 0;
  144. var title_char = titleName();
  145. document.title = title_char;
  146. }
  147. }
  148.  
  149. /*
  150. * タイトル設定
  151. */
  152. // タイトルに板名を追加する
  153. function setTitle() {
  154. if (USE_BOARD_NAME) {
  155. if (board_name == "二次元裏") {
  156. board_name = server_name;
  157. }
  158. document.title = board_name + " " + document.title;
  159. }
  160. }
  161.  
  162. })(jQuery);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址