Skip to content

Instantly share code, notes, and snippets.

@JavaGT
Created August 17, 2026 22:08
Show Gist options
  • Select an option

  • Save JavaGT/b874fc998e76d0206924f04ad8ae4c0d to your computer and use it in GitHub Desktop.

Select an option

Save JavaGT/b874fc998e76d0206924f04ad8ae4c0d to your computer and use it in GitHub Desktop.
TVNZ Session Exporter bookmarklet (updated for current tvnz.co.nz storage scheme)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>TVNZ Session Exporter (updated)</title>
<style>
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
max-width: 720px; margin: 40px auto; padding: 0 20px; line-height: 1.6; }
.bookmarklet { display: inline-block; padding: 14px 28px; background: #1a73e8; color: #fff;
text-decoration: none; border-radius: 8px; font-weight: 600; font-size: 1.2em; cursor: grab; }
.bookmarklet:hover { background: #1557b0; }
.note { background: #fff3cd; border: 1px solid #ffc107; padding: 12px 16px; border-radius: 6px; }
pre { background: #f5f5f5; padding: 16px; border-radius: 6px; overflow-x: auto; font-size: 0.85em; }
code { background: #f0f0f0; padding: 2px 6px; border-radius: 3px; font-size: 0.9em; word-break: break-all; }
</style>
</head>
<body>
<h1>TVNZ Session Exporter (updated)</h1>
<div class="note"><strong>How to use:</strong> drag the button below to your bookmarks bar,
log in at <code>www.tvnz.co.nz</code>, then click the bookmark. It downloads
<code>local_storage.json</code>. If it can't find tokens it will pop a diagnostic listing
of the storage keys on the current page — send that list along and the bookmarklet can be
adjusted. Everything runs in your browser; nothing is sent anywhere.</div>
<p><a class="bookmarklet" id="dragme" href="javascript:(()=>{const p=(s)=>{const o={};for(const k of ['accessToken','refreshToken','deviceref'])if(s.getItem(k))o[k]=s.getItem(k);for(let i=0;i<s.length;i++){const k=s.key(i),v=s.getItem(k);if(!v||v.length>500000)continue;try{const j=JSON.parse(v);if(j&&typeof j==='object'){if(!o.accessToken&&j.accessToken)o.accessToken=j.accessToken;if(!o.refreshToken&&j.refreshToken)o.refreshToken=j.refreshToken;if(!o.deviceref&&(j.deviceref||j.deviceRef))o.deviceref=j.deviceref||j.deviceRef;}}catch(e){}}return o;};const dump=(s)=>{const a=[];for(let i=0;i<s.length;i++){const k=s.key(i),v=s.getItem(k)||'';a.push(k+' => '+(v.length>60?v.length+' chars':v));}return a;};let o=p(localStorage);if(!o.accessToken){try{const so=p(sessionStorage);if(so.accessToken&&!o.accessToken)o.accessToken=so.accessToken;if(so.refreshToken&&!o.refreshToken)o.refreshToken=so.refreshToken;if(so.deviceref&&!o.deviceref)o.deviceref=so.deviceref;}catch(e){}}if(!o.accessToken){const msg=['localStorage:',' '+dump(localStorage).join('\n '),'sessionStorage:',' '+dump(sessionStorage).join('\n ')].join('\n');console.log(msg);alert('No TVNZ accessToken found on this page.\nCopy the list from the browser console (F12) and share it.\n\n'+msg);return;}const a=document.createElement('a');a.href='data:application/json,'+encodeURIComponent(JSON.stringify(o,null,2));a.download='local_storage.json';document.body.appendChild(a);a.click();document.body.removeChild(a);console.log('TVNZ session exported keys:',Object.keys(o));})();">📥 Export TVNZ Session</a></p>
<h2>Usage</h2>
<ol>
<li>Drag the button above to your browser's bookmarks bar.</li>
<li>Go to <a href="https://www.tvnz.co.nz" target="_blank">www.tvnz.co.nz</a> and log in.</li>
<li>Click the bookmarklet. A file <code>local_storage.json</code> downloads.</li>
<li>If a "No TVNZ accessToken found" dialog appears, copy the console list (F12) and share it.</li>
</ol>
<h2>Manual fallback</h2>
<p>Open DevTools (F12) → Console on tvnz.co.nz and paste:</p>
<pre>(()=>{const keys=[];for(let i=0;i&lt;localStorage.length;i++){const k=localStorage.key(i);const v=localStorage.getItem(k)||'';keys.push(k+' =&gt; '+(v.length&gt;60?v.length+' chars':v));}console.log(keys.join('\n'));})();</pre>
<p>Send the output if the bookmarklet can't find the session.</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment