-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject-links-v106.js
More file actions
65 lines (59 loc) · 2.63 KB
/
Copy pathproject-links-v106.js
File metadata and controls
65 lines (59 loc) · 2.63 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
(() => {
'use strict';
if(location.hostname!=='chatgpt.com'||window.__NIAKGPT_PROJECT_LINKS_106__)return;
window.__NIAKGPT_PROJECT_LINKS_106__=true;
let observer=null,box=null,timer=0,suspended=false;
const clean=v=>String(v||'').replace(/\s+/g,' ').trim();
function ensureProjectsHome(){
const pins=document.getElementById('ng8-pins');
const head=pins?.querySelector(':scope > .ng8-pin-head');
if(!head)return false;
let link=head.querySelector(':scope > a.ng106-projects-home');
if(link){
if(link.getAttribute('href')!=='/projects')link.setAttribute('href','/projects');
return true;
}
const label=[...head.children].find(el=>/^(projects?|projets?)$/i.test(clean(el.textContent)));
if(!label)return false;
link=document.createElement('a');
link.className='ng106-projects-home';
link.href='/projects';
link.textContent='PROJECTS';
link.title='Ouvrir tous les Projects ChatGPT';
link.setAttribute('aria-label','Ouvrir tous les Projects ChatGPT');
label.replaceWith(link);
return true;
}
function verifyDrawerLinks(){
const pins=document.getElementById('ng8-pins');if(!pins)return;
for(const link of pins.querySelectorAll('.ng96-folder-list > a[data-chat]')){
const pid=link.closest('.ng96-pin-drawer')?.dataset.pid||'';
const cid=link.dataset.chat||'';
if(pid&&cid&&!/\/c\//.test(link.getAttribute('href')||''))link.setAttribute('href',`/g/${pid}/c/${cid}`);
}
}
function repair(){if(suspended)return;ensureProjectsHome();verifyDrawerLinks();}
function schedule(delay=16){if(suspended)return;clearTimeout(timer);timer=setTimeout(()=>{timer=0;repair();},delay);}
function bind(){
const next=document.getElementById('ng8-pins');
if(!next||next===box)return;
observer?.disconnect();box=next;
observer=new MutationObserver(()=>schedule(12));
observer.observe(box,{childList:true,subtree:true});
schedule(0);
}
function start(){
suspended=false;bind();
if(!box){
const boot=new MutationObserver(()=>{bind();if(box)boot.disconnect();});
boot.observe(document.documentElement,{childList:true,subtree:true});
setTimeout(()=>boot.disconnect(),15000);
}
schedule(0);
}
function stop(){suspended=true;clearTimeout(timer);timer=0;observer?.disconnect();observer=null;box=null;}
document.addEventListener('niakgpt:pins-rendered',()=>{bind();schedule(0);});
window.addEventListener('pagehide',stop);
window.addEventListener('pageshow',event=>{if(event.persisted)start();});
if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',start,{once:true});else start();
})();