-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject-chat-ux-v110.js
More file actions
35 lines (34 loc) · 3.7 KB
/
Copy pathproject-chat-ux-v110.js
File metadata and controls
35 lines (34 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
(() => {
'use strict';
if(location.hostname!=='chatgpt.com'||window.__NIAKGPT_PROJECT_CHAT_UX_110__)return;
window.__NIAKGPT_PROJECT_CHAT_UX_110__=true;
const OUT_KEY='niakgpt-continuity-v100';
let observer=null,boxNode=null,bootstrapObserver=null,timer=0,stopped=false,outState={out:{}},revealedCid='';
const cid=h=>String(h||'').match(/\/c\/([A-Za-z0-9_-]+)/)?.[1]||'';
const currentCid=()=>cid(location.pathname);
function revealActive(link,chatId){
if(!chatId||revealedCid===chatId||!(link instanceof HTMLElement))return;
const list=link.closest('.ng96-folder-list');if(!list)return;
const lr=list.getBoundingClientRect(),rr=link.getBoundingClientRect();
if(rr.top<lr.top||rr.bottom>lr.bottom)link.scrollIntoView({block:'nearest',inline:'nearest'});
revealedCid=chatId;
}
function decorateLink(link){
if(!(link instanceof HTMLElement))return;const chatId=link.dataset.chat||cid(link.getAttribute('href'));if(!chatId)return;
const row=link.closest('.ng96-chat-entry');
link.dataset.ng110Chat='1';const titleEl=link.querySelector(':scope>span,.ng96-chat-title,span');if(titleEl)titleEl.classList.add('ng110-chat-title');
const active=chatId===currentCid(),out=!!outState?.out?.[chatId];
if(active){link.dataset.ng110Active='1';link.setAttribute('aria-current','page');}else{delete link.dataset.ng110Active;link.removeAttribute('aria-current');}
if(out)link.dataset.ng110Out='1';else delete link.dataset.ng110Out;
if(row){row.dataset.ng110ChatRow='1';if(active)row.dataset.ng110Active='1';else delete row.dataset.ng110Active;if(out)row.dataset.ng110Out='1';else delete row.dataset.ng110Out;}
if(active)requestAnimationFrame(()=>revealActive(link,chatId));
}
function render(){timer=0;if(stopped)return;const box=document.getElementById('ng8-pins');if(!box)return;for(const link of box.querySelectorAll('.ng96-folder-list a[data-chat]'))decorateLink(link);}
function schedule(delay=18){if(stopped)return;clearTimeout(timer);timer=setTimeout(render,delay);}
function bind(){const box=document.getElementById('ng8-pins');if(!box)return false;if(box===boxNode)return true;observer?.disconnect();boxNode=box;observer=new MutationObserver(()=>schedule(10));observer.observe(box,{childList:true,subtree:true});schedule(0);return true;}
function start(){stopped=false;if(bind())return;bootstrapObserver?.disconnect();bootstrapObserver=new MutationObserver(()=>{if(bind()){bootstrapObserver?.disconnect();bootstrapObserver=null;}});bootstrapObserver.observe(document.documentElement,{childList:true,subtree:true});setTimeout(()=>{bootstrapObserver?.disconnect();bootstrapObserver=null;},15000);}
function stop(){stopped=true;clearTimeout(timer);observer?.disconnect();bootstrapObserver?.disconnect();observer=bootstrapObserver=null;boxNode=null;revealedCid='';}
function onRoute(){revealedCid='';bind();schedule(0);}
try{chrome.storage.local.get(OUT_KEY).then(g=>{outState=g?.[OUT_KEY]||outState;schedule(0);}).catch(()=>{});chrome.storage.onChanged.addListener((changes,area)=>{if(area==='local'&&changes[OUT_KEY]){outState=changes[OUT_KEY].newValue||{out:{}};schedule(0);}});}catch{}
document.addEventListener('niakgpt:pins-rendered',()=>{bind();schedule(0);});document.addEventListener('niakgpt:folder-rendered',()=>schedule(0));document.addEventListener('visibilitychange',()=>{if(!document.hidden)onRoute();});window.addEventListener('popstate',onRoute);if(window.navigation?.addEventListener)window.navigation.addEventListener('navigatesuccess',onRoute);window.addEventListener('pagehide',stop);window.addEventListener('pageshow',e=>{if(e.persisted){revealedCid='';start();}});if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',start,{once:true});else start();
})();