1(function(){'use strict';if(!document.getElementById('n2pn-settings-form')){return;} 2document.addEventListener('DOMContentLoaded',function(){setTimeout(initFcmCheck,800);});function initFcmCheck(){injectStatusCard();checkFcmSubscriptions();document.querySelectorAll('input[name="topics[]"]').forEach(function(cb){cb.addEventListener('change',function(){var cached=window.__n2pnFcmActual||[];markCheckboxes(cached);});});} 3function injectStatusCard(){var statusDiv=document.querySelector('.n2pn-settings-status');if(!statusDiv)return;var card=document.createElement('div');card.className='n2pn-status-card';card.id='n2pn-fcm-status-card';card.style.cssText='margin-top:16px;border-left-color:#FF9800;';card.innerHTML='<h3>FCMç»é²ç¶æ </h3>'+'<p id="n2pn-fcm-status-text">確èªä¸...</p>'+'<div id="n2pn-fcm-diff" style="display:none;margin-top:8px;font-size:13px;"></div>'+'<div id="n2pn-fcm-actions" style="margin-top:12px;display:none;">'+' <button type="button" id="n2pn-fcm-repair-btn" class="n2pn-btn n2pn-btn-primary" style="margin-right:8px;">æ¬ ãã¦ãããããã¯ãåç»é²</button>'+' <button type="button" id="n2pn-fcm-recheck-btn" class="n2pn-btn-link">å確èªãã</button>'+'</div>';statusDiv.appendChild(card);document.getElementById('n2pn-fcm-repair-btn').addEventListener('click',handleRepair);document.getElementById('n2pn-fcm-recheck-btn').addEventListener('click',function(e){e.preventDefault();checkFcmSubscriptions();});} 4async function checkFcmSubscriptions(){var statusEl=document.getElementById('n2pn-fcm-status-text');var diffEl=document.getElementById('n2pn-fcm-diff');var actionsEl=document.getElementById('n2pn-fcm-actions');statusEl.innerHTML='<small>確èªä¸...</small>';diffEl.style.display='none';actionsEl.style.display='none';var fcmToken=localStorage.getItem('n2pn_fcm_token');if(!fcmToken){statusEl.innerHTML='<small style="color:#999;">FCMãã¼ã¯ã³æªåå¾ã®ãã確èªã§ãã¾ãã</small>';return;} 5if(typeof n2pnConfig==='undefined'){statusEl.innerHTML='<small style="color:#999;">è¨å®æªèªã¿è¾¼ã¿</small>';return;} 6try{var params=new URLSearchParams();params.append('action','n2pn_check_fcm_subscriptions');params.append('token',fcmToken);params.append('nonce',n2pnConfig.nonce);var res=await fetch(n2pnConfig.ajaxUrl,{method:'POST',headers:{'Content-Type':'application/x-www-form-urlencoded'},body:params});var data=await res.json();if(!data.success){var msg=(data.data&&data.data.message)?data.data.message:'䏿ãªã¨ã©ã¼';var extra='';if(data.data&&data.data.token_head){extra+='<br><small style="color:#999;">token: '+escapeHtml(data.data.token_head)+' ('+data.data.token_len+'æå)</small>';} 7statusEl.innerHTML='<small style="color:#f44336;">確èªã¨ã©ã¼: '+escapeHtml(msg)+'</small>'+extra;if(/InvalidToken/i.test(msg)){var actionsEl=document.getElementById('n2pn-fcm-actions');var diffEl=document.getElementById('n2pn-fcm-diff');if(diffEl){diffEl.style.display='block';diffEl.innerHTML='<p style="margin:8px 0;">ä¿åããã¦ããFCMãã¼ã¯ã³ã失å¹ãã¦ãã¾ãã<br>æ°ãããã¼ã¯ã³ãçºè¡ãã¦å ¨ãããã¯ã«åç»é²ãã¾ãã</p>';} 8if(actionsEl){actionsEl.style.display='block';var btn=document.getElementById('n2pn-fcm-repair-btn');btn.textContent='ãã¼ã¯ã³ãåçºè¡ãã¦ç»é²ãç´ã';btn.dataset.mode='refresh-token';delete btn.dataset.missing;}} 9return;} 10var actualTopics=data.data.actual_topics||[];window.__n2pnFcmActual=actualTopics;renderStatus(actualTopics);markCheckboxes(actualTopics);}catch(err){console.error('FCMç¶æ 確èªã¨ã©ã¼:',err);statusEl.innerHTML='<small style="color:#f44336;">確èªå¤±æ: '+escapeHtml(err.message)+'</small>';}} 11function getSelectedTopics(){return Array.prototype.map.call(document.querySelectorAll('input[name="topics[]"]:checked'),function(cb){return cb.value;});} 12function getLabelMap(){var map={};document.querySelectorAll('input[name="topics[]"]').forEach(function(cb){var span=cb.parentElement.querySelector('span');if(span)map[cb.value]=span.textContent.trim();});return map;}
13function renderStatus(actualTopics){var statusEl=document.getElementById('n2pn-fcm-status-text');var diffEl=document.getElementById('n2pn-fcm-diff');var actionsEl=document.getElementById('n2pn-fcm-actions');var repairBtn=document.getElementById('n2pn-fcm-repair-btn');var card=document.getElementById('n2pn-fcm-status-card');var selected=getSelectedTopics();var missing=selected.filter(function(t){return actualTopics.indexOf(t)===-1;});if(missing.length===0){statusEl.innerHTML='<strong style="color:#4CAF50;">â ãã¹ã¦ã®ãããã¯ãæ£å¸¸ã«ç»é²ããã¦ãã¾ã</strong> <small>('+actualTopics.length+'ä»¶)</small>';diffEl.style.display='none';actionsEl.style.display='none';if(card)card.style.borderLeftColor='#4CAF50';return;} 14if(card)card.style.borderLeftColor='#FF9800';statusEl.innerHTML='<strong style="color:#FF9800;">â '+missing.length+'ä»¶ã®ãããã¯ãFCMã«æªç»é²ã§ã</strong>';var labelMap=getLabelMap();var missingLabels=missing.map(function(t){return escapeHtml(labelMap[t]||t);});diffEl.style.display='block';diffEl.innerHTML='<strong>æªç»é²ã®ãããã¯:</strong><br>'+missingLabels.join('ã');actionsEl.style.display='block';repairBtn.dataset.missing=JSON.stringify(missing);} 15function markCheckboxes(actualTopics){document.querySelectorAll('input[name="topics[]"]').forEach(function(cb){var label=cb.closest('.n2pn-checkbox-item');
15if(!label)return;var existing=label.querySelector('.n2pn-fcm-mark');if(existing)existing.remove();if(!cb.checked)return;var mark=document.createElement('small');mark.className='n2pn-fcm-mark';mark.style.marginLeft='auto';mark.style.paddingLeft='8px';mark.style.fontSize='14px';mark.style.fontWeight='bold';if(actualTopics.indexOf(cb.value)!==-1){mark.innerHTML='<span style="color:#4CAF50;">â</span>';mark.title='FCMã«ç»é²æ¸ã¿';}else{mark.innerHTML='<span style="color:#f44336;">â</span>';mark.title='FCMã«æªç»é²';} 16label.appendChild(mark);});} 17async function handleRepair(e){var btn=e.currentTarget;var mode=btn.dataset.mode||'missing';if(!window.n2pnPush){alert('éç¥ãµã¼ãã¹ãåæåããã¦ãã¾ãããéç¥ã許å¯ãã¦ããã試ããã ããã');return;} 18if(mode==='refresh-token'){var originalText=btn.textContent;btn.disabled=true;btn.textContent='ãã¼ã¯ã³åçºè¡ä¸...';try{localStorage.removeItem('n2pn_fcm_token');if(typeof window.n2pnPush.requestPermission==='function'){await window.n2pnPush.requestPermission();} 19var allSelected=getSelectedTopics();if(allSelected.length>0&&typeof window.n2pnPush.subscribe==='function'){btn.textContent='ç»é²ä¸('+allSelected.length+'ä»¶)...';await window.n2pnPush.subscribe(allSelected);localStorage.setItem('n2pn_subscribed_topics',JSON.stringify(allSelected));} 20btn.textContent='â åç»é²å®äºã確èªä¸...';setTimeout(function(){checkFcmSubscriptions();btn.disabled=false;btn.textContent=originalText;btn.dataset.mode='missing';},1500);}catch(err){console.error('ãã¼ã¯ã³åçºè¡ã¨ã©ã¼:',err);alert('ãã¼ã¯ã³ã®åçºè¡ã«å¤±æãã¾ãã: '+err.message);btn.disabled=false;btn.textContent=originalText;} 21return;} 22var missing;try{missing=JSON.parse(btn.dataset.missing||'[]');}catch(_){missing=[];} 23if(missing.length===0)return;if(typeof window.n2pnPush.subscribe!=='function'){alert('éç¥ãµã¼ãã¹ãåæåããã¦ãã¾ããã');return;} 24var originalText=btn.textContent;btn.disabled=true;btn.textContent='ç»é²ä¸('+missing.length+'ä»¶)...';try{await window.n2pnPush.subscribe(missing);var current=[];try{current=JSON.parse(localStorage.getItem('n2pn_subscribed_topics')||'[]');}catch(_){current=[];} 25var merged=current.slice();missing.forEach(function(t){if(merged.indexOf(t)===-1)merged.push(t);});localStorage.setItem('n2pn_subscribed_topics',JSON.stringify(merged));btn.textContent='â ç»é²å®äºãå確èªä¸...';setTimeout(function(){checkFcmSubscriptions();btn.disabled=false;btn.textContent=originalText;},1500);}catch(err){console.error('修復ã¨ã©ã¼:',err);alert('åç»é²ã«å¤±æãã¾ãã: '+err.message);btn.disabled=false;btn.textContent=originalText;}} 26function escapeHtml(str){return String(str).replace(/[&<>"']/g,function(m){return({'&':'&','<':'<','>':'>','"':'"',"'":'''})[m];});}})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.