2 lines
13 KiB
JavaScript
2 lines
13 KiB
JavaScript
var app=function(){"use strict";function t(){}function e(t){return t()}function n(){return Object.create(null)}function r(t){t.forEach(e)}function o(t){return"function"==typeof t}function s(t,e){return t!=t?e==e:t!==e||t&&"object"==typeof t||"function"==typeof t}function a(e,n,r){e.$$.on_destroy.push(function(e,...n){if(null==e)return t;const r=e.subscribe(...n);return r.unsubscribe?()=>r.unsubscribe():r}(n,r))}function c(t,e){t.appendChild(e)}function i(t,e,n){t.insertBefore(e,n||null)}function l(t){t.parentNode.removeChild(t)}function u(t){return document.createElement(t)}function d(t){return document.createTextNode(t)}function f(){return d(" ")}function p(t,e,n,r){return t.addEventListener(e,n,r),()=>t.removeEventListener(e,n,r)}function m(t,e,n){null==n?t.removeAttribute(e):t.getAttribute(e)!==n&&t.setAttribute(e,n)}function h(t,e){e=""+e,t.data!==e&&(t.data=e)}let g;function b(t){g=t}const y=[],v=[],$=[],x=[],w=Promise.resolve();let k=!1;function J(t){$.push(t)}let _=!1;const A=new Set;function C(){if(!_){_=!0;do{for(let t=0;t<y.length;t+=1){const e=y[t];b(e),j(e.$$)}for(y.length=0;v.length;)v.pop()();for(let t=0;t<$.length;t+=1){const e=$[t];A.has(e)||(A.add(e),e())}$.length=0}while(y.length);for(;x.length;)x.pop()();k=!1,_=!1,A.clear()}}function j(t){if(null!==t.fragment){t.update(),r(t.before_update);const e=t.dirty;t.dirty=[-1],t.fragment&&t.fragment.p(t.ctx,e),t.after_update.forEach(J)}}const L=new Set;function S(t,e){t&&t.i&&(L.delete(t),t.i(e))}function T(t,e,n,r){if(t&&t.o){if(L.has(t))return;L.add(t),(void 0).c.push(()=>{L.delete(t),r&&(n&&t.d(1),r())}),t.o(e)}}function M(t){t&&t.c()}function N(t,n,s){const{fragment:a,on_mount:c,on_destroy:i,after_update:l}=t.$$;a&&a.m(n,s),J(()=>{const n=c.map(e).filter(o);i?i.push(...n):r(n),t.$$.on_mount=[]}),l.forEach(J)}function q(t,e){const n=t.$$;null!==n.fragment&&(r(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx=[])}function O(t,e){-1===t.$$.dirty[0]&&(y.push(t),k||(k=!0,w.then(C)),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<<e%31}function R(e,o,s,a,c,i,u=[-1]){const d=g;b(e);const f=o.props||{},p=e.$$={fragment:null,ctx:null,props:i,update:t,not_equal:c,bound:n(),on_mount:[],on_destroy:[],before_update:[],after_update:[],context:new Map(d?d.$$.context:[]),callbacks:n(),dirty:u};let m=!1;if(p.ctx=s?s(e,f,(t,n,...r)=>{const o=r.length?r[0]:n;return p.ctx&&c(p.ctx[t],p.ctx[t]=o)&&(p.bound[t]&&p.bound[t](o),m&&O(e,t)),n}):[],p.update(),m=!0,r(p.before_update),p.fragment=!!a&&a(p.ctx),o.target){if(o.hydrate){const t=function(t){return Array.from(t.childNodes)}(o.target);p.fragment&&p.fragment.l(t),t.forEach(l)}else p.fragment&&p.fragment.c();o.intro&&S(e.$$.fragment),N(e,o.target,o.anchor),C()}b(d)}class E{$destroy(){q(this,1),this.$destroy=t}$on(t,e){const n=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return n.push(e),()=>{const t=n.indexOf(e);-1!==t&&n.splice(t,1)}}$set(){}}const D=[];function P(e,n=t){let r;const o=[];function a(t){if(s(e,t)&&(e=t,r)){const t=!D.length;for(let t=0;t<o.length;t+=1){const n=o[t];n[1](),D.push(n,e)}if(t){for(let t=0;t<D.length;t+=2)D[t][0](D[t+1]);D.length=0}}}return{set:a,update:function(t){a(t(e))},subscribe:function(s,c=t){const i=[s,c];return o.push(i),1===o.length&&(r=n(a)||t),s(e),()=>{const t=o.indexOf(i);-1!==t&&o.splice(t,1),0===o.length&&(r(),r=null)}}}}var H=function t(e){function n(t){return function(e,n){return s(e,Object.assign({method:t},n))}}function r(t){return function(e,n,r){return s(e,Object.assign({method:t,data:n},r))}}function o(t,e,n){if(Array.isArray(t))return t.concat(e);if(e&&"object"==typeof e){var r,s={};if(t)for(r in t)s[n?r.toLowerCase():r]=t[r];for(r in e){var a=n?r.toLowerCase():r;"headers"===a&&(n=!0),s[a]=r in s?o(s[a],e[r],n):e[r]}return s}return e}function s(t,n){"string"!=typeof t&&(t=(n=t).url);var r=o(e,n||{}),s=r.data;if(r.transformRequest)for(var a=0;a<r.transformRequest.length;a++){var c=r.transformRequest[a](s,r.headers);void 0!==c&&(s=c)}var i={};if(s&&"object"==typeof s&&(s=JSON.stringify(s),i["Content-Type"]="application/json"),r.xsrfCookieName)for(var l=document.cookie.split(/ *[;=] */),u=0;u<l.length;u+=2)if(l[u]==r.xsrfCookieName){i[r.xsrfHeaderName]=decodeURIComponent(l[u+1]);break}r.auth&&(i.Authorization=r.auth);var d={};return d.config=n,fetch(t,{method:r.method,body:s,headers:o(r.headers,i,!0)}).then((function(t){var e;for(e in t)"function"!=typeof t[e]&&(d[e]=t[e]);return(r.validateStatus?r.validateStatus(t.status):t.ok)?("stream"===r.responseType?Promise.resolve(t.body):t[r.responseType||"text"]()).then((function(t){return d.data=t,d})):Promise.reject(t)}))}return e=e||{},s.request=s,s.get=n("get"),s.delete=n("delete"),s.options=n("options"),s.post=r("post"),s.put=r("put"),s.patch=r("patch"),s.all=Promise.all,s.spread=function(t){return function(e){return t.apply(this,e)}},s.CancelToken=self.AbortController||Object,s.create=t,s}();const I=`${location.protocol}//${location.hostname}:3000`,z={jobs:I.concat("/jobs"),apply:I.concat("/apply"),readall:I.concat("/readall")},F=P([]),B=P({}),U={getJobList(){H.get(z.jobs).then(t=>{const e=JSON.parse(t.data);F.set(e)}).catch(t=>{console.error("getJobList",t)})},loadJobDetail(t){if(console.log("loadJobDetail: "+t),t){const e=`${z.jobs}/${t}`;H.get(e).then(t=>{const e=JSON.parse(t.data);B.set(e)}).catch(t=>{console.error("loadJobDetail",t)})}},async touchJob(t){if(console.log("touchJob: "+t),t){const e=`${z.jobs}/${t}`;await H.put(e).then(t=>{200!==t.status&&console.error(t)}).catch(t=>{console.error("touchJob",t)});const n=parseInt(t,10);F.update(t=>(t.map(t=>{if(t._id===n)return t.d=(new Date).getTime(),t}),t))}},async appliedJob(t){console.log("touchJob: "+t);const e=(new Date).getTime();if(t){console.log("Applying..");const n=`${z.apply}/${t}`;await H.put(n).then(t=>{200!==t.status&&console.error(t)}).catch(t=>{console.error("appliedJob",t)});const r=parseInt(t,10);F.update(t=>(t.map(t=>{if(t._id===r)return t.a=e,t}),t)),B.update(t=>(t.a=e,t))}},async markAllRead(){console.log(">> markAllRead");const t=""+z.readall;await H.put(t).then(t=>{200!==t.status&&console.error(t)}).catch(t=>{console.error("markAllRead",t)}),this.getJobList()}};function W(t,e,n){const r=t.slice();return r[4]=e[n],r[6]=n,r}function G(t){let e,n,r,o,s,a,g,b,y,v,$,x,w,k,J,_,A=t[4].title+"",C=t[4].site+"",j=Q(t[4].company)+"",L=t[4].date+"";return{c(){e=u("tr"),n=u("td"),r=d(A),o=f(),s=u("td"),a=d(C),g=f(),b=u("td"),y=d(j),v=f(),$=u("td"),x=d(L),w=f(),m(e,"class",k="dataRow "+(t[4].d?"read":"")+" "+(t[4].a?"applied":"")+" svelte-bblkbk"),m(e,"data-id",J=t[4]._id)},m(l,u,d){var f;i(l,e,u),c(e,n),c(n,r),c(e,o),c(e,s),c(s,a),c(e,g),c(e,b),c(b,y),c(e,v),c(e,$),c($,x),c(e,w),d&&_(),_=p(e,"click",(f=t[1],function(t){return t.stopPropagation(),f.call(this,t)}))},p(t,n){1&n&&A!==(A=t[4].title+"")&&h(r,A),1&n&&C!==(C=t[4].site+"")&&h(a,C),1&n&&j!==(j=Q(t[4].company)+"")&&h(y,j),1&n&&L!==(L=t[4].date+"")&&h(x,L),1&n&&k!==(k="dataRow "+(t[4].d?"read":"")+" "+(t[4].a?"applied":"")+" svelte-bblkbk")&&m(e,"class",k),1&n&&J!==(J=t[4]._id)&&m(e,"data-id",J)},d(t){t&&l(e),_()}}}function K(e){let n,r,o,s,a,d=e[0],p=[];for(let t=0;t<d.length;t+=1)p[t]=G(W(e,d,t));return{c(){n=u("div"),r=u("table"),o=u("thead"),o.innerHTML='<tr><th class="col-5">\n Title\n </th> \n <th class="col-2">\n Site\n </th> \n <th class="col-3">\n Company\n </th> \n <th class="col-2">\n Date\n </th></tr>',s=f(),a=u("tbody");for(let t=0;t<p.length;t+=1)p[t].c();m(r,"class",""),m(n,"class","lister svelte-bblkbk")},m(t,e){i(t,n,e),c(n,r),c(r,o),c(r,s),c(r,a);for(let t=0;t<p.length;t+=1)p[t].m(a,null)},p(t,[e]){if(3&e){let n;for(d=t[0],n=0;n<d.length;n+=1){const r=W(t,d,n);p[n]?p[n].p(r,e):(p[n]=G(r),p[n].c(),p[n].m(a,null))}for(;n<p.length;n+=1)p[n].d(1);p.length=d.length}},i:t,o:t,d(t){t&&l(n),function(t,e){for(let n=0;n<t.length;n+=1)t[n]&&t[n].d(e)}(p,t)}}}function Q(t){return t.length<=40?t:t.slice(0,40)+"…"}function V(t,e,n){let r;return a(t,F,t=>n(0,r=t)),[r,function(t){const e=t.target.parentElement.dataset.id;U.loadJobDetail(e),U.touchJob(e)}]}class X extends E{constructor(t){super(),R(this,t,V,K,s,{})}}function Y(t){let e,n,r,o,s,a,p,g,b,y,v,$,x,w,k,J,_,A,C,j,L,S,T,M,N,q,O,R,E,D,P,H,I,z,F,B,U,W,G=t[1].title+"",K=t[1].company+"",Q=t[1].location+"",V=t[1].salary+"",X=t[1].date+"",Y=t[1].site+"",et=t[1].summary+"";function nt(t,e){return t[1].a?Z:tt}let rt=nt(t),ot=rt(t);return{c(){e=u("div"),n=u("div"),r=u("div"),o=u("div"),s=d(G),a=f(),p=u("div"),g=u("div"),b=d("Company: "),y=u("span"),v=d(K),$=f(),x=u("div"),w=d("Location: "),k=u("span"),J=d(Q),_=f(),A=u("div"),C=d("Applied:\n "),ot.c(),j=f(),L=u("div"),S=u("div"),T=d("Salary: "),M=u("span"),N=d(V),q=f(),O=u("div"),R=d("Scraped: "),E=u("span"),D=d(X),P=f(),H=u("div"),I=d("Site: "),z=u("a"),F=d(Y),U=f(),W=u("blockquote"),m(o,"class","col-12 text-primary lead"),m(r,"class","row svelte-1mq6d8m"),m(y,"class","text-primary"),m(g,"class","col-1-3rd"),m(k,"class","text-primary"),m(x,"class","col-1-3rd"),m(A,"class","col-1-3rd"),m(p,"class","row svelte-1mq6d8m"),m(M,"class","text-primary"),m(S,"class","col-1-3rd"),m(E,"class","text-primary"),m(O,"class","col-1-3rd"),m(z,"href",B=t[1].url),m(z,"class","text-capitalize"),m(z,"target","_blank"),m(H,"class","col-1-3rd"),m(L,"class","row svelte-1mq6d8m"),m(n,"class","detailHead bg-light svelte-1mq6d8m"),m(e,"class","detail svelte-1mq6d8m")},m(t,l){i(t,e,l),c(e,n),c(n,r),c(r,o),c(o,s),c(n,a),c(n,p),c(p,g),c(g,b),c(g,y),c(y,v),c(p,$),c(p,x),c(x,w),c(x,k),c(k,J),c(p,_),c(p,A),c(A,C),ot.m(A,null),c(n,j),c(n,L),c(L,S),c(S,T),c(S,M),c(M,N),c(L,q),c(L,O),c(O,R),c(O,E),c(E,D),c(L,P),c(L,H),c(H,I),c(H,z),c(z,F),c(e,U),c(e,W),W.innerHTML=et},p(t,e){2&e&&G!==(G=t[1].title+"")&&h(s,G),2&e&&K!==(K=t[1].company+"")&&h(v,K),2&e&&Q!==(Q=t[1].location+"")&&h(J,Q),rt===(rt=nt(t))&&ot?ot.p(t,e):(ot.d(1),ot=rt(t),ot&&(ot.c(),ot.m(A,null))),2&e&&V!==(V=t[1].salary+"")&&h(N,V),2&e&&X!==(X=t[1].date+"")&&h(D,X),2&e&&Y!==(Y=t[1].site+"")&&h(F,Y),2&e&&B!==(B=t[1].url)&&m(z,"href",B),2&e&&et!==(et=t[1].summary+"")&&(W.innerHTML=et)},d(t){t&&l(e),ot.d()}}}function Z(e){let n;return{c(){n=d("Applied!")},m(t,e){i(t,n,e)},p:t,d(t){t&&l(n)}}}function tt(e){let n,r;return{c(){n=u("button"),n.textContent="Applied",m(n,"class","btn btn-sm btn-primary")},m(t,o,s){i(t,n,o),s&&r(),r=p(n,"click",e[2])},p:t,d(t){t&&l(n),r()}}}function et(e){let n,r=e[0]&&Y(e);return{c(){r&&r.c(),n=d("")},m(t,e){r&&r.m(t,e),i(t,n,e)},p(t,[e]){t[0]?r?r.p(t,e):(r=Y(t),r.c(),r.m(n.parentNode,n)):r&&(r.d(1),r=null)},i:t,o:t,d(t){r&&r.d(t),t&&l(n)}}}function nt(t,e,n){let r;a(t,B,t=>n(1,r=t));let o=!1;return B.subscribe(t=>{n(0,o=!function(t){for(const e in t)if(t.hasOwnProperty(e))return!1;return!0}(t))}),[o,r,function(){U.appliedJob(r._id)}]}class rt extends E{constructor(t){super(),R(this,t,nt,et,s,{})}}function ot(e){let n,r,o,s,a,d,h;return{c(){n=u("header"),r=u("section"),o=u("span"),o.textContent=""+st,s=f(),a=u("section"),d=u("button"),d.textContent="Mark All Read",m(o,"class","text-bold navbar-brand mx-1 text-uppercase"),m(r,"class","navbar-section"),m(d,"class","btn btn-sm btn-primary"),m(a,"class","navbar-section text-right"),m(n,"class","navbar bg-primary")},m(t,l,u){i(t,n,l),c(n,r),c(r,o),c(n,s),c(n,a),c(a,d),u&&h(),h=p(d,"click",e[0])},p:t,i:t,o:t,d(t){t&&l(n),h()}}}let st="Jobs";function at(t){return[function(){U.markAllRead()}]}class ct extends E{constructor(t){super(),R(this,t,at,ot,s,{})}}function it(e){let n,r,o,s,a;const d=new ct({}),p=new X({}),h=new rt({});return{c(){M(d.$$.fragment),n=f(),r=u("div"),o=u("div"),M(p.$$.fragment),s=f(),M(h.$$.fragment),m(o,"class","col-12"),m(r,"class","container fullWidth")},m(t,e){N(d,t,e),i(t,n,e),i(t,r,e),c(r,o),N(p,o,null),c(o,s),N(h,o,null),a=!0},p:t,i(t){a||(S(d.$$.fragment,t),S(p.$$.fragment,t),S(h.$$.fragment,t),a=!0)},o(t){T(d.$$.fragment,t),T(p.$$.fragment,t),T(h.$$.fragment,t),a=!1},d(t){q(d,t),t&&l(n),t&&l(r),q(p),q(h)}}}var lt=1e3,ut=6e4,dt=60*ut,ft=24*dt,pt=function(t,e){e=e||{};var n=typeof t;if("string"===n&&t.length>0)return function(t){if((t=String(t)).length>100)return;var e=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(t);if(!e)return;var n=parseFloat(e[1]);switch((e[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return 315576e5*n;case"weeks":case"week":case"w":return 6048e5*n;case"days":case"day":case"d":return n*ft;case"hours":case"hour":case"hrs":case"hr":case"h":return n*dt;case"minutes":case"minute":case"mins":case"min":case"m":return n*ut;case"seconds":case"second":case"secs":case"sec":case"s":return n*lt;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return n;default:return}}(t);if("number"===n&&isFinite(t))return e.long?function(t){var e=Math.abs(t);if(e>=ft)return mt(t,e,ft,"day");if(e>=dt)return mt(t,e,dt,"hour");if(e>=ut)return mt(t,e,ut,"minute");if(e>=lt)return mt(t,e,lt,"second");return t+" ms"}(t):function(t){var e=Math.abs(t);if(e>=ft)return Math.round(t/ft)+"d";if(e>=dt)return Math.round(t/dt)+"h";if(e>=ut)return Math.round(t/ut)+"m";if(e>=lt)return Math.round(t/lt)+"s";return t+"ms"}(t);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(t))};function mt(t,e,n,r){var o=e>=1.5*n;return Math.round(t/n)+" "+r+(o?"s":"")}let ht=0;const gt=new class extends E{constructor(t){super(),R(this,t,null,it,s,{})}}({target:document.body});return function t(){U.getJobList();const e=function(t=0){return 36e5-(new Date).getTime()%36e5+t}()+pt("10m");console.log("Next:",e),ht=setTimeout(()=>{t()},e)}(),gt}();
|