chrome.alarms.onAlarm.addListener(async(alarm)=>{if(!alarm.name.startsWith('monitor_'))return;const url=alarm.name.replace('monitor_','');try{const r=await fetch(url);const text=await r.text();const hash=Array.from(new Uint8Array(await crypto.subtle.digest('SHA-256',new TextEncoder().encode(text)))).map(b=>b.toString(16).padStart(2,'0')).join('');chrome.storage.local.get(['monitors'],d=>{const m=d.monitors||{};if(m[url]&&m[url].hash&&m[url].hash!==hash){chrome.notifications.create('change_'+Date.now(),{type:'basic',iconUrl:'icons/icon128.png',title:'Page Changed!',message:url.slice(0,50)+'...'});m[url].changed=true;m[url].lastChange=Date.now();}m[url].hash=hash;m[url].lastCheck=Date.now();chrome.storage.local.set({monitors:m});});}catch(e){console.error('Monitor error:',e);}});
