-
Notifications
You must be signed in to change notification settings - Fork 4
/
watchapedia_export.js
1 lines (1 loc) · 2.74 KB
/
watchapedia_export.js
1
!async function(){const e=document.querySelector('a[href*="/users/"]').href.replace(/^.*\/users\/(.*)$/,"$1"),t=async e=>fetch(`https://api-pedia.watcha.com${e}`,{credentials:"same-origin",headers:{"x-watcha-client":"watcha-WebApp","x-watcha-client-language":"ko","x-watcha-client-region":"KR","x-watcha-client-version":"2.1.0"}}).then((e=>e.json())).then((e=>e.result)),n=e=>{const t=e.content.code,n=`https://pedia.watcha.com/ko-KR/contents/${t}`,a=e.content.title.replace(/"/g,""),i="tv_seasons"===e.content.content_type?"TV":"MOVIE",c=e.content.year,s=e.content.director_names?.join(),r=e.user_content_action.watched_at||e.created_at,o=+e.user_content_action.rating/2,l=e.text?.trim().replace(/"/g,'""');return{id:t,url:n,title:a,type:i,year:c,directors:s,watchedAt:r,rating:o,review:l,spoiler:e.spoiler}},a=async(e,a)=>{let i=await t(e);const c=[];i.result.forEach((e=>{c.push(n(e))}));let s=i.next_uri;for(;s;)i=await t(s),i.result.forEach((e=>{c.push(n(e))})),a&&a(i.result.length),s=i.next_uri;return c},i=async(t,n)=>{let i=0;const c=e=>{i+=e,n&&n(i)},s=await a(`/api/users/${e}/contents/${t}/ratings`,c),r=await a(`/api/users/${e}/contents/${t}/comments`,c);return s.map((e=>{const t=r.find((t=>t.id===e.id));let n=t?.watchedAt||e.watchedAt;if(n){const e=new Date(n);n=`${e.getFullYear()}-${`0${e.getMonth()+1}`.slice(-2)}-${`0${e.getDate()}`.slice(-2)}`}return[e.id,e.url,e.title,e.type,e.year,t?.directors||e.directors,n,e.rating,t?.review,t?.spoiler]}))};await(async()=>{const{setProgress:n,destroy:a}=(()=>{const e=Object.assign(document.createElement("div"),{style:"position: fixed; left: 0; top: 0; right: 0;height: 59px; z-index:60;display:flex; align-items: center; background-color:#fff"}),t=Object.assign(document.createElement("div"),{style:"max-width:1320px;width:100%;height:100%;margin:0 auto;display:flex; align-items: center;padding:0 32px;"}),n=Object.assign(document.createElement("p"),{style:"color: #7e7e7e; font-size: 15px; letter-spacing: -0.3px;"});n.innerText="리뷰 다운로드 중입니다.";const a=Object.assign(document.createElement("span"),{style:"font-weight: bold"});return n.appendChild(a),t.appendChild(n),e.appendChild(t),document.body.appendChild(e),{setProgress(e){a.innerText=`${e.toFixed(0)}%`},destroy(){e.remove()}}})();try{const a=await(async()=>(await t(`/api/users/${e}`)).ratings_count)(),c=(e=0)=>{a&&e&&n(e/a*100)},s=await i("movies",c),r=await i("tv_seasons",c);let o=s.map((e=>`"${e.join('","')}"`)).join("\n");o+="\n",o+=r.map((e=>`"${e.join('","')}"`)).join("\n"),((e,t)=>{const n=new window.Blob(["\ufeff"+t],{type:"text/csv;charset=utf-8;"}),a=document.createElement("a");a.href=URL.createObjectURL(n),a.download=e,a.click()})(`${e}-watcha.csv`,`ID,URL,Title,Type,Year,Directors,WatchedAt,Rating,Review,Spoiler,\n${o}`)}catch(e){}a()})()}();