javascript:(async%20()%20%3D%3E%20%7B%20const%20API%20%3D%20'https%3A%2F%2Fapi.clay.com'%3B%20const%20MAX_RECORDS%20%3D%20500%3B%20const%20BATCH%20%3D%2050%3B%20const%20path%20%3D%20location.pathname%3B%20const%20tableId%20%3D%20(path.match(%2F%5C%2Ftables%5C%2F(t_%5BA-Za-z0-9%5D%2B)%2F)%20%7C%7C%20%5B%5D)%5B1%5D%3B%20let%20viewId%20%3D%20(path.match(%2F%5C%2Fviews%5C%2F(gv_%5BA-Za-z0-9%5D%2B)%2F)%20%7C%7C%20%5B%5D)%5B1%5D%3B%20if%20(!tableId)%20%7B%20alert('Clay%20extract%3A%20no%20table%20id%20in%20URL.%20Open%20a%20%2Ftables%2Ft_...%20page%20first.')%3B%20return%3B%20%7D%20const%20toast%20%3D%20(msg)%20%3D%3E%20%7B%20let%20el%20%3D%20document.getElementById('__clay_extract_toast')%3B%20if%20(!el)%20%7B%20el%20%3D%20document.createElement('div')%3B%20el.id%20%3D%20'__clay_extract_toast'%3B%20el.style.cssText%20%3D%20'position%3Afixed%3Bz-index%3A2147483647%3Bbottom%3A20px%3Bright%3A20px%3Bbackground%3A%23111%3Bcolor%3A%23fff%3B'%20%2B%20'font%3A13px%2F1.4%20-apple-system%2Csystem-ui%2Csans-serif%3Bpadding%3A10px%2014px%3Bborder-radius%3A8px%3B'%20%2B%20'box-shadow%3A0%204px%2016px%20rgba(0%2C0%2C0%2C.3)%3Bmax-width%3A320px'%3B%20document.body.appendChild(el)%3B%20%7D%20el.textContent%20%3D%20'Clay%20extract%3A%20'%20%2B%20msg%3B%20return%20el%3B%20%7D%3B%20const%20getJSON%20%3D%20async%20(url%2C%20opts)%20%3D%3E%20%7B%20const%20r%20%3D%20await%20fetch(url%2C%20%7B%20credentials%3A%20'include'%2C%20headers%3A%20%7B%20accept%3A%20'application%2Fjson%2C%20text%2Fplain%2C%20*%2F*'%2C%20...(opts%20%26%26%20opts.headers)%20%7D%2C%20...opts%2C%20%7D)%3B%20if%20(!r.ok)%20throw%20new%20Error(url.replace(API%2C%20'')%20%2B%20'%20%E2%86%92%20'%20%2B%20r.status)%3B%20return%20r.json()%3B%20%7D%3B%20try%20%7B%20toast('fetching%20table%20config%E2%80%A6')%3B%20const%20table%20%3D%20await%20getJSON(API%20%2B%20'%2Fv3%2Ftables%2F'%20%2B%20tableId)%3B%20viewId%20%3D%20viewId%20%7C%7C%20table%3F.table%3F.firstViewId%20%7C%7C%20table%3F.firstViewId%3B%20if%20(!viewId)%20throw%20new%20Error('could%20not%20resolve%20a%20view%20id%20(firstViewId%20missing)')%3B%20toast('fetching%20schema%20%2B%20sample%20records%E2%80%A6')%3B%20let%20schemaTree%20%3D%20null%3B%20let%20exampleRecords%20%3D%20%5B%5D%3B%20try%20%7B%20const%20sv2%20%3D%20await%20getJSON(%20API%20%2B%20'%2Fv3%2Ftables%2F'%20%2B%20tableId%20%2B%20'%2Fviews%2F'%20%2B%20viewId%20%2B%20'%2Ftable-schema-v2'%2C%20)%3B%20schemaTree%20%3D%20sv2%3F.tableSchema%20%7C%7C%20sv2%20%7C%7C%20null%3B%20exampleRecords%20%3D%20sv2%3F.exampleRecords%20%7C%7C%20sv2%3F.records%20%7C%7C%20sv2%3F.sampleRecords%20%7C%7C%20%5B%5D%3B%20%7D%20catch%20(e)%20%7B%20console.warn('%5Bclay-extract%5D%20table-schema-v2%20failed%3A'%2C%20e.message)%3B%20%7D%20let%20totalRecordCount%20%3D%20null%3B%20try%20%7B%20const%20cnt%20%3D%20await%20getJSON(API%20%2B%20'%2Fv3%2Ftables%2F'%20%2B%20tableId%20%2B%20'%2Fcount')%3B%20totalRecordCount%20%3D%20cnt%3F.tableTotalRecordsCount%20%3F%3F%20cnt%3F.count%20%3F%3F%20null%3B%20%7D%20catch%20(e)%20%7B%20console.warn('%5Bclay-extract%5D%20count%20failed%3A'%2C%20e.message)%3B%20%7D%20toast('fetching%20record%20ids%E2%80%A6')%3B%20let%20recordIds%20%3D%20%5B%5D%3B%20try%20%7B%20const%20ids%20%3D%20await%20getJSON(%20API%20%2B%20'%2Fv3%2Ftables%2F'%20%2B%20tableId%20%2B%20'%2Fviews%2F'%20%2B%20viewId%20%2B%20'%2Frecords%2Fids'%2C%20)%3B%20recordIds%20%3D%20ids%3F.results%20%7C%7C%20ids%3F.recordIds%20%7C%7C%20ids%3F.ids%20%7C%7C%20(Array.isArray(ids)%20%3F%20ids%20%3A%20%5B%5D)%3B%20%7D%20catch%20(e)%20%7B%20console.warn('%5Bclay-extract%5D%20records%2Fids%20failed%3A'%2C%20e.message)%3B%20%7D%20const%20truncated%20%3D%20recordIds.length%20%3E%20MAX_RECORDS%3B%20const%20idsToFetch%20%3D%20recordIds.slice(0%2C%20MAX_RECORDS)%3B%20const%20bulkFetchRecords%20%3D%20%5B%5D%3B%20for%20(let%20i%20%3D%200%3B%20i%20%3C%20idsToFetch.length%3B%20i%20%2B%3D%20BATCH)%20%7B%20const%20chunk%20%3D%20idsToFetch.slice(i%2C%20i%20%2B%20BATCH)%3B%20toast('records%20'%20%2B%20(i%20%2B%20chunk.length)%20%2B%20'%2F'%20%2B%20idsToFetch.length%20%2B%20'%E2%80%A6')%3B%20try%20%7B%20const%20res%20%3D%20await%20getJSON(API%20%2B%20'%2Fv3%2Ftables%2F'%20%2B%20tableId%20%2B%20'%2Fbulk-fetch-records'%2C%20%7B%20method%3A%20'POST'%2C%20headers%3A%20%7B%20'content-type'%3A%20'application%2Fjson'%20%7D%2C%20body%3A%20JSON.stringify(%7B%20recordIds%3A%20chunk%2C%20includeExternalContentFieldIds%3A%20%5B%5D%20%7D)%2C%20%7D)%3B%20if%20(res%3F.results)%20bulkFetchRecords.push(...res.results)%3B%20%7D%20catch%20(e)%20%7B%20console.warn('%5Bclay-extract%5D%20bulk-fetch%20batch%20failed%3A'%2C%20e.message)%3B%20%7D%20%7D%20if%20(truncated)%20%7B%20console.warn(%20'%5Bclay-extract%5D%20record%20pull%20capped%20at%20MAX_RECORDS%3D'%20%2B%20MAX_RECORDS%20%2B%20'%20of%20'%20%2B%20recordIds.length%20%2B%20'%20total.%20Raise%20MAX_RECORDS%20to%20pull%20all.'%2C%20)%3B%20%7D%20const%20extract%20%3D%20%7B%20_meta%3A%20%7B%20extractedAt%3A%20new%20Date().toISOString()%2C%20method%3A%20'bookmarklet'%2C%20tableId%2C%20viewId%2C%20url%3A%20location.href%2C%20totalRecordCount%2C%20idCount%3A%20recordIds.length%2C%20fetchedRecordCount%3A%20bulkFetchRecords.length%2C%20exampleRecordCount%3A%20exampleRecords.length%2C%20truncated%2C%20%7D%2C%20table%3A%20table%3F.table%20%7C%7C%20table%2C%20fields%3A%20table%3F.fields%20%7C%7C%20table%3F.table%3F.fields%20%7C%7C%20%5B%5D%2C%20tableSchema%3A%20schemaTree%2C%20exampleRecords%2C%20recordIds%2C%20bulkFetchRecords%2C%20%7D%3B%20const%20name%20%3D%20(extract.table%3F.name%20%7C%7C%20tableId).replace(%2F%5B%5EA-Za-z0-9_-%5D%2B%2Fg%2C%20'_').slice(0%2C%2060)%3B%20const%20blob%20%3D%20new%20Blob(%5BJSON.stringify(extract%2C%20null%2C%202)%5D%2C%20%7B%20type%3A%20'application%2Fjson'%20%7D)%3B%20const%20a%20%3D%20document.createElement('a')%3B%20a.href%20%3D%20URL.createObjectURL(blob)%3B%20a.download%20%3D%20'clay_extract_'%20%2B%20name%20%2B%20'.json'%3B%20document.body.appendChild(a)%3B%20a.click()%3B%20a.remove()%3B%20setTimeout(()%20%3D%3E%20URL.revokeObjectURL(a.href)%2C%204000)%3B%20window.__clayExtract%20%3D%20extract%3B%20toast(%20'done%3A%20'%20%2B%20(extract.fields%3F.length%20%7C%7C%200)%20%2B%20'%20fields%2C%20'%20%2B%20exampleRecords.length%20%2B%20'%20sample%20rows%2C%20'%20%2B%20bulkFetchRecords.length%20%2B%20'%2F'%20%2B%20(totalRecordCount%20%3F%3F%20recordIds.length)%20%2B%20'%20records'%20%2B%20(truncated%20%3F%20'%20(CAPPED)'%20%3A%20'')%20%2B%20'.%20Downloaded%20JSON.'%2C%20)%3B%20setTimeout(()%20%3D%3E%20document.getElementById('__clay_extract_toast')%3F.remove()%2C%206000)%3B%20%7D%20catch%20(err)%20%7B%20console.error('%5Bclay-extract%5D'%2C%20err)%3B%20toast('ERROR%3A%20'%20%2B%20err.message%20%2B%20'%20(see%20console)')%3B%20%7D%20%7D)()%3B
