
LINEスタンプの「タグ編集」に登録したタグの「保存」と「削除」をする2つのブックマークレット
毎度、rorosukeです。
LINEスタンプ作ってますか?
LINEスタンプをLINEクリエイターズマーケットに投稿する際の作業の一つとして、タグ編集があります。ここに登録したタグは、基本的にはそのまま申請するだけなのですが、場合によっては、
設定タグを全保存したい
と思うことがあるかもしれません。また、もう一度改めてすべてのタグを付け替えたいので、
設定タグを全削除したい
と思うこともあるかもしれません。そしてこのような場合、通常は手作業で行うしかありません。
というわけで、これらの処理をお手軽に行う2つのブックマークレットを公開したいと思います。
📌設定タグ保存ブックマークレット
タグ編集で、すでに設定されているタグを読み取って、CSV形式で保存するためのブックマークレットです。表示している番号以降を対象にします。
▶️コード
javascript:(async function(){var WAIT=500;var W=function(ms){return new Promise(function(r){setTimeout(r,ms);});};var cur=function(){var s=document.querySelector('button.btn-dropdown .btn-dropdown-text');if(!s){return null;}var n=parseInt(s.textContent.trim(),10);return isNaN(n)?null:n;};if(cur()===null){alert('ページ番号が取得できません。\nスタンプタグ編集ページで実行してください。');return;}var stop=false;var box=document.createElement('div');box.style.cssText='position:fixed;top:12px;right:12px;z-index:10000;background:#fff;border:2px solid #1e88e5;border-radius:10px;padding:12px 16px;font:13px sans-serif;box-shadow:0 6px 24px rgba(0,0,0,0.3);max-width:320px;';box.innerHTML='<div id="tx-msg" style="margin-bottom:8px;color:#333;"></div><button id="tx-stop" style="background:#9e9e9e;color:#fff;border:none;padding:6px 14px;border-radius:5px;cursor:pointer;">中止</button>';document.body.appendChild(box);document.getElementById('tx-stop').onclick=function(){stop=true;};var msg=function(t){document.getElementById('tx-msg').textContent=t;};var getLabels=function(){return document.querySelectorAll('label.cm-product-image-tag');};var nameOf=function(l){var sp=l.querySelector('span.cm-product-image-tag-name-text');return sp?sp.textContent.replace(/\s*[((][0-9]+[))]\s*$/,'').trim():'';};var isOn=function(l){var cb=l.querySelector('input[type="checkbox"]');return !!(cb&&cb.checked);};var tagsNow=function(){var ls=getLabels();var o=[];var s={};for(var i=0;i<ls.length;i++){if(isOn(ls[i])){var n=nameOf(ls[i]);if(n&&!s[n]){s[n]=1;o.push(n);}}}return o;};var press=async function(sel){var b=document.querySelector(sel);if(!b||b.disabled||b.getAttribute('aria-disabled')==='true'){return null;}var before=cur();b.click();await W(WAIT);for(var t=0;t<20;t++){var c=cur();if(c!==null&&c!==before){return c;}await W(250);}return null;};var rows=[],empty=[],errs=[],seen={};while(!stop){var n=cur();var ns=String(n).padStart(2,'0');if(seen[n]){break;}seen[n]=1;msg('読み取り中:'+ns+'番('+(rows.length+empty.length)+'件完了)');var ready=false;for(var t=0;t<20;t++){if(getLabels().length>0){ready=true;break;}await W(250);}if(!ready){errs.push(ns+'番: タグエリアが表示されませんでした');}else{var a=tagsNow();for(var k=0;k<5;k++){await W(250);var b2=tagsNow();if(JSON.stringify(b2)===JSON.stringify(a)){break;}a=b2;}if(a.length>0){rows.push(ns+','+a.join(','));}else{empty.push(ns);}}var nx=await press('button.btn-next-image');if(nx===null){break;}}document.body.removeChild(box);var text=rows.join('\n');var ov=document.createElement('div');ov.style.cssText='position:fixed;top:0;left:0;width:100vw;height:100vh;background:rgba(0,0,0,0.55);z-index:10000;display:flex;justify-content:center;align-items:center;font-family:sans-serif;';var bx=document.createElement('div');bx.style.cssText='background:#fff;border-radius:12px;padding:24px;width:90vw;max-width:760px;max-height:92vh;overflow-y:auto;box-shadow:0 12px 40px rgba(0,0,0,0.35);';bx.innerHTML='<h2 style="margin:0 0 8px;color:#333;font-size:17px;">📤 タグCSV</h2><div id="tx-info" style="font-size:12px;color:#555;margin-bottom:8px;"></div><textarea id="tx-ta" readonly style="width:100%;height:50vh;border:1px solid #ccc;border-radius:6px;padding:10px;font-size:12px;font-family:monospace;box-sizing:border-box;"></textarea><div id="tx-err" style="display:none;margin-top:10px;padding:8px;background:#fff3f3;border:1px solid #f44336;border-radius:6px;font-size:12px;color:#c62828;"></div><div style="display:flex;gap:10px;margin-top:12px;"><button id="tx-copy" style="flex:1;background:#1e88e5;color:#fff;border:none;padding:12px;border-radius:6px;cursor:pointer;font-weight:bold;">コピー</button><button id="tx-dl" style="flex:1;background:#43a047;color:#fff;border:none;padding:12px;border-radius:6px;cursor:pointer;font-weight:bold;">CSVをダウンロード</button><button id="tx-close" style="background:#9e9e9e;color:#fff;border:none;padding:12px 20px;border-radius:6px;cursor:pointer;">閉じる</button></div>';ov.appendChild(bx);document.body.appendChild(ov);var ta=document.getElementById('tx-ta');ta.value=text;document.getElementById('tx-info').textContent=(stop?'中止しました。':'完了しました。')+' タグあり:'+rows.length+' 件'+(empty.length>0?'/タグなし(出力から除外):'+empty.join('、')+'番':'');if(errs.length>0){var ed=document.getElementById('tx-err');ed.style.display='block';ed.textContent=errs.join(' / ');}document.getElementById('tx-copy').onclick=async function(){try{await navigator.clipboard.writeText(text);}catch(e){ta.select();document.execCommand('copy');}this.textContent='コピーしました';};document.getElementById('tx-dl').onclick=function(){var blob=new Blob(['\ufeff'+text+'\n'],{type:'text/csv;charset=utf-8'});var l=document.createElement('a');l.href=URL.createObjectURL(blob);l.download='tags.csv';document.body.appendChild(l);l.click();document.body.removeChild(l);};document.getElementById('tx-close').onclick=function(){document.body.removeChild(ov);};})();▶️使い方
1.編集ページを開く
タグ保存したい先頭の番号のスタンプを表示します。01番から40番まで保存したいときには、01番を表示します。

