「クエリ文字列」からの年度取得コードを改善
「Quick EntryList」の年度ジャンプのボタンは、ジャンプ先の年度を指定するだけでなく、現在に表示しているデータの年度も表示する必要があります。 現在のデザインは、デフォルトの年度表示の上に被せ、その表示を奪っているので、責任重大です。
で、ページデータから年度を割り出して表示するのですが、これまではページURLのクエリ文字列から「年度・月」を読み取っていました。「記事の編集・削除」のシステムは、「entry_ym=202205」の形式のクエリ文字列でページ操作をしています。(但し、最初に開いた時は、この文字列は有りません)
これは、これまで問題が無かったのですが、前ページの「Edit At Once Am」のテストで、「記事の編集・削除」を開いた時に「年度表示」が正しい表示でないのに気付きました。 調べると理由は簡単でした。
下は、「Edit At Once Am」が送り出すクエリ文字列の例で、「年度・月」だけでなく「ユーザーID」「記事ID」を追加していたのです。
このクエリ、自分で作っておきながら忘れていました。 年度の読出しコードは単純で、「entry_ym=202205」が末尾と想定していたので、こんなクエリを受け取ったら年度が正しく読み出せなかったのです。
ページ上に年度のデータはいくらでもある
上記の様なクエリ文字列でも「entry_ym」を検索して読み出せるのですが、ページ上に現在の「年度・月」を反映する場所は沢山あります。 そこから「年度」を読んだ方が簡単です。
下は、全体の「form要素」の最初にある隠し「input要素」で、名前は「urlParam」となっていて、必ず「年度・月」の value値がセットされます。
今後はこれを読む事にしました。 以下は「年度」を取得して、年度を選択するセレクトボックスの初期表示を、自動的に「年度」に設定するコードです。
前半は、上記の「input要素」から「年度」を読み出しています。
中間のコードは、この操作で「年度」が読めなかった場合に、現在の年度を設定する様にしています。(値がないよりましですから) 後半は、セレクトボックスの選択できる年度を生成しながら、初期表示表示をこの年度にするコードです。
以上の改善で、「Edit At Once」の複雑なクエリでも、年度表示に問題を生じなくなりました。
「Quick EntryList」の仕様と操作方法
ツールの全機能の説明と操作については、下のマニュアルを参照ください。
「Quick EntryList」を利用するには
このツールは Chrome / Edge / Firefox の拡張機能「Tampermonkey」上で動作します。 このツールは常駐型のツールで、Tampermonkey上で常に「ON」にしておくと、「記事の編集・削除」の画面を開いた時に起動します。
以下に、このツールの導入手順を簡単に説明します。
❶「Tampermonkey」を導入します
使用しているブラウザに拡張機能「Tampermonkey」を導入する事が必要です。 以下のページに簡単な導入の説明があるので参照ください。
❷「Tampermonkey」にスクリプトを登録します
●「Tampermonkey」の「+」マークの「新規スクリプト」タブを開きます。
●「新規スクリプト」には、最初からテンプレートが記入されています。 これは全て削除して、完全に空白の編集枠に 下のコードをコピー&ペーストします。
〔コピー方法〕 軽量シンプルなツール「PreBox Button 」を使うと
コード枠内を「Ctrl+左Click」➔「Copy code 」を「左Click」
の操作で、掲載コードのコピーが可能になります。
● 最後に「ファイル」メニューの「保存」を押すと、ツールが使用可能になります。
〔 Quick EntryList 〕 ver. 0.8
// ==UserScript==
// @name Quick EntryList
// @namespace http://tampermonkey.net/
// @version 0.8
// @description 記事の編集・削除の機能拡張
// @author Ameba Blog User
// @match https://blog.ameba.jp/ucs/entry/srventrylist*
// @match https://blog.ameba.jp/ucs/entry/srventry*draft*
// @grant none
// ==/UserScript==
let year_list=[]; // 選択年度の配列
let point_ym; // ユーザーの指定年月のクエリー文字
let qe_ym=[]; // Quick EntryList 復帰ポイントのユーザー設定
let read_json=localStorage.getItem('QE_Point'); // ローカルストレージ 保存名
qe_ym=JSON.parse(read_json);
if(qe_ym==null){
qe_ym=['', '?', '?', '?', '?']; }
let write_json=JSON.stringify(qe_ym);
localStorage.setItem('QE_Point', write_json); // ローカルストレージ 保存
let disp_qe=
'<div id="disp_qe">'+
'<span class="qe_s">表示年月:</span>'+
'<button class="qe_button" id="qe_b1"></button>'+
'<button class="qe_button" id="qe_b2"></button>'+
'<button class="qe_button" id="qe_b3"></button>'+
'<button class="qe_button" id="qe_b4"></button></div>';
let Main_h1=document.querySelector('#ucsMainLeft h1');
if(!document.querySelector('#disp_qe') && Main_h1){
Main_h1.insertAdjacentHTML('beforeend', disp_qe); }
let ym_select=
'<select id="ym_select_box"></select>';
let entrySort=document.querySelector('#entrySort');
if(!document.querySelector('#ym_select_box') && entrySort){
entrySort.insertAdjacentHTML('beforeend', ym_select); }
let qe_style=
'<style id="qe_style">'+
'#disp_qe { float: right; padding-left: 20px; margin-top: -2px; '+
'background: #fff; } '+
'.qe_s { font: normal 14px Meiryo; cursor: default; } '+
'.qe_s:hover::before { '+
'content: "Ctrl+Click:表示年月を登録 Click:登録ページを表示"; '+
'position: absolute; margin: -27px 0 0; padding: 2px 6px 0; '+
'background: #fff; border: thin solid #aaa; } '+
'.qe_button { height: 25px; min-width: 70px; font-size: 15px; '+
'margin: 0 4px; padding: 2px 6px; border: 1px solid #ccc; '+
'vertical-align: -1px; cursor: pointer; } '+
'#entrySort { position: relative; padding: 1px 0 0; } '+
'#entryYear { display: flex; justify-content: space-between; '+
'align-items: center; width: 120px; margin: 0 5px; } '+
'#yearText { position: absolute; top: 6px; left: 84px; width: 16px; '+
'padding: 0 1px; font-size: 14px; color: #1976d2; z-index: 1; } '+
'#ym_select_box { position: absolute; top: 0; left: 24px; height: 29px; '+
'width: 81px; padding: 1px 11px 0 0; font: bold 18px Meiryo !important; '+
'text-align: center; border: 1px solid #ccc; outline: none; background: #fff; '+
'appearance: none; scrollbar-width: none; cursor: pointer; } '+
'#ym_select_box::-webkit-scrollbar { display: none; } '+
'#ym_select_box option { font: bold 18px Meiryo; } '+
'#entryMonth { margin-right: -10px; } '+
'#sorting .pagingArea { float: left; margin: -3px -10px -3px 20px; '+
'background: #fff; } '+
'#sorting .pagingArea ul { padding: 3px 2px 2px; } '+
'#sorting .pagingArea li { margin: 0; padding: 0;border-right: none; }</style>';
if(!document.querySelector('#qe_style')){
document.documentElement.insertAdjacentHTML('beforeend', qe_style); }
for(let k=1; k<5; k++){
disp_button(k)}
set_year_list();
disp_select();
select_year();
point_set(1);
point_set(2);
point_set(3);
point_set(4);
paging();
feature();
function disp_button(n){
let button=document.querySelector('#qe_b'+n);
if(button){
let date_raw;
let ny;
let nm;
if(qe_ym[n].indexOf("&so=")!=-1){ // 古い順表示の場合
date_raw=qe_ym[n].substring(0, qe_ym[n].indexOf("&so=")); }
else{
date_raw=qe_ym[n]; }
ny=date_raw.slice(-6, -2);
nm=date_raw.slice(-2);
if((ny>1999 && ny<2100) && (nm>0 && nm<13)){
button.textContent=ny+'-'+nm; }
else{ // 未登録の場合
button.textContent='- - -'; }}}
function select_year(){
let set_year;
let ym_select_box=document.querySelector('#ym_select_box');
if(ym_select_box){
ym_select_box.onchange=function(){
set_year=ym_select_box.options[ym_select_box.selectedIndex].value;
location.href=
"https://blog.ameba.jp/ucs/entry/srventrylist.do?entry_ym="+
set_year +"01"; }}}
function set_year_list(){
let currentTime=new Date();
let year=currentTime.getFullYear();
for(let k=2000; k<year+1; k++){
year_list.push(k); }
year_list.reverse(); }
function disp_select(){
let page_year;
let query;
let input_year=document.querySelector('input[name="urlParam"]');
if(input_year){
query=input_year.value;
page_year=query.slice(-6, -2); }
if(!page_year){
let currentTime=new Date();
let current_year=currentTime.getFullYear();
page_year=current_year; }
let ym_select_box=document.querySelector('#ym_select_box');
if(ym_select_box){
for(let k=0; k<year_list.length; k++){
let option=document.createElement('option');
option.text=year_list[k];
option.value=year_list[k];
ym_select_box.appendChild(option);
if(page_year==year_list[k]){
option.selected=true; }}}}
function point_set(n){
let point_button=document.querySelector('#qe_b'+n);
if(point_button){
point_button.onclick=function(event){
if(!event.ctrlKey){ // 登録ページの表示
location.href=
"https://blog.ameba.jp/ucs/entry/srventrylist.do"+ qe_ym[n]; }
else{ // ページを登録
let date_raw;
let ny;
let nm;
let current_search; // 現在のクエリー文字列
if(!location.search){ //「記事の編集・削除」の初期表示の場合
let currentTime=new Date();
ny=currentTime.getFullYear();
nm=('0'+(currentTime.getMonth()+1)).slice(-2); }
else{
if(location.search.indexOf("&so=")!=-1){ // 古い順表示の場合
date_raw=location.search.substring(0, location.search.indexOf("&so=")); }
else{
date_raw=location.search; }
ny=date_raw.slice(-6, -2);
nm=date_raw.slice(-2); }
if((ny>1999 && ny<2100) && (nm>0 && nm<13)){
let ok=confirm(
" 💢 Quick指定年月の登録を変更します\n\n"+
"「OK」を押すと現在選択している "+ny+"年 "+nm+"月 のページを登録します" );
if(ok){
current_search=location.search;
if(!current_search){
current_search='?entry_ym='+ny+nm; }
qe_ym[n]=current_search;
let write_json=JSON.stringify(qe_ym); // ローカルストレージ 保存
localStorage.setItem('QE_Point', write_json);
disp_button(n); }}
else{ // クエリーの値が不正値の場合
let ok=confirm(
" 💢 クエリー文字列が異常値で登録できません\n\n"+
" 「OK」を押すと先頭ページに移動します" );
if(ok){
location.href=
"https://blog.ameba.jp/ucs/entry/srventrylist.do"; }}}
}}} // point_set()
function paging(){
let paging_area=document.querySelector('.pagingArea');
if(paging_area){
let sorting=document.querySelector('#sorting');
let s_theme=document.querySelector('#selectTheme');
let clone_paging=document.querySelector('#sorting .pagingArea');
if(!clone_paging){
if(sorting && s_theme){
let clone=paging_area.cloneNode(true);
sorting.insertBefore(clone, s_theme.nextElementSibling); }}}}
function feature(){
let currentDate = new Date();
let year=currentDate.getFullYear();
let month=currentDate.getMonth() + 1;
let date=currentDate.getDate();
let hour=currentDate.getHours();
let minute=currentDate.getMinutes();
function formatTime(val) {
return ("0" + val).slice(-2); } //「0」付きで2桁テキストに変更
let now=year + formatTime(month) + formatTime(date) +
formatTime(hour) + formatTime(minute)
now=parseInt(now, 10);
let page_year=document.querySelector('#entryYear #year');
if(page_year){
page_year=page_year.textContent; }
else{
page_year='2000'; }
let p_time=document.querySelectorAll('#entryList .date');
for(let k=0; k<p_time.length; k++){
let p_date=p_time[k].textContent;
p_date=page_year + p_date.replace(/[^0-9]/g, '');
p_date=parseInt(p_date, 10); // 文字列を10進数に変換
if(p_date>now){
p_time[k].style.color='#fff';
p_time[k].style.background='#2196f3'; }}
} // feature()
if(location.pathname.includes('draft')){ // 下書き保存の場合
let qe_button=
'<div id="qe_button">'+
'<svg viewBox="0 0 120 120">'+
'<path d="M0 0L0 112L112 112L112 0L0 0z" style="fill:#fff"></path>'+
'<path d="M23 21L45 21C48 21 52 20 55 22C60 26 56 34 64 36C70 38 '+
'78 37 84 37C88 37 92 37 94 40C97 43 96 48 96 52L96 81C100 81 103 '+
'80 105 76C107 73 106 69 106 65L106 43C106 39 106 35 104 31C101 27 '+
'96 27 92 27C84 27 76 27 68 27C68 22 68 17 65 14C61 10 55 11 50 11C39 '+
'11 26 8 23 21M52 43C52 40 52 38 51 35C48 25 35 27 27 27C21 27 13 26 '+
'9 32C6 37 7 43 7 48L7 82C7 87 6 94 10 97C15 101 22 100 28 100L69 '+
'100C74 100 81 101 86 98C90 95 90 91 90 86L90 58C90 53 90 48 86 '+
'45C83 43 79 43 75 43L52 43z" style="fill:#010101"></path>'+
'<path d="M80 53C72 52 65 52 57 52C54 52 49 53 47 52C40 48 44 39 '+
'38 37C34 36 21 35 18 39C16 42 17 45 17 48L17 69C17 74 15 85 18 '+
'89C21 92 28 91 32 91L67 91C71 91 77 92 80 89C82 86 81 81 81 78C81 '+
'70 81 61 80 53z" style="fill:#fff"></path></svg>'+
'記事の編集・削除を表示'+
'<style>'+
'#qe_button { position: absolute; top: 170px; left: calc(50% + 200px); '+
'font: normal 16px Meiryo; padding: 7px 20px 5px; border-radius: 6px; '+
'background: #fff; box-shadow: 5px 10px 30px #00000025; } '+
'#qe_button:hover { background: #cfd8dc; } '+
'#qe_button svg { width: 48px; height: 36px; vertical-align: -12px; } }</style></div>';
if(!document.querySelector('#qe_button')){
document.body.insertAdjacentHTML('beforeend', qe_button); }
let files_link=document.querySelector('#qe_button');
if(files_link){
files_link.onclick=function(){
location.href="https://blog.ameba.jp/ucs/entry/srventrylist.do"; }}}
「Quick EntryList」最新版について
旧いバージョンの「Quick EntryList」は、アメーバのページ構成の変更で動作しない場合があり、導入する場合は最新バージョンをお勧めします。 最新バージョンへのリンクは、以下のページのリンクリストから探せます。




