Firefoxでの起動不良について
Firefox版の「Tampermonkey」自体が、編集画面のページを開く 4~5回に1度程度の確率で、無効になる状態が続いています。 これはもしかすると私の環境だけの問題かも知れませんが、Chrome版では全く生じない事です。
そして、Firefox版にインストールしたツールの中でも、「S-R in Editor」は、他のツールより正常に起動しない傾向がありましたが、これについては、今回ほぼ改善出来た様に感じています。 更新は、起動に関わる関数「check_key()」中の条件分岐に「event.stopImmediatePropagation()」を加えています。 また、検索パネルの表示を「MutationObserver」に感知させない様にしました。 その更新のテスト結果として、ユーザーエージェントの分離対処は不要と判断し、これは削除しました。
以下に、これらの修正を加えた最新版をアップロードしておきます。
「S-R in Editor」 ver. 2.3
「S-R in Editor」は、「TEXTのヒット文字列の巡回」「HTML一括置換」「TEXT一括置換」「TEXT選択置換」「全ての置換チェック」「UNDO」が可能なツールです。
この検索・置換ツールはアメーバブロク最新版エディタ専用のツールです。 編集画面で使用できる置換ツールは、ブラウザ拡張機能を探しても他に無いかも知れません。 編集画面内に書き込まれた文字は「iframe」内をのぞいて、検索 / 置換処理をする事ができます。 下図では preコード枠内の文字列が置換対象になっています。
Chrome版 / Firefox版の「Tampermonkey」の新規作成編集枠に、以下のスクリプトコードをコピー&ペーストする事で、このツールが利用できます。
〔コピー方法〕 軽量シンプルなツール「PreBox Button 」を使うと
コード枠内を「Ctrl+左Click」➔「Copy code 」を「左Click」
の操作で、掲載コードのコピーが可能になります。
〔 S-R in Editor 〕 ver. 2.3
// ==UserScript==
// @name S-R in Editor
// @namespace http://tampermonkey.net/
// @version 2.3
// @description 通常編集枠で実行できる 検索 / 置換 ツール
// @author Ameba Blog User
// @match https://blog.ameba.jp/ucs/entry/srventry*
// @exclude https://blog.ameba.jp/ucs/entry/srventrylist.do*
// @grant none
// ==/UserScript==
window.addEventListener('load', function(){
let p_flag; // Process
let t_flag; // TEXT処理
let t_or_h=1; // TEXT・HTML選択スイッチ用フラグ
let arg_t_or_h; // TEXT・HTML選択が必要な場合
let count_t;
let count_h;
let buffer;
let buffer_arr=[];
let avoid=[];
let caution;
let hk; // ハイライト要素のインデックス
let native_hk; // フォーカス要素のインデックス履歴
let editor_iframe;
let iframe_doc;
let iframe_html;
let iframe_body;
let js_cover;
let search_box;
let search_word;
let search_word_es;
let replace_box;
let replace_word;
let result_box;
let s_1;
let s_2;
let s_3;
let s_4;
let s_5;
let s_6;
let cke_1_contents=document.getElementById('cke_1_contents'); // 監視 target
let monitor=new MutationObserver(catch_key);
monitor.observe(cke_1_contents, {childList: true}); // ショートカット待受け開始
catch_key();
function catch_key(){
search_box=document.querySelector('#search_box');
editor_iframe=document.querySelector('.cke_wysiwyg_frame');
if(editor_iframe){ //「通常表示」の場合
add_mu_style(); // muタグ用 styleをiframeに再設定
if(search_box){
search_box.disabled=false; }
document.addEventListener("keydown", check_key); // documentは先に指定
iframe_doc=editor_iframe.contentWindow.document;
if(iframe_doc){
iframe_doc.addEventListener("keydown", check_key); } // iframeは後に指定
function check_key(event){
if(event.ctrlKey==true){
if(event.keyCode==123){
if(p_flag!=3){ // 置換チェック時でなければ「Ctrl+F12」でON/OFF
event.stopImmediatePropagation();
search_replace();
if(!editor_iframe){
if_html(); }}}}
if(event.keyCode==27){
if(p_flag==3){ // 置換チェック時に「Esc」で置換チェックを解除=UNDO
event.preventDefault();
out_p_flag3(); }}
if(event.keyCode==9){
if(p_flag==0){ // 編集時に編集枠から「Tab」で検索に戻る
event.preventDefault();
search_box.focus(); }}
if(event.keyCode==9 || event.keyCode==16 || event.keyCode==17 ||
event.keyCode==18 || event.keyCode==19){
if(p_flag==3){ // 置換チェック時に「Tab/Shift/Ctrl/Alt/Pause」を無効化
event.preventDefault(); }}}}
else{ //「HTML表示」の場合
if_html(); }
function out_p_flag3(){ // 置換チェックを解除する
js_cover.style.display='none';
cke_1_contents.style.zIndex='0';
if(iframe_body){
iframe_body.contentEditable='true'; } // 編集可能にする
iframe_body.innerHTML=buffer; // 置換処理をUNDO ⏹
get_search();
search_box.disabled=false;
replace_box.disabled=false;
s_2.style.display='none';
s_3.style.display='none';
s_4.style.display='none';
s_5.style.display='none';
reset_mu_style();
if(t_flag>0){ //「buffer」を戻したので再度ハイライト表示
t_flag=1;
t_process(); // 🔳 RegExp
next(hk); } // UNDO時の巡回表示
replace_box.focus();
p_flag=2; } // 2=置換入力
function if_html(){ //「HTML表示」を開いた場合のクローズ処理
let s_container=document.querySelector('#s_container');
if(s_container){
search_box.disabled=true;
result_box.textContent=' ';
s_1.style.display='none';
replace_box.style.display='none';
replace_box.value='';
s_2.style.display='none';
s_3.style.display='none';
s_4.style.display='none';
s_5.style.display='none';
t_flag=0;
p_flag=0; }}
} // catch_key
function disp_s_container(){
monitor.disconnect(); // MutationObserverを 起動表示に反応させない
let l_body=document.querySelector('body.l-body');
let insert_node_d=document.createElement('div');
insert_node_d.setAttribute('id', 's_container');
l_body.appendChild(insert_node_d);
insert_node_d.innerHTML=
'<input id="search_box" placeholder=" 検索文字" autocomplete="off">'+
'<span id="result"> </span>'+
'<span class="s_sw s_6">▲ Caution: '+
'<span class="c_nb">nbsp</span> <span class="c_lt"><</span> '+
'<span class="c_gt">></span> <span class="c_am">&</span></span>'+
'<span class="s_sw s_1"> </span>'+
'<input id="replace_box" placeholder=" 置換文字" autocomplete="off">'+
'<span class="s_sw s_2">OK</span>'+
'<span class="s_sw s_3">UNDO</span>'+
'<span class="s_sw s_4">一括 選択</span>'+
'<span class="s_sw s_5">⇦⇧⇩⇨:移動<br>'+
'Space:設定 / 解除<br>OK:置換を確定する<br>UNDO:全て元に戻す</span>';
let css=
'#s_container {position: absolute; top: 12px; left: calc(50% - 490px); '+
'background: #fff; border: 1px solid #aaa; border-radius: 4px; '+
'padding: 6px 15px; min-width: 948px; z-index: 11;}'+
'#search_box {width: 210px;} #replace_box {width: 210px; display: none;}'+
'::placeholder {font-size: 15px; color: #bbb;}'+
'#s_container input:disabled {color: #000; background: #eef1f3;}'+
'#s_container input {font-size: 16px; padding: 2px 6px 0; -moz-appearance: none;}'+
'#result {display: inline-block; min-width: 50px; padding: 4px 6px 2px; '+
'margin-left: 5px; border: 1px solid #aaa; font-size: 16px;}'+
'.s_sw {display: inline-block; vertical-align: -9px; font-size: 15px; '+
'padding: 5px 8px 2px; border: 1px solid #aaa; overflow: hidden;}'+
'.s_1 {margin: 0 15px; min-width: 4em; display: none;} .s_1 span {color: #fff; }'+
'.s_2, .s_3, .s_4 {margin-left: 5px; color:#fff; background: #1e88e5; '+
'cursor: pointer; display: none;} .s_2 {margin-left: 15px;}'+
'.s_4 {margin-left: 15px; box-shadow: inset -45px 0 0 0 #b0bec5;}'+
'.s_5 {margin-left: 5px; position: fixed; top: 70px; right: calc(50% - 490px); width: 155px; '+
'padding: 7px 15px 4px 25px; border-radius: 4px; background: #e3f2fd; display: none;}'+
'.s_6 {margin-left: -1px; background: #ffcc00; display: none; white-space: nowrap;}'+
'.s_6:hover {width: auto !important; padding: 5px 8px 2px !important;}'+
'.c_nb, .c_lt, .c_gt, .c_am {font-weight: bold;}'+
'.js_cover {position: fixed; top: 0; width: 100%; height: 100%; '+
'background: rgba(0, 0, 0, .6); z-index: 10; display: none;}';
let style_tag=document.createElement("style"); // css設定styleタグ
style_tag.type="text/css";
style_tag.setAttribute("class", "bp");
style_tag.appendChild(iframe_doc.createTextNode(css));
if(!l_body.querySelector('.bp')){
l_body.appendChild(style_tag); }
monitor.observe(cke_1_contents, {childList: true}); }
function disp_js_cover(){
monitor.disconnect(); // MutationObserverを 起動表示に反応させない
js_cover=document.createElement("div"); // クリック操作のブロックカバー
js_cover.setAttribute("class", "js_cover");
if(!document.querySelector('.js_cover')){
document.querySelector('#js-container').appendChild(js_cover); }
js_cover=document.querySelector('.js_cover');
monitor.observe(cke_1_contents, {childList: true}); }
function search_replace(){
editor_iframe=document.querySelector('.cke_wysiwyg_frame');
if(editor_iframe){ //「通常表示」の場合
iframe_doc=editor_iframe.contentWindow.document;
iframe_html=iframe_doc.querySelector('html');
iframe_body=iframe_doc.querySelector('body.cke_editable'); }
disp_js_cover();
let s_container=document.querySelector('#s_container');
if(s_container){ // #s_container がある場合は「Ctrl+F12」で終了 「muタグを削除」
delete_mu();
s_container.remove();
native_hk=-1; } // 初期化🅿
else if(!s_container){ //#s_containerが無い場合 生成して開始
disp_s_container();
search_box=document.querySelector('#search_box');
result_box=document.querySelector('#result');
replace_box=document.querySelector('#replace_box');
s_1=document.querySelector('.s_1');
s_2=document.querySelector('.s_2');
s_3=document.querySelector('.s_3');
s_4=document.querySelector('.s_4');
s_5=document.querySelector('.s_5');
s_6=document.querySelector('.s_6');
p_flag=0; // 0=検索文字 未確定
search_box.focus();
search_box.onkeydown=function(event){ // 🔽 検索ツール操作の開始点
if(event.keyCode==13){
if(p_flag==0){
event.preventDefault();
search_word=search_box.value; // 🟥 検索文字取得
native_hk=-1; // 初期化🅿
get_search();
result_box_disp(); }
else if(p_flag==1){
event.preventDefault();
if(search_box.value==search_word){
if(caution==1 && t_flag>0 ){
s_6.style.display='inline-block';
arg_t_or_h=0; } // caution文字チェックに該当し「置換」は不可
else{
replace_box.style.display='inline-block';
replace_box.focus();
arg_t_or_h=0;
p_flag=2;
all_replace(); }} // 巡回ループを抜けて 置換入力へ
else{
iframe_body.innerHTML=buffer; // highlight を抜ける時はリセット ⏹
search_word=search_box.value; // 🟥 検索文字取得 変更
native_hk=-1; // 初期化🅿
result_box.textContent='⏎';
caution_reset();
s_1.style.display='none';
arg_t_or_h=0;
p_flag=0; // 巡回ループを抜けて 検索文字 未確定へ
search_box.dispatchEvent( new KeyboardEvent( "keydown", {keyCode: 13})); }}}
if(event.keyCode==9){ //「Tab」で置換入力へ
if(p_flag==0){
event.preventDefault(); } //「Tab」で入力枠外に出るのを抑止
else if(p_flag==1){
event.preventDefault();
if(caution==1 && t_flag>0 ){
s_6.style.display='inline-block';
arg_t_or_h=0; } // caution文字チェックに該当し「置換」は不可
else{
replace_box.style.display='inline-block';
replace_box.focus();
arg_t_or_h=0;
p_flag=2;
all_replace(); }}} // 巡回ループを抜ける
if(event.keyCode==27 ){ //「Esc」
if(p_flag==1 && t_flag==1){ //「巡回」表示をリセット
event.preventDefault();
result_box.textContent='T:'+count_t+'│-';
iframe_body.innerHTML=buffer; // highlight を抜ける時はリセット ⏹
caution_reset();
arg_t_or_h=0;
p_flag=0; }}}
search_box.onchange=function(){ //「Enter」を押さず移動した場合は検索語を再表示
if(search_box.value!==search_word){
search_box.style.outline='2px solid #2196f3';
search_box.style.outlineOffset='-3px';
setTimeout(()=>{
search_box.style.outline='none';
search_box.value=search_word; }, 500); }}
function result_box_disp(){
t_flag=0; // t_flag リセット
arg_t_or_h=0; // リセット
search_box.disabled=false;
replace_box.disabled=false;
s_1.style.display='inline-block';
s_1.style.boxShadow='none';
s_2.style.display='none';
s_3.style.display='none';
replace_box.style.display='none';
replace_box.value='';
if(count_t!=0 && count_h==0){
s_1.textContent='TEXT処理';
// s_1.style.color='#000';
t_flag=1; // TEXT処理
p_flag=1; // 1=検索文字確定 処理開始
t_process(); // 🔳 RegExp
next(hk); }
if(count_t!=0 && count_h!=0){
p_flag=1; // 1=検索文字確定 処理開始
arg_t_or_h=1; // この場合だけフラグを立てる
t_h_select(); } // TEXT・HTML処理選択
if(count_t==0 && count_h!=0){
result_box.textContent='H:'+count_h;
s_1.textContent='HTML処理';
s_1.style.color='#000';
t_flag=0;
p_flag=1; // 1=検索文字確定 処理開始
all_replace(); }
if(count_t==0 && count_h==0){
result_box.textContent='T:'+count_t+' H:'+count_h;
s_1.textContent=' - - - ';
s_1.style.color='#000';
p_flag=0; } // 0=検索文字未確定 検索前
function t_h_select(){
if(t_or_h==1){
t_flag=1; // TEXT処理
result_box.textContent='T:'+count_t+'│-';
s_1.innerHTML='TEXT処理 <span>HTML</span>';
s_1.style.boxShadow='inset -56px 0 0 0 #cfd8dc';
t_process();
next(hk); }
else{
t_flag=0; // HTML処理
result_box.textContent='H:'+count_h;
s_1.innerHTML='<span>TEXT</span> HTML処理';
s_1.style.boxShadow='inset 54px 0 0 0 #cfd8dc';
all_replace(); }
s_1.onclick=function(){
search_box.focus();
native_hk=-1; // 初期化🅿
iframe_body.innerHTML=buffer; // highlight を抜ける時はリセット ⏹
get_search();
if(t_or_h==1){
t_or_h=0; // HTML処理を選択
t_flag=0;
s_1.innerHTML='<span>TEXT</span> HTML処理';
s_1.style.boxShadow='inset 54px 0 0 0 #cfd8dc';
result_box.textContent='H:'+count_h;
all_replace(); }
else{
t_or_h=1; // TEXT処理を選択
t_flag=1;
s_1.innerHTML='TEXT処理 <span>HTML</span>';
s_1.style.boxShadow='inset -56px 0 0 0 #cfd8dc';
result_box.textContent='T:'+count_t+'│-';
t_process();
next(hk); }}}
search_box.onblur=function(){ //「検索枠」が focusを無くしたらリセット
setTimeout( ()=>{
if(replace_box.style.display=='none'){ //「置換」へ移動とT/H操作は除外
stop_out(); }}, 10); }
replace_box.onblur=function(){ //「置換枠」が focusを無くしたらリセット
setTimeout( ()=>{
if(p_flag!=3){ //「置換確認画面」へ移行は除外
stop_out(); }}, 10); }
function stop_out(){
if(arg_t_or_h==1){
setTimeout(()=>{
if(search_box!=document.activeElement){
arg_t_or_h=0;
stop_out(); }}, 400); }
else{
if(p_flag==1 || p_flag==2){ // 1=検索文字入力枠 2=置換文字入力枠
if(t_flag==1 || t_flag==2){
result_box.textContent='T:'+count_t+'│-'; }
else{
result_box.textContent='H:'+count_h; }
s_1.style.display='none';
replace_box.style.display='none';
replace_box.value='';
iframe_body.innerHTML=buffer; // highlight を抜ける時はリセット ⏹
native_hk=-1; // 初期化🅿
caution_reset();
arg_t_or_h=0;
t_flag=0;
p_flag=0; }}}} // result_box_disp()
function all_replace(){ // 置換処理全般
replace_box.focus();
all_roop();
function all_roop(){
replace_box.onkeydown=function(event){ // 🔽 置換操作の開始点
if(event.keyCode==13){
event.preventDefault();
replace_word=replace_box.value; // 🟥 置換文字取得
if(t_flag>0){
t2_process(); } // 🔳 RegExp
else{
h_process(); } // 🔳 RegExp
js_cover.style.display='block';
cke_1_contents.style.zIndex='11';
iframe_body.contentEditable='false'; // 編集不可にする
search_box.disabled=true;
replace_box.disabled=true;
s_2.style.display='inline-block';
s_3.style.display='inline-block';
add2_mu_style();
if(t_flag>0 && p_flag==2){
s_4.textContent='一括 選択';
s_4.style.display='inline-block';
s_4.style.boxShadow='inset -45px 0 0 0 #b0bec5';
replace_box.blur();
next(hk); } //「一括置換」の「巡回表示」
p_flag=3; } // 3=置換処理
if(event.keyCode==9 || event.keyCode==27){ //「Tab」「Esc」で処理前に戻る
event.preventDefault();
result_box.textContent=' ';
s_1.style.display='none';
replace_box.style.display='none';
replace_box.value='';
if(t_flag==1){
iframe_body.innerHTML=buffer; } // 置換処理をUNDO ⏹
search_box.focus();
p_flag=0; }} // 0=検索文字 未確定
s_2.onclick=function(){ //「OK」ボタンで一括置換確定
cover_remove();
delete_mu(); // muタグを削除
result_box.textContent=' '; // 検索結果は変更される
s_1.style.display='none';
replace_box.style.display='none';
replace_box.value='';
reset_mu_style();
if(t_flag>0){
t_flag=0;
native_hk=-1; } // 初期化🅿
search_box.focus();
p_flag=0; } // 0=検索文字 未確定
s_3.onclick=function(){ //「UNDO」ボタン
cover_remove();
iframe_body.innerHTML=buffer; // 置換処理をUNDO ⏹
get_search();
reset_mu_style();
if(t_flag>0){
t_flag=1;
t_process(); // 🔳 RegExp
next(hk); } // UNDO時は「一括置換」の「巡回表示」
replace_box.focus();
p_flag=2; } // 2=検索文字確定 置換文字入力 処理選択
s_4.onclick=function(){ //「一括・選択」ボタン
if(t_flag==1){
t_flag=2; //「選択置換」を指定
s_4.textContent='選択置換';
s_4.style.boxShadow='none';
s_5.style.display='inline-block';
select_replace(); } //「一括置換」に戻るのは「OK」「UNDO」以外は不可
s_4.addEventListener('mouseover', ()=>{
if(t_flag==2){
s_5.innerHTML='「OK」「UNDO」で\u2000<br>\u2000置換チェック画面を'+
'<br>\u2000終了してください'; }}, false);
s_4.addEventListener('mouseleave', ()=>{
if(t_flag==2){
s_5.innerHTML='⇦⇧⇩⇨:移動<br>'+
'Space:設定 / 解除<br>OK:置換を確定する<br>UNDO:全て元に戻す'; }}, false); }
function cover_remove(){
js_cover.style.display='none';
cke_1_contents.style.zIndex='0';
iframe_body.contentEditable='true'; // 編集可能にする
search_box.disabled=false;
replace_box.disabled=false;
s_2.style.display='none';
s_3.style.display='none';
s_4.style.display='none';
s_5.style.display='none'; }} // all_roop()
} // all_replace()
function select_replace(){ //「選択置換処理」
if(t_flag==2 && p_flag==3){
iframe_body.innerHTML=buffer; // 置換処理を一旦デフォルトに戻す ⏹
get_search();
t_process(); // 🔳 RegExp
let mark=iframe_body.querySelectorAll('mu');
next(hk); //「選択置換」の「巡回表示」
}} // select_replace()
} // #s_container が無い場合「Ctrl+F12」で開始
} // search_replace()
function next(hk){ //「巡回表示」「選択置換」コード
let mark=iframe_body.querySelectorAll('mu');
if(native_hk!=-1){ // 基本的に前回のインデックスを再現🅿
hk=native_hk; }
else if(native_hk==-1 || !native_hk){ // 初期インデックス生成🅿
if(mark.length==1){ hk=0; } // 1個なら即決定
else{
let near_n; // 中央後方の要素のインデックス
let editor_hight=editor_iframe.clientHeight; // 編集枠の高さ
for(let k=1; k<mark.length; k++){ // スクロール位置中央を越えるmark[k]を取得
if(mark[k].getBoundingClientRect().top>editor_hight/2){
near_n=k;
break; }}
if(!near_n){ // スクロール位置中央より後方にmark[k]がない場合
hk=mark.length-1; }
else{ // 直前の mark[k]と比較して、近い方を採る
if(mark[near_n].getBoundingClientRect().top>
editor_hight-mark[near_n-1].getBoundingClientRect().top){
hk=near_n-1; }
else{
hk=near_n; }}}}
view(hk);
try{
mark[hk].classList.add("h"); } // 最初のハイライト色を変更
catch(e){ ; }
result_box.textContent='T:'+count_t+'│'+(hk+1);
document.addEventListener("keydown", check_key); // documentは先に指定
iframe_doc=editor_iframe.contentWindow.document;
if(iframe_doc){
iframe_doc.addEventListener("keydown", check_key); }// iframeは後に指定
function check_key(event){
if(event.keyCode==37 || event.keyCode==38){ //「←」「↑」
if(p_flag>0 && t_flag>0){
event.preventDefault();
if(hk>0){ // 標準のハイライト色に戻す
mark[hk].classList.remove("h");
hk-=1; }
else if(hk==0){
hk=0; }
result_box.textContent='T:'+count_t+'│'+(hk+1);
try{
mark[hk].classList.add("h"); }
catch(e){ ; }
view(hk); }}
if(event.keyCode==39 || event.keyCode==40){ //「→」「↓」
if(p_flag>0 && t_flag>0){
event.preventDefault();
if(hk<mark.length-1){ // 標準のハイライト色に戻す
mark[hk].classList.remove("h");
hk+=1; }
else if(hk==mark.length-1){
hk=mark.length-1; }
result_box.textContent='T:'+count_t+'│'+(hk+1);
try{
mark[hk].classList.add("h"); }
catch(e){ ; }
view(hk); }}
if(event.keyCode==32){ //「Space」で個別に置換の設定/解除
if(p_flag==3 && t_flag==2){
event.preventDefault();
if(mark[hk].textContent==search_word){
mark[hk].textContent=replace_word; }
else if(mark[hk].textContent==replace_word){
mark[hk].textContent=search_word; }}}
native_hk=hk; }} // next() インデックス取得🅿
function view(hk){
let l_body=document.querySelector('body.l-body');
let mark=iframe_body.querySelectorAll('mu');
try{
mark[hk].scrollIntoView({block: "center"});
iframe_html.scrollBy(0, -12); } // -1~-24 -12がクリープを無くす最適値
catch(e){ ; }
l_body.scrollIntoView(); }
function get_search(){
search_word_es=escapeRegExp(search_word); // 🔳 RegExp
editor_iframe=document.querySelector('.cke_wysiwyg_frame'); // ここで取得
if(editor_iframe){ //「通常表示」が実行条件
iframe_doc=editor_iframe.contentWindow.document;
iframe_body=iframe_doc.querySelector('.cke_editable');
buffer=iframe_body.innerHTML; // ハイライト表示のためソースコードを保存 🟦
buffer_arr=[]; // 切分けたソースコードを入れる配列
let sa=0;
let sb=0;
let sc=0;
let result_t;
let result_h;
let n=buffer.split('<').length-1; // 開始・終結を含む全タグ数を取得
for(let k=0; k<n; k++){
sb=buffer.indexOf('>', sa);
buffer_arr.push(buffer.slice(sa, sb+1)); //タグ括弧内 1個を配列に収納
sc=buffer.indexOf('<', sb+1);
if(sc==-1){ break; } // 文書の末尾で後がない場合に終了
else{
buffer_arr.push(buffer.slice(sb+1, sc)); //タグ括弧外 1個を配列に収納
sa=sc; }}
avoid=[]; //「styleタグ」のインデックスを記録
for(let i=0; i<n; i++){
if(buffer_arr[i*2].match(new RegExp('<style'))){
avoid.push(i*2); }}
count_t=0; // テキストノードのヒット数
for(let i=0; i<n; i++){ //配列の奇数インデックスはタグ括弧外(TEXT)
if(buffer_arr[i*2+1]){
result_t=buffer_arr[i*2+1].match(new RegExp(search_word_es, 'g')); // 🔳 RegExp
if(result_t){
count_t+=result_t.length; }}}
count_h=0; // HTMLコードのヒット数
for(let i=0; i<n; i++){ //配列の偶数インデックスはタグ括弧内(HTMLコード)
result_h=buffer_arr[i*2].match(new RegExp(search_word_es, 'g')); // 🔳 RegExp
if(result_h){
count_h+=result_h.length; }}
caution_ck(); //「no-break space」「文字実体参照」の可能性をチェック
}} // get_search()
function caution_ck(){
caution=0;
document.querySelector('.c_nb').style.display='none';
document.querySelector('.c_lt').style.display='none';
document.querySelector('.c_gt').style.display='none';
document.querySelector('.c_am').style.display='none';
if(' '.match(new RegExp(search_word_es))){
if(buffer.match(new RegExp(/ /))){
document.querySelector('.c_nb').style.display='inline';
caution=1; }}
if('<'.match(new RegExp(search_word_es))){
if(buffer.match(new RegExp(/</))){
document.querySelector('.c_lt').style.display='inline';
caution=1; }}
if('>'.match(new RegExp(search_word_es))){
if(buffer.match(new RegExp(/>/))){
document.querySelector('.c_gt').style.display='inline';
caution=1; }}
if('&'.match(new RegExp(search_word_es))){
if(buffer.match(new RegExp(/&/))){
document.querySelector('.c_am').style.display='inline';
caution=1; }}}
function caution_reset(){
s_6.style.display='none'; }
function t_process(){
let rep_word='<mu>'+ search_word +'</mu>';
let n=buffer.split('<').length-1; // 開始・終結を含む全タグ数を取得
for(let i=0; i<n; i++){ //配列の奇数インデックスはタグ括弧外(TEXT)
let pass=1;
for(let j=0; j<avoid.length; j++){
if(avoid[j]==i*2){
pass=0;
break; }}
if(pass!=0 && buffer_arr[i*2+1]){
buffer_arr[i*2+1]=buffer_arr[i*2+1].replace(new RegExp(search_word_es, 'g'), rep_word); }} // 🔳 RegExp
iframe_body.innerHTML=buffer_arr.join(''); }
function t2_process(){
let rep_word=replace_word;
let n=buffer.split('<').length-1; // 開始・終結を含む全タグ数を取得
for(let i=0; i<n; i++){ //配列の奇数インデックスはタグ括弧外(TEXT)
let pass=1;
for(let j=0; j<avoid.length; j++){
if(avoid[j]==i*2){
pass=0;
break; }}
if(pass!=0 && buffer_arr[i*2+1]){
buffer_arr[i*2+1]=buffer_arr[i*2+1].replace(new RegExp(search_word_es, 'g'), rep_word); }} // 🔳 RegExp
iframe_body.innerHTML=buffer_arr.join(''); }
function h_process(){
let rep_word=replace_word;
let n=buffer.split('<').length-1; // 開始・終結を含む全タグ数を取得
for(let i=0; i<n; i++){ //配列の偶数インデックスはタグ括弧内(HTMLコード)
if(buffer_arr[i*2]){
buffer_arr[i*2]=buffer_arr[i*2].replace(new RegExp(search_word_es, 'g'), rep_word); }} // 🔳 RegExp
iframe_body.innerHTML=buffer_arr.join(''); }
function add_mu_style(){
editor_iframe=document.querySelector('.cke_wysiwyg_frame');
if(editor_iframe){ //「通常表示」の場合
iframe_doc=editor_iframe.contentWindow.document;
iframe_html=iframe_doc.querySelector('html');
let css_iframe=
'.cke_editable mu { background: #ffcc00; } '+ // ハイライト muタグ背景色⭕
'.cke_editable mu.h { background: #85ff00; }'; // フォーカス muタグ背景色⭕
let style_tag_iframe=iframe_doc.createElement("style");
style_tag_iframe.type="text/css";
style_tag_iframe.setAttribute("class", "ep");
style_tag_iframe.appendChild(document.createTextNode(css_iframe));
if(iframe_html.querySelector('.ep')){
iframe_html.querySelector('.ep').remove(); }
iframe_html.appendChild(style_tag_iframe); }}
function add2_mu_style(){
if(replace_word==''){
replace_box.setAttribute('placeholder', " 🟦 削除モード");
replace_box.style.border='2px solid #009688';
replace_box.style.background='#090907';
replace_box.style.filter='invert(1)';
if(t_flag>0){
if(iframe_html.querySelector('.ep')){ // ハイライト・フォーカス muタグ「削除モード」⭕
iframe_html.querySelector('.ep').textContent=
'.cke_editable mu { box-shadow: 0 0 0 2px #ffcc00; background: #ffcc00; } '+
'.cke_editable mu.h { filter: opacity(1); '+
'box-shadow: 0 0 0 2px red; background: #fce4ec; }'; }}}}
function reset_mu_style(){
replace_box.setAttribute('placeholder', " 置換文字");
replace_box.style.border='';
replace_box.style.background='';
replace_box.style.filter='none';
if(t_flag>0){
if(iframe_html.querySelector('.ep')){ // ハイライト・フォーカス muタグ デフォルト ⭕
iframe_html.querySelector('.ep').textContent=
'.cke_editable mu { background: #ffcc00; } '+
'.cke_editable mu.h { background: #85ff00; }'; }}}
function delete_mu(){
editor_iframe=document.querySelector('.cke_wysiwyg_frame');
if(editor_iframe){ //「通常表示」の場合
iframe_doc=editor_iframe.contentWindow.document;
iframe_body=iframe_doc.querySelector('.cke_editable');
if(iframe_body){
let mark=iframe_body.querySelectorAll('mu');
if(mark.length!=0){
iframe_body.innerHTML=
iframe_body.innerHTML.replace(new RegExp('<mu.*?>', 'g'), ''); }}}} // 🔳 RegExp
function escapeRegExp(string){
let reRegExp=/[\\^$.*+?()[\]{}|]/g;
let reHasRegExp=new RegExp(reRegExp.source);
return (string && reHasRegExp.test(string))
? string.replace(reRegExp, '\\$&')
: string; }
});
「S-R in Editor ⭐」最新版について
旧いバージョンの JavaScriptツールは、アメーバのページ構成の変更で動作しない場合があり、導入する場合は最新バージョンをお勧めします。
●「S-R in Editor ⭐」の最新バージョンへのリンクは、以下のページのリンクリストから探せます。

