2chScript

ブラウザから見る2ch.netを強化(新鯖のみ対応)

  1. // ==UserScript==
  2. // @name 2chScript
  3. // @namespace https://greasyfork.org/ja/users/94414
  4. // @version 0.1.1
  5. // @description ブラウザから見る2ch.netを強化(新鯖のみ対応)
  6. // @author Petitsurume
  7. // @match http://*.2ch.net/test/read.cgi/*
  8. // @require https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js
  9. // @grant GM_getValue
  10. // @grant GM_setValue
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. // Your code here...
  17. $(function(){
  18. var ng_ids = JSON.parse(GM_getValue("2ch_ng_ids","[]"))
  19. var filter_flag=false
  20. console.log("NG:",ng_ids)
  21. function setNGCSS(){
  22. ng_ids.forEach(function(id){
  23. var $post = $('.post[data-userid="'+id+'"]')
  24. $post.find(".name").html("<b>あぼーん</b>")
  25. $post.find(".message").text("あぼーん")
  26. $post.find(".date").text("あぼーん(UserScript "+id+")")
  27. var $$hide_link=$("<a>")
  28. $$hide_link.attr("href","#"+Math.random())
  29. $$hide_link.css("margin-left","0.5em")
  30. $$hide_link.click(function(){
  31. $('.post[data-userid="'+id+'"]').hide()
  32. })
  33. $$hide_link.text("[透明化]")
  34. $post.find(".date").append($$hide_link)
  35. })
  36. }
  37. function addNG(id){
  38. ng_ids.push(id)
  39. GM_setValue("2ch_ng_ids",JSON.stringify(ng_ids))
  40. setNGCSS()
  41. }
  42. $(".post").each(function(){
  43. var $post = $(this)
  44. var $date = $post.find(".date")
  45. var $message = $post.find(".message")
  46. var userid = $post.data("userid")
  47. var isAnon = (userid == "ID:???" || userid =="")
  48. // 発言カウンター
  49. if(!isAnon) {
  50. var $$counter = $("<span>")
  51. if($('.post[data-userid="'+userid+'"]').length > 5) $$counter.css("color","#a00"); else $$counter.css("color","#888")
  52. var count = "??"
  53. var _count=0
  54. $('.post[data-userid="'+userid+'"]').each(function(){
  55. _count++
  56. if($(this).data("id") == $post.data("id")) count=_count
  57. })
  58. $$counter.text(" ("+count+"/"+($('.post[data-userid="'+userid+'"]').length)+"回発言)")
  59. $date.append($$counter)
  60. }
  61. // NGリンク
  62. if(userid !== "") {
  63. var $$ng_link = $("<a>")
  64. $$ng_link.attr("href","#."+Math.random())
  65. $$ng_link.text("[IDをNG]")
  66. $$ng_link.css("margin-left","0.5em")
  67. $$ng_link.click(function(e){
  68. e.preventDefault()
  69. if(!confirm(userid+"をNGします")) return
  70. addNG($post.data("userid"))
  71. })
  72. $date.append($$ng_link)
  73. }
  74. // 抽出リンク
  75. if(userid !== "") {
  76. var $$filter_link = $("<a>")
  77. $$filter_link.attr("href","#."+Math.random())
  78. $$filter_link.text("[IDで抽出]")
  79. $$filter_link.css("margin-left","0.5em")
  80. $$filter_link.addClass("filter_link")
  81. $$filter_link.click(function(e){
  82. e.preventDefault()
  83. if(filter_flag){
  84. filter_flag=false
  85. $(".filter_link").text("[IDで抽出]")
  86. $(".post").removeClass("filter_gisei")
  87. return
  88. }
  89. $(".post").each(function(){
  90. var $post=$(this)
  91. if($post.data("userid") != userid) $post.addClass("filter_gisei")
  92. })
  93. $(".filter_link").text("[抽出をやめる]")
  94. filter_flag = true
  95. })
  96. $date.append($$filter_link)
  97. }
  98. // リンク解析
  99. var $preview = $("<div>")
  100. $message.append($preview)
  101. $message.find("a").each(function(){
  102. var $link = $(this)
  103. var url = $link.text()
  104. var hostname = $("<a>").attr("href",$link.text()).get(0).hostname
  105. if($link.text().substring(0,2) == ">>") { // アンカー
  106. $link.attr("href",location.href.replace(location.hash,"")+"#"+$link.text().substring(2))
  107. $link.attr("target","")
  108. }
  109. if(hostname == "i.imgur.com") { // imgur プレビュー
  110. var $$img_a = $("<a>")
  111. var $$img = $("<img>")
  112. $$img.attr("src",url)
  113. $$img_a.attr("href",url)
  114. $$img.css("width","3em")
  115. $$img.css("height","3em")
  116. $$img_a.attr("target","_blank")
  117. $$img_a.append($$img)
  118. $preview.append($$img_a)
  119. }
  120. })
  121. })
  122. $("body").append($("<style>.filter_gisei{display:none;}</style>"))
  123. setNGCSS()
  124. })
  125. })();