2.ブックマークレットを実行する
ブラウザの右上にダイアログが表示され、タグの読み取りが開始します。途中で止めたくなったときには「中止」ボタンを押してください。

3.すべて読み取ると終了
最後の番号まで読み取ると、結果を表示します。「コピー」ボタンでクリップボードに、「CSVをダウンロード」でファイルに保存されます。

▶️保存したタグを再登録
本スクリプトで保存したタグデータは、次の記事で公開している「まとめて登録式ブックマークレット」に入力すると、そのまま再登録できます。
📌設定タグ削除(解除)ブックマークレット
タグ編集ページで1回クリックするだけで、表示中の番号から最後のスタンプまで、登録されているタグをまとめて解除するブックマークレットです。スタンプに登録したタグを外すだけのものです。
▶️コード
javascript:(async function(){var WAIT=500;var W=function(ms){return new Promise(function(r){setTimeout(r,ms);});};var cur=function(){var s=document.querySelector('button.btn-dropdown .btn-dropdown-text');if(!s){return null;}var n=parseInt(s.textContent.trim(),10);return isNaN(n)?null:n;};if(cur()===null){alert('ページ番号が取得できません。\nスタンプタグ編集ページで実行してください。');return;}if(!confirm('表示中の'+String(cur()).padStart(2,'0')+'番から最後のスタンプまで、【すべてのスタンプ】のタグをすべて削除します。\n\n※元に戻せません。よろしいですか?')){return;}var stop=false;var box=document.createElement('div');box.style.cssText='position:fixed;top:12px;right:12px;z-index:10000;background:#fff;border:2px solid #e53935;border-radius:10px;padding:12px 16px;font:13px sans-serif;box-shadow:0 6px 24px rgba(0,0,0,0.3);max-width:320px;';box.innerHTML='<div id="ct-msg" style="margin-bottom:8px;color:#333;"></div><button id="ct-stop" style="background:#9e9e9e;color:#fff;border:none;padding:6px 14px;border-radius:5px;cursor:pointer;">中止</button>';document.body.appendChild(box);document.getElementById('ct-stop').onclick=function(){stop=true;};var msg=function(t){document.getElementById('ct-msg').textContent=t;};var getLabels=function(){return document.querySelectorAll('label.cm-product-image-tag');};var nameOf=function(l){var sp=l.querySelector('span.cm-product-image-tag-name-text');return sp?sp.textContent.replace(/\s*[((][0-9]+[))]\s*$/,'').trim():'';};var isOn=function(l){var cb=l.querySelector('input[type="checkbox"]');return !!(cb&&cb.checked);};var uniq=function(){var ls=getLabels();var o={};for(var i=0;i<ls.length;i++){if(isOn(ls[i])){o[nameOf(ls[i])||('#'+i)]=1;}}return Object.keys(o);};var clickOn=async function(){var ls=getLabels();for(var i=0;i<ls.length;i++){if(isOn(ls[i])){ls[i].click();await W(60);}}await W(300);};var press=async function(sel){var b=document.querySelector(sel);if(!b||b.disabled||b.getAttribute('aria-disabled')==='true'){return null;}var before=cur();b.click();await W(WAIT);for(var t=0;t<20;t++){var c=cur();if(c!==null&&c!==before){return c;}await W(250);}return null;};var pages=0,total=0,errs=[],seen={};while(!stop){var n=cur();var ns=String(n).padStart(2,'0');if(seen[n]){break;}seen[n]=1;msg('処理中:'+ns+'番('+pages+'件完了)');var ready=false;for(var t=0;t<20;t++){if(getLabels().length>0){ready=true;break;}await W(250);}if(!ready){errs.push(ns+'番: タグエリアが表示されませんでした');}else{var before=uniq();if(before.length>0){await clickOn();var remain=uniq();if(remain.length>0){await clickOn();remain=uniq();}total+=before.length-remain.length;if(remain.length>0){errs.push(ns+'番: 解除できなかったタグ '+remain.join('、'));}await W(400);}pages++;}var nx=await press('button.btn-next-image');if(nx===null){break;}}document.body.removeChild(box);alert((stop?'中止しました。\n':'完了しました。\n')+'処理したスタンプ:'+pages+' 件\n解除したタグ:合計 '+total+' 個'+(errs.length>0?'\n\n【エラー】\n'+errs.join('\n'):''));})();▶️使い方
1.編集ページを開く
タグ削除したい先頭の番号のスタンプを表示します。01番から40番まで削除したいときには、01番を表示します。

