Skip to content

Instantly share code, notes, and snippets.

@hitamu
Last active May 6, 2025 13:21
Show Gist options
  • Save hitamu/c2606f38f18c1d2d7e0da0b6226a382e to your computer and use it in GitHub Desktop.
Save hitamu/c2606f38f18c1d2d7e0da0b6226a382e to your computer and use it in GitHub Desktop.
Search Saved Post on LinkedIn
javascript:(async()=>{const s=ms=>new Promise(r=>setTimeout(r,ms));const a=async()=>{let p=0,a=0;while(a<10){window.scrollTo(0,document.body.scrollHeight);await s(2000);const c=document.body.scrollHeight;c===p?a++:(a=0,p=c)}};const t=(t,e)=>{const n=t.split(/\s+/);return n.length<=e?t:n.slice(0,e).join(" ")+"..."};const e=()=>{const p=[];document.querySelectorAll("[data-chameleon-result-urn]").forEach(e=>{const u=e.getAttribute("data-chameleon-result-urn"),r=`https://www.linkedin.com/feed/update/${u}`,c=e.querySelector(".entity-result__content-summary"),t=c?.innerText?.trim(),l=e.querySelector(".entity-result__content-actor"),a=l?.innerText?.trim().split("\n")[0],n=e.querySelector(".entity-result__content-actor a"),o=n?.href||"#";t&&a&&p.push({a,u:o,c:t,l:r})});return p};const o=p=>{const e=JSON.parse(localStorage.getItem("li_p")||"[]"),c=[...e,...p],u=Array.from(new Map(c.map(p=>[p.l,p])).values());localStorage.setItem("li_p",JSON.stringify(u));return u};const f=(p,s)=>s?p.filter(p=>p.c.toLowerCase().includes(s.toLowerCase())||p.a.toLowerCase().includes(s.toLowerCase())):p;const n=p=>{document.getElementById("li-p")?.remove();const s=document.createElement("style");s.innerHTML=`#li-p{position:fixed;top:10px;right:10px;width:480px;max-height:90vh;overflow-y:auto;background:white;border:1px solid #ccc;padding:16px;box-shadow:0 4px 20px rgba(0,0,0,0.2);z-index:9999;font-family:Arial,sans-serif;border-radius:8px}#li-p h2{margin:0 0 10px;font-size:18px}#li-p input{width:100%;padding:6px;margin-bottom:10px;border:1px solid #ccc;border-radius:4px}#li-p button{margin-right:10px;padding:6px 12px;border:none;border-radius:4px;background:#0073b1;color:white;cursor:pointer}#li-p button:hover{background:#005983}.p-i{border-top:1px solid #eee;padding:10px 0;position:relative}.p-i a{color:#0073b1;text-decoration:none}.p-i p{margin:4px 0}.p-a{font-weight:bold;margin-bottom:4px}.p-l{position:absolute;top:10px;right:0;color:#0073b1;font-size:18px;cursor:pointer}.l{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);font-size:18px;color:#0073b1}`;document.head.appendChild(s);const u=document.createElement("div");u.id="li-p";const d=document.createElement("h2");d.innerText="LinkedIn Posts";u.appendChild(d);const i=document.createElement("input");i.type="text";i.placeholder="Search by author or post text...";u.appendChild(i);const b=document.createElement("div"),c=document.createElement("button");c.innerText="Clear";c.onclick=()=>{localStorage.removeItem("li_p");alert("Cache cleared");document.getElementById("li-p")?.remove()};b.appendChild(c);const x=document.createElement("button");x.innerText="Export CSV";x.onclick=()=>{const e="data:text/csv;charset=utf-8,"+encodeURI("Author,Content,URL\n"+p.map(p=>`"${p.a.replace(/"/g,'""')}","${p.c.replace(/"/g,'""')}","${p.l}"`).join("\n")),l=document.createElement("a");l.setAttribute("href",e);l.setAttribute("download","linkedin_posts.csv");document.body.appendChild(l);l.click();document.body.removeChild(l)};b.appendChild(x);u.appendChild(b);const l=document.createElement("div");u.appendChild(l);const h=document.createElement("div");h.className="l";h.innerText="Loading posts...";u.appendChild(h);const r=e=>{h.style.display="none";l.innerHTML="";e.forEach(e=>{const p=document.createElement("div");p.className="p-i";const s=document.createElement("div");s.className="p-a";const u=document.createElement("a");u.href=e.u;u.target="_blank";u.innerText=e.a;s.appendChild(u);const d=document.createElement("p");d.innerText=t(e.c,100);const i=document.createElement("a");i.href=e.l;i.target="_blank";i.className="p-l";i.innerHTML="&#128279;";i.title="View post";p.appendChild(s);p.appendChild(d);p.appendChild(i);l.appendChild(p)})};i.oninput=()=>{const t=f(p,i.value);r(t)};r(p);document.body.appendChild(u)};await a();const p=e(),d=o(p);n(d)})();
@hitamu
Copy link
Author

hitamu commented May 6, 2025

  1. Copy content of script.js
  2. Right click on Bookmark Bar
  3. Choose Add Page
  4. Input Name: Searchable Saved Posts, URL: paste the copied script content
  5. Go to https://www.linkedin.com/my-items/saved-posts/ then click to Searchable Saved Posts on Bookmark Bar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment