Advertisement
Awn_pastebin

別タブ常駐型ほぼ完全自動アク禁ブックマークレット

Oct 12th, 2016
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //////////////////////////////////////////////////////////////////////////
  2. //
  3. //@title 別タブ常駐型ほぼ完全自動アク禁ブックマークレット
  4. //@include http://*.open2ch.net
  5. //@private
  6. //
  7. //作った人: Awn
  8. //
  9. //改定履歴
  10. //-20161011: とりあえず作ってみた。
  11. //-20161012: 細かい修正。
  12. //-20161012: スレ主の投稿は自動アク禁の対象から除外。
  13. //-20161012: localStorageにまだNG文字列が格納されていない場合、読込ボタンを押下してもlocalStorageからの読込は実行しない。
  14. //-20161012: ボタンの名前を変更(保存ボタン->適用ボタン)し、コメントもちょいちょい変更。
  15. //-20161012: 初回起動時、localStorageにNG文字列が格納されている場合、変数とテキストエリアににそれらを退避する。
  16. //-20161012: 見分けをつけるため、ブックマークレット実行タブのbodyのbgcolorを変える。
  17. //-20161012: 適用ボタンを押した時の見た目を変更(★の色が変わる)。
  18. //
  19. //諸注意
  20. //-ご利用は自己責任でお願いします。
  21. //-ブックマークレットは予告なく修正または廃止されることがあります。
  22. //-悪用は厳禁です。
  23. //-改造改良改悪はご自由にどうぞ。
  24. //
  25. //////////////////////////////////////////////////////////////////////////
  26.  
  27.  
  28. //初回起動時の設定
  29. if(document.getElementById("NGNAMES_sv") === null){
  30.     //変数
  31.     var ngwords = [];//NGワード格納用の配列
  32.     var ngnames = [];//NGネーム格納用の配列
  33.     var lastnum = 1001;//最終書き込みのレス番号(仮の初期値:1001)
  34.     var surenusi = "red";//スレ主判定
  35.  
  36.     //UI
  37.     $("body").append("<hr><b id='NGWORDS_tglicon' style='color:black'>★</b><b style='color:red'>↓NGワード↓</b> <button type='button' id='NGWORDS_sv'>適用</button> <button type='button' id='NGWORDS_rd'>読込</button><br><textarea rows=5 cols=56 id='NGWORDS_AREA'></textarea>");
  38.     $("body").append("<hr><b id='NGNAMES_tglicon' style='color:black'>★</b><b style='color:red'>↓NGネーム↓</b> <button type='button' id='NGNAMES_sv'>適用</button> <button type='button' id='NGNAMES_rd'>読込</button><br><textarea rows=5 cols=56 id='NGNAMES_AREA'></textarea>");
  39.  
  40.     //背景色変更
  41.     $("body").attr("bgcolor","#e6e6fa");//#e6e6faはlavenderの色
  42.  
  43.     //localStorageのNG文字列を変数とテキストエリアに退避する
  44.     ngwords = JSON.parse(getStorage("NGWORDS"));
  45.     if(ngwords !== null){$("#NGWORDS_AREA").val(ngwords.join("\n"));}
  46.  
  47.     ngnames = JSON.parse(getStorage("NGNAMES"));
  48.     if(ngnames !== null){$("#NGNAMES_AREA").val(ngnames.join("\n"));}
  49.  
  50.  
  51. }
  52.  
  53.  
  54. //[読込]を押した時の挙動
  55. $("#NGWORDS_rd").click(function(){
  56.     ngwords = JSON.parse(getStorage("NGWORDS"));
  57.     if(ngwords !== null){$("#NGWORDS_AREA").val(ngwords.join("\n"));}
  58. });
  59.  
  60. $("#NGNAMES_rd").click(function(){
  61.     ngnames = JSON.parse(getStorage("NGNAMES"));
  62.     if(ngnames !== null){$("#NGNAMES_AREA").val(ngnames.join("\n"));}
  63. });
  64.  
  65.  
  66. //[適用]を押した時の挙動
  67. $("#NGWORDS_sv")
  68.     .click(function(){
  69.         ngwords = $("#NGWORDS_AREA").val().split("\n");
  70.         ngwords = ngwords.filter(function(e){return e !=="";});
  71.         setStorage("NGWORDS",JSON.stringify(ngwords));})
  72.     .toggle(
  73.         function(){$("#NGWORDS_tglicon").css("color","white");},
  74.         function(){$("#NGWORDS_tglicon").css("color","black");})
  75. ;
  76.  
  77. $("#NGNAMES_sv")
  78.     .click(function(){
  79.         ngnames = $("#NGNAMES_AREA").val().split("\n");
  80.         ngnames = ngnames.filter(function(e){return e !=="";});
  81.         setStorage("NGNAMES",JSON.stringify(ngnames));})
  82.     .toggle(
  83.         function(){$("#NGNAMES_tglicon").css("color","white");},
  84.         function(){$("#NGNAMES_tglicon").css("color","black");})
  85. ;
  86.  
  87.  
  88. /////////////////////////////////////
  89. //
  90. // 自動アク禁処理
  91. //
  92. /////////////////////////////////////
  93. //新着レスが自動表示される度に実行
  94. $(document).ajaxComplete(function(){
  95.     detectNGs();
  96. });
  97.  
  98.  
  99. //NG検出関数
  100. function detectNGs(){
  101.     //最終書き込みのレス番号の取得
  102.     lastnum = $("dl.hide:last > dd > ares").attr("num");
  103.     //スレ主チェック
  104.     surenusi = $("dl.hide:last > dt > font > font").attr("color");
  105.  
  106.     //スレ主でない書き込みの場合、自動アク禁判定を実行する
  107.     if( surenusi !== "red"){
  108.         //NGワードを見つけたら、該当レス番号をアク禁する
  109.         if(ngwords !== null ){
  110.             $.each(ngwords,function(i,elm){
  111.                 if($("dl.hide:last > dd").is(":contains("+elm+')')){$("#MESSAGE").val("!aku"+lastnum);$("#submit_button").click();};
  112.             });
  113.         }
  114.  
  115.         //NGネームを見つけたら、該当レス番号をアク禁する
  116.         if(ngnames !== null){
  117.             $.each(ngnames,function(i,elm){
  118.                 if($("dl.hide:last > dt").is(":contains("+elm+')')){$("#MESSAGE").val("!aku"+lastnum);$("#submit_button").click();};
  119.             });
  120.         }
  121.     }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement