-
Notifications
You must be signed in to change notification settings - Fork 0
/
background-compiled.js
1 lines (1 loc) · 18.2 KB
/
background-compiled.js
1
!function(e){function t(n){if(o[n])return o[n].exports;var i=o[n]={exports:{},id:n,loaded:!1};return e[n].call(i.exports,i,i.exports,t),i.loaded=!0,i.exports}var o={};return t.m=e,t.c=o,t.p="",t(0)}([function(e,t,o){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function i(e,t){console.log("track ",e,t),window.Intercom("trackEvent",e,t)}function a(e){chrome.tabs.getSelected(null,function(e){chrome.tabs.executeScript(e.id,{code:"window.codesign = {me: "+localStorage.me+"}"},function(){chrome.tabs.executeScript(e.id,{file:"page-script-compiled/comment.js"},function(){chrome.tabs.sendRequest(e.id,{msg:"contextMenu"},function(){})})})})}function r(){chrome.tabs.getSelected(null,function(e){chrome.tabs.executeScript(e.id,{file:"page.js"},function(){chrome.tabs.sendRequest(e.id,{msg:"scrollPage"},function(){i("#SNAPPED FULL PAGE",{WEB_URL:e.url,"PAGE-TITLE":e.title}),u(A,e.url,e.title)})})})}function s(){l(function(e){chrome.tabs.getSelected(null,function(t){u({canvas:e},t.url,t.title),i("#SNAPPED SCREEN AREA",{WEB_URL:t.url,"PAGE-TITLE":t.title})})})}function c(e,t,o){var n=parseInt(100*e.complete,10)+"%";chrome.runtime.sendMessage({msg:"progress",progress:n,progressMsg:"Capturing..."}),chrome.browserAction.setBadgeText({text:n});var i=e.devicePixelRatio&&1!==e.devicePixelRatio?1/e.devicePixelRatio:1;1!==i&&(e.x=e.x/i,e.y=e.y/i,e.totalWidth=e.totalWidth/i,e.totalHeight=e.totalHeight/i),A.canvas||(A.canvas=document.createElement("canvas"),A.canvas.width=e.totalWidth,A.canvas.height=e.totalHeight),l(function(){o(!0)},{left:e.x,top:e.y})}function l(e,t){chrome.tabs.captureVisibleTab(null,{format:"png",quality:100},function(o){if(o){var n=new Image;n.onload=function(){if(A.canvas)A.canvas.getContext("2d").drawImage(n,t.left,t.top),e();else{var o={width:this.width,height:this.height,left:0,top:0};y&&(o=y);var i=document.createElement("canvas");i.width=o.width,i.height=o.height,i.getContext("2d").drawImage(n,o.left,o.top,o.width,o.height,0,0,o.width,o.height),e(i),console.log(i)}},n.src=o}})}function d(e,t,o){for(var n=e.toDataURL(),i=atob(n.split(",")[1]),a=n.split(",")[0].split(":")[1].split(";")[0],r=new ArrayBuffer(i.length),s=new Uint8Array(r),c=0;c<i.length;c++)s[c]=i.charCodeAt(c);var l=new Blob([r],{type:a}),d=l.size+512,u=t.split("?")[0].split("#")[0];u?(u=u.replace(/^https?:\/\//,"").replace(/[^A-z0-9]+/g,"-").replace(/-+/g,"-").replace(/^[_\-]+/,"").replace(/[_\-]+$/,""),u="-"+u):u="",u="screencapture"+u+"-"+Date.now()+".png";var p="filesystem:chrome-extension://"+chrome.i18n.getMessage("@@extension_id")+"/temporary/"+u;window.webkitRequestFileSystem(window.TEMPORARY,d,function(e){e.root.getFile(u,{create:!0},function(e){e.createWriter(function(e){e.onwriteend=function(){return o(p)},e.write(l)})})})}function u(e,t,o){console.log(e),d(e.canvas,t,function(n){var i=U.pageTitle||o,a={link:n,size:{width:e.canvas.width,height:e.canvas.height},url:t,pins:U.pins,pageTitle:i},r=JSON.parse(localStorage.capturedImages||"[]"),s=JSON.parse(localStorage.images||"[]");s.push(a),r.push(a),localStorage.capturedImages=JSON.stringify(r),localStorage.images=JSON.stringify(s),chrome.runtime.sendMessage({msg:"captured",capturedImage:a}),e.canvas=null,U={},y=null})}function p(e,t,o){var n=e.pin,a=localStorage.token,r=e.boardData.posts[0];e.parentPin;if(console.log(e),"addPin"==e.msg){var s=n.updated?"PUT":"POST",c="POST"==s?"posts/"+r.id+"/tasks/":"tasks/"+n.id;(0,w.request)("http://api.codesign.io/"+c,n.updated?"PUT":"POST",{Authorization:"Token "+a,"Content-Type":"application/json;charset=UTF-8"},{marker:{geometry:{left:n.x/e.width*100,top:n.y/e.height*100,relativeX:n.relativeX,relativeY:n.relativeY,cssPath:n.cssPath},measure:"pixel",shape:"PN"},title:n.text},function(e){o(e)}),i("#CREATED LIVE BOARD TASK",{"LIVE-URL":e.liveUrl,"WEB-URL":e.webUrl,PAGE_TITLE:e.documentTitle,ID:n.id,MESSAGE:n.text})}else if("addComment"==e.msg){var s=n.updated?"PUT":"POST",c="POST"==s?"tasks/"+e.parentPin.id+"/comments/":"comments/"+n.id;(0,w.request)("http://api.codesign.io/"+c,s,{Authorization:"Token "+a,"Content-Type":"application/json;charset=UTF-8"},{title:n.text},function(e){o(e)}),i("#CREATED LIVE BOARD COMMENT",{"LIVE-URL":e.liveUrl,"WEB-URL":e.webUrl,PAGE_TITLE:e.documentTitle,ID:n.id,MESSAGE:n.text})}else if("deletePin"==e.msg)(0,w.request)("http://api.codesign.io/tasks/"+n.id,"DELETE",{Authorization:"Token "+a,"Content-Type":"application/json;charset=UTF-8"},{},function(e){});else if("deleteComment"==e.msg)(0,w.request)("http://api.codesign.io/comments/"+n.id,"DELETE",{Authorization:"Token "+a,"Content-Type":"application/json;charset=UTF-8"},{},function(e){});else if("completePin"==e.msg)(0,w.request)("http://api.codesign.io/tasks/"+n.id,"PUT",{Authorization:"Token "+a,"Content-Type":"application/json;charset=UTF-8"},{status:n.completed?"CP":"AC"},function(e){}),i("#MARKED LIVE BOARD TASK AS COMPLETED",{"LIVE-URL":e.liveUrl,"WEB-URL":e.webUrl,PAGE_TITLE:e.documentTitle,ID:n.id,MESSAGE:n.text});else if("movePin"==e.msg){var l={dragging:!0,geometry:{left:n.x/e.width*100,top:n.y/e.height*100,relativeX:n.relativeX,relativeY:n.relativeY,cssPath:n.cssPath},id:n.id,shape:"PN",task:n.id};(0,w.request)("http://api.codesign.io/markers/"+n.id,"PUT",{Authorization:"Token "+a,"Content-Type":"application/json;charset=UTF-8"},l,function(e){}),i("#MOVED LIVE BOARD TASK PIN",{"LIVE-URL":e.liveUrl,"WEB-URL":e.webUrl,PAGE_TITLE:e.documentTitle,ID:n.id,MESSAGE:n.text})}}function g(e,t,o){var n=localStorage.token,a=e.boardCode;(0,w.request)("http://api.codesign.io/get_board/?code="+a,"GET",{Authorization:"Token "+n},null,function(e){var t=e.board.description.match(/url:(.+)\s/)[1],o="http://www.codesign.io/live/"+a,n=e.board.posts[0].images[0],r={link:n&&n.thumbnail_url,size:{width:n&&n.width,height:n&&n.height},url:t,pins:[],pageTitle:"",sharedLink:o,liveUrl:!0};localStorage.currentLiveBoard=JSON.stringify(r);var s=e.board.posts[0].tasks;chrome.tabs.getSelected(null,function(n){function i(a,r){a==n.id&&"loading"==r.status&&(chrome.tabs.onUpdated.removeListener(i),chrome.tabs.executeScript(n.id,{code:"window.codesign = {me: "+localStorage.me+"};window.codesignPins = "+JSON.stringify(s)+";window.codesignBoardData = "+JSON.stringify(e.board)},function(){chrome.tabs.executeScript(n.id,{file:"page-script-compiled/comment.js"},function(){chrome.tabs.sendRequest(n.id,{msg:"loadPins",liveUrl:t,webUrl:o},function(){})})}))}chrome.tabs.update(n.id,{url:t}),chrome.tabs.onUpdated.addListener(i)}),i("#OPENED LIVE BOARD VIA CLIENT LINK",{"LIVE-URL":t,"WEB-URL":e.board.title,ID:e.board.id})})}function h(e,t,o){var n=localStorage.token,a=JSON.parse(localStorage.capturedImages),r=a.filter(function(t){return t.link==e.image.link})[0];(0,w.request)("http://api.codesign.io/folders/","GET",{Authorization:"Token "+n},null,function(e){function t(e){(0,w.request)("http://api.codesign.io/folders/"+e.id+"/boards/","POST",{Authorization:"Token "+n,"Content-Type":"application/json;charset=UTF-8"},{title:r.pageTitle,description:"url:"+r.url+" #liveboard"},function(e){(0,w.request)("http://api.codesign.io/boards/"+e.id+"/posts/","POST",{Authorization:"Token "+n,"Content-Type":"application/json;charset=UTF-8"},{title:(new Date).toString()},function(t){function o(){console.log(arguments)}(0,w.request)("http://api.codesign.io/posts/"+t.id+"/images/get_upload_url/?filename="+r.name+"&image_type=image%2Fjpeg&thumbnail_type=image%2Fjpeg","GET",{Authorization:"Token "+n},null,function(e){console.log(e),window.webkitResolveLocalFileSystemURL(r.link,function(i){console.log("fillllle"),i.file(function(i){(0,w.s3Upload)(e.image_upload_url,i,o,function(i){var a=document.createElement("canvas");a.width=250,a.height=150;var s=new Image;s.onload=function(){a.getContext("2d").drawImage(s,0,0,this.width,.6*this.width,0,0,250,150);var i=(0,w.dataURItoBlob)(a.toDataURL());(0,w.s3Upload)(e.thumbnail_upload_url,i,o,function(){(0,w.request)("http://api.codesign.io/posts/"+t.id+"/images/","POST",{Authorization:"Token "+n,"Content-Type":"application/json;charset=UTF-8"},{image_upload_url:e.image_upload_url,thumbnail_upload_url:e.thumbnail_upload_url,width:r.size.width,height:r.size.height},function(e){console.log("finish")})})},s.src=r.link})})})});for(var s=0,c=0;c<r.pins.length;c++){var l=r.pins[c];(0,w.request)("http://api.codesign.io/posts/"+t.id+"/tasks/","POST",{Authorization:"Token "+n,"Content-Type":"application/json;charset=UTF-8"},{marker:{geometry:{left:l.x/r.size.width*100,top:l.y/r.size.height*100,relativeX:l.relativeX,relativeY:l.relativeY,cssPath:l.cssPath},measure:"pixel",shape:"PN"},title:l.text},function(t){function o(){if(s++,s==r.pins.length){var t="http://www.codesign.io/live/"+e.client_code;r.sharedLink=t,localStorage.capturedImages=JSON.stringify(a),chrome.runtime.sendMessage({msg:"sharedImage",url:t}),i("#CREATED LIVE BOARD",{"LIVE-URL":t,"WEB-URL":e.title,ID:e.id}),i("#CREATED LIVE BOARD CLIENT LINK",{"LIVE-URL":t,"WEB-URL":e.title,ID:e.id})}}function c(){if(l.children.length)for(var e=0,i=0;i<l.children.length;i++){var a=l.children[i];(0,w.request)("http://api.codesign.io/tasks/"+t.id+"/comments/","POST",{Authorization:"Token "+n,"Content-Type":"application/json;charset=UTF-8"},{title:a.text},function(){e++,e==l.children.length&&o()})}else o()}l.completed?(0,w.request)("http://api.codesign.io/tasks/"+t.id,"PUT",{Authorization:"Token "+n,"Content-Type":"application/json;charset=UTF-8"},{status:"CP"},function(){c()}):c()})}})})}var o=(e.results,e.results.filter(function(e){return"My live boards"==e.title})[0]);o?t(o):(0,w.request)("http://api.codesign.io/folders/","POST",{Authorization:"Token "+n,"Content-Type":"application/json;charset=UTF-8"},{title:"My live boards",personal:!0},function(e){t(e)})})}function m(e,t,o){function n(e){chrome.runtime.sendMessage({msg:"progress",progress:e,progressMsg:"Uploading..."})}var i=localStorage.token,a=e.activeBoard,r=e.activeFolder,s=[],c=JSON.parse(localStorage.capturedImages);"new_board"==a.id?(0,w.request)("http://api.codesign.io/folders/"+r.id+"/boards/","POST",{Authorization:"Token "+i,"Content-Type":"application/json;charset=UTF-8"},{title:c[0].pageTitle},function(e){a=e,f(a,s,n)}):(0,w.request)("http://api.codesign.io/boards/"+a.id+"/posts/","GET",{Authorization:"Token "+i},null,function(e){s=e.results,f(a,s,n)})}function f(e,t,o){var n=localStorage.token,a=JSON.parse(localStorage.capturedImages),r=0;a.forEach(function(s){var c=s.sharedLink,l=c?" liveboard":"";(0,w.request)("http://api.codesign.io/boards/"+e.id+"/posts/","POST",{Authorization:"Token "+n,"Content-Type":"application/json;charset=UTF-8"},{title:s.url+" "+(new Date).toString()+l},function(c){console.log(c),(0,w.request)("http://api.codesign.io/posts/"+c.id+"/images/get_upload_url/?filename="+s.name+"&image_type=image%2Fjpeg&thumbnail_type=image%2Fjpeg","GET",{Authorization:"Token "+n},null,function(l){console.log(l),window.webkitResolveLocalFileSystemURL(s.link,function(d){console.log("fillllle"),d.file(function(d){(0,w.s3Upload)(l.image_upload_url,d,o,function(d){var u=document.createElement("canvas");u.width=250,u.height=150;var p=new Image;p.onload=function(){u.getContext("2d").drawImage(p,0,0,this.width,.6*this.width,0,0,250,150);var d=(0,w.dataURItoBlob)(u.toDataURL());(0,w.s3Upload)(l.thumbnail_upload_url,d,o,function(){(0,w.request)("http://api.codesign.io/posts/"+c.id+"/images/","POST",{Authorization:"Token "+n,"Content-Type":"application/json;charset=UTF-8"},{image_upload_url:l.image_upload_url,thumbnail_upload_url:l.thumbnail_upload_url,width:s.size.width,height:s.size.height},function(o){(0,w.request)("http://api.codesign.io/boards/"+e.id+"/update_order/","POST",{Authorization:"Token "+n,"Content-Type":"application/json;charset=UTF-8"},{keys:t.map(function(e){return e.id}).concat(c.id)},function(){if(s.pins)for(var t=0,o=0;o<s.pins.length;o++){var l=s.pins[o];(0,w.request)("http://api.codesign.io/posts/"+c.id+"/tasks/","POST",{Authorization:"Token "+n,"Content-Type":"application/json;charset=UTF-8"},{marker:{geometry:{left:l.x/s.size.width*100,top:l.y/s.size.height*100,relativeX:l.relativeX,relativeY:l.relativeY,cssPath:l.cssPath},measure:"pixel",shape:"PN"},title:l.text},function(o){function c(){t++,t==s.pins.length&&(i("#UPLOADED IMAGE SUCESSFULLY",{WEB_URL:s.url,"PAGE-TITLE":e.title,"BOARD-ID":e.id,LINK:"http://www.codesign.io/board/"+e.client_code}),r++,r==a.length&&(window.open("http://www.codesign.io/board/"+e.client_code),chrome.browserAction.setBadgeText({text:""}),localStorage.capturedImages="[]"))}function d(){if(l.children.length)for(var e=0,t=0;t<l.children.length;t++){var i=l.children[t];(0,w.request)("http://api.codesign.io/tasks/"+o.id+"/comments/","POST",{Authorization:"Token "+n,"Content-Type":"application/json;charset=UTF-8"},{title:i.text},function(){e++,e==l.children.length&&c()})}else c()}l.completed?(0,w.request)("http://api.codesign.io/tasks/"+o.id,"PUT",{Authorization:"Token "+n,"Content-Type":"application/json;charset=UTF-8"},{status:"CP"},function(){d()}):d()})}else r++,r==a.length&&(window.open("http://www.codesign.io/board/"+e.client_code),chrome.browserAction.setBadgeText({text:""}),localStorage.capturedImages="[]")})})})},p.src=s.link})})})})})})}var T=o(1),w=(n(T),o(2));!function(){var e=window,t=e.Intercom;if("function"==typeof t)t("reattach_activator"),t("update",intercomSettings);else{var o=function(){var e=n.createElement("script");e.type="text/javascript",e.async=!0,e.src="https://widget.intercom.io/widget/ufe67jbo";var t=n.getElementsByTagName("script")[0];t.parentNode.insertBefore(e,t)},n=document,i=function a(){a.c(arguments)};i.q=[],i.c=function(e){i.q.push(e)},e.Intercom=i,e.attachEvent?e.attachEvent("onload",o):e.addEventListener("load",o,!1)}}();var v,b,E,S={boot:function(e,t,o,n){console.log("Intercom.boot: start"),window.Intercom("boot",{app_id:"lid3oqje",user_id:e,name:t,email:o,created_at:n,extension:!0}),console.log("Intercom.boot: done")},shutdown:function(){console.log("Intercom.shutdown"),window.Intercom("shutdown")},loggedIn:function(e){i("#LOGGED IN VIA EXTENSION",e)},loggedOut:function(e){i("#LOGGED OUT VIA EXTENSION",e)}},A={},U={},y=null;chrome.contextMenus.create({title:"Add Comment",contexts:["all"],onclick:a}),chrome.runtime.onInstalled.addListener(function(){chrome.tabs.create({url:"http://www.codesign.io/checkauthorization"},function(e){})}),chrome.runtime.setUninstallURL("http://www.codesign.io/uninstalled"),chrome.extension.onRequest.addListener(function(e,t,o){console.log("message ext"),"capturePage"===e.msg?b?console.log("cancel"):c(e,t,o):"cropData"===e.msg?(y=e,localStorage.currentAction="crop",chrome.browserAction.setBadgeText({text:"share"})):"addPin"==e.msg||"deletePin"==e.msg||"completePin"==e.msg||"addComment"==e.msg||"deleteComment"==e.msg?(e.commentMode?p(e,t,o):(U=e,e.pins.length&&(localStorage.currentAction="comment")),chrome.browserAction.setBadgeText({text:e.pins.length?"share":""})):"cancelCrop"==e.msg?(y=null,localStorage.currentAction="",chrome.browserAction.setBadgeText({text:""})):"checkStartOauth"==e.msg?o(v):"stopOauth"==e.msg?(console.log("stopOauth"),e.token?(localStorage.token=e.token,chrome.tabs.getSelected(null,function(t){chrome.tabs.remove(t.id),!E&&chrome.tabs.create({url:"http://www.codesign.io/extension-successfully-installed"},function(e){});var o=localStorage.token;(0,w.request)("http://api.codesign.io/users/me/","GET",{Authorization:"Token "+o},null,function(t){localStorage.me=JSON.stringify(t),S.boot(t.user.id,t.user.first_name,t.user.date_joined),S.loggedIn({login_type:e.urlProvider?e.urlProvider:"email"})}),e.fromSite||chrome.tabs.create({url:"http://www.codesign.io/syncauthorization",selected:!1},function(e){})})):chrome.tabs.getSelected(null,function(e){E=!0,localStorage.firstAuthorization="true",chrome.tabs.update(e.id,{url:"http://www.codesign.io/chrome?extension-authorization"})}),v=null):"syncAuthorization"==e.msg?e.token?chrome.tabs.remove(t.tab.id):o(localStorage.token):"closeWindow"==e.msg&&(console.log("closeWindow"),chrome.tabs.remove(t.tab.id))}),chrome.runtime.onMessage.addListener(function(e,t,o){console.log("message"),"takeFullPageScreenshot"===e.msg?r():"takeVisiblePageScreenshot"===e.msg?s():"uploadImages"==e.msg?m(e,t,o):"startOauth"==e.msg?v=!0:"shareImage"==e.msg?h(e,t,o):"cancel"==e.msg?(b=!0,A.canvas=null,U={},y=null,chrome.runtime.sendMessage({msg:"cancelXHR"}),setTimeout(function(){b=!1,chrome.browserAction.setBadgeText({text:JSON.parse(localStorage.capturedImages||"[]").length||""})},500)):"logOutUser"==e.msg?(S.loggedOut({}),S.shutdown()):"liveBoard"==e.msg&&(console.log("liveboard message"),g(e,t,o))}),chrome.runtime.onMessageExternal.addListener(function(e,t,o){console.log("receive external message"),"liveBoard"==e.msg&&(console.log("liveboard message"),g(e,t,o))})},function(e,t){"use strict";function o(e){if(null===e||void 0===e)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(e)}var n=Object.prototype.hasOwnProperty,i=Object.prototype.propertyIsEnumerable;e.exports=Object.assign||function(e,t){for(var a,r,s=o(e),c=1;c<arguments.length;c++){a=Object(arguments[c]);for(var l in a)n.call(a,l)&&(s[l]=a[l]);if(Object.getOwnPropertySymbols){r=Object.getOwnPropertySymbols(a);for(var d=0;d<r.length;d++)i.call(a,r[d])&&(s[r[d]]=a[r[d]])}}return s}},function(e,t){"use strict";function o(e,t,o,n,i){var a=new XMLHttpRequest,r=JSON.stringify(n);a.open(t,e,!0);for(var s in o)a.setRequestHeader(s,o[s]);a.onreadystatechange=function(){4==a.readyState&&i(JSON.parse(a.responseText||"{}"))},chrome.runtime.onMessage.addListener(function(e,t,o){"cancelXHR"===e.msg&&a.abort()}),a.send(r)}function n(e,t,o,n){var i=new XMLHttpRequest;i.onerror=function(e){console.log("error")},i.upload.addEventListener("progress",function(e){var t=Math.round(e.loaded/e.total*100);o(t)},!1),i.onreadystatechange=function(){i.readyState===XMLHttpRequest.DONE&&(i.status>=200&&i.status<=299?n(i.responseText):console.log("error"))},chrome.runtime.onMessage.addListener(function(e,t,o){"cancelXHR"===e.msg&&i.abort()}),i.open("PUT",e,!0),i.setRequestHeader("Content-Type","image/jpeg"),i.setRequestHeader("Cache-Control","public, max-age=31536000"),i.send(t)}function i(e){var t=";base64,";if(-1==e.indexOf(t)){var o=e.split(","),n=o[0].split(":")[1],i=decodeURIComponent(o[1]);return new Blob([i],{type:n})}for(var o=e.split(t),n=o[0].split(":")[1],i=window.atob(o[1]),a=i.length,r=new Uint8Array(a),s=0;a>s;++s)r[s]=i.charCodeAt(s);return new Blob([r],{type:n})}Object.defineProperty(t,"__esModule",{value:!0}),t.request=o,t.s3Upload=n,t.dataURItoBlob=i}]);