Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding a new procedure: archiving #196

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

<script src="extension.js"></script>
<script src="js/pdf.js"></script>
<script src="js/archive.js"></script>
<script src="editor.js"></script>
<script src="libs\svgcanvas.js"></script>
</head>
Expand Down Expand Up @@ -99,6 +100,8 @@
</div>
</div>
<div class="buttons">
<button title="Archive" class="archive" style="text-indent: initial;font-size:inherit">
<span class="icon"></span>Archive</button>
<button title="Share" class="share" style="text-indent: initial;font-size:inherit">
<span class="icon"></span> Share</button>
<button title="Save Local" class="save">
Expand Down
7 changes: 7 additions & 0 deletions editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2197,6 +2197,13 @@ $(function(){
}
});

$('.archive').on('click',function (e){
editor.createLastCanvas('toolbar',function (data){
screenshot['image_data'] = data;
archivePage(screenshot);
})
});

$('.share').on('click',function (e){
var x=staticPlugin.getPluginByKey('openscreenshot')
editor.createLastCanvas('toolbar',function (data){
Expand Down
40 changes: 40 additions & 0 deletions js/archive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

function archivePage(screenshot_data){

var pngDataURItoBlob=function(dataURI) {
var binary = atob(dataURI.split(',')[1]);
var array = [];
for(var i = 0; i < binary.length; i++) {
array.push(binary.charCodeAt(i));
}
return new Blob([new Uint8Array(array)], {type: 'image/jpeg'})
}

var send_download = function(blob,dt,dtype,ext){
var url=URL.createObjectURL(blob);
console.log(url);
var evt = document.createEvent("MouseEvents");evt.initMouseEvent("click", true, true, window,0, 0, 0, 0, 0, false, true, false, false, 0, null);
var a=$('<a></a>').appendTo(document.body);
var filename = 'webarc_' + dt.getTime() + '.' + dtype + '.' + ext;
a.attr({'href':url,'download':filename})[0].dispatchEvent(evt);
};

let now = new Date();
//PAGE SRC
var blob_src = new Blob([ screenshot_data['captureCodeTxt'] ], {type : "text/plain;charset=utf-8"});
send_download(blob_src,now, 's','html');


//META
var meta = {
'url': screenshot_data['url'],
'title': (screenshot_data['title'] || ''),
'dt': now.toISOString()
};
var blob_meta = new Blob([ JSON.stringify(meta, null, 2) ], {type : "text/plain;charset=utf-8"});
send_download(blob_meta,now, 'm','json');

//IMAGE
var blob_image = pngDataURItoBlob(screenshot_data['image_data']);
send_download(blob_image,now, 'i','png');
}
8 changes: 7 additions & 1 deletion js/screenshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ var screenshot = {

},

captureCode: function (){
chrome.tabs.executeScript(screenshot.thisTabId, {code:'var code = document.documentElement.outerHTML; code'}, function(code){
screenshot.captureCodeTxt = code;
});
},

captureVisible: function (data) {
$.extend(screenshot, {
callback: null,
Expand Down Expand Up @@ -310,7 +316,7 @@ var screenshot = {
}

} else {

screenshot.captureCode();
chrome.tabs.create({url: chrome.extension.getURL('editor.html') + '#last'});

delete screenshot.callback;
Expand Down