2.ブックマークレットを実行する
削除の確認ダイアログが表示されます。OKを押すと、タグの削除を開始します。タグを削除すると、再設定しない限り元に戻せませんので、慎重に判断してください。

3.削除を開始
ブラウザの右上にダイアログが表示され、タグの削除を開始します。途中で止めたくなったときには「中止」ボタンを押してください。

4.すべて削除すると終了
最後の番号まで削除すると、結果レポートを表示します。「OK」ボタンをクリックすると終了です。

📌ブックマークレットの登録方法
ブックマークレットについて解説します。
ブックマークレットとは、URLの代わりにJavaScriptのコードを登録した「特殊なブックマーク」です。処理したいWebページを開いてからブックマークを選択すると、プログラムが実行され、Webページに対して処理が行われます。今回であれば「タグを読み取る」とか「タグを削除する」という処理です。
ブックマークレットを導入する手順は次のとおりです。ChromeなどのPCブラウザを想定しています。
▶️ステップ1 ブックマークバーを表示する
Chromeなら、Ctrl+Shift+Bでブックマークバーを表示します。すでに表示されている場合は、そのままで大丈夫です。
▶️ステップ2 適当なページをブックマークする
任意のページを開いてCtrl+Dでブックマークに追加します。このとき、名前を「タグ保存」「タグ削除」など、わかりやすいものにしておきましょう。

▶️ステップ3 URL欄にコードを貼り付ける
追加したブックマークを右クリックして「編集」を選びます。URL欄にコードを貼り付けてから保存します。コードは「javascript:」から最後の「;」まで全部コピーしてください。アドレスバーに貼ると「javascript:」が消えることがあるので、必ずこの編集画面のURL欄に貼ります。

まとめ:先回りの精神
もともとは、「削除」が欲しいと思っていたので先に作りました。
読み取り保存については、たいていは一回タグ設定してそのまま申請となるはずなので、「もしかしたら」ぐらいの感じです。
本当に必要とされる方がいるかはわかりませんが、そこは先回りの精神で公開してみました。
「削除」に関しては、実行すると元に戻せません。先に「保存」でタグを書き出しておくと安心です。くれぐれも慎重に行ってください。
以上!
#時産時利 #AI活用 #時短術 #LINEスタンプ #LINEクリエイターズマーケット #削除 #保存 #読み取り #ブックマークレット #JavaScript