Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- vkopt['messages'] = {
- html_tpl:'<!DOCTYPE html>\
- <html>\
- <head><meta charset="utf-8"/><link rel="shortcut icon" href="http://vk.com/images/fav_chat.ico"/><link rel="stylesheet" type="text/css" href="http://vk.com/css/al/common.css" /><title>%title</title><style>\
- body{text-align:center;font:12px/16px Verdana;margin:5px;}\
- hr{border-color:#C3D1E0;}\
- .messages{width:950px;margin:0 auto;text-align:left;} .msg_item {overflow:hidden} .from,.msg_body,.att_head,.attacments,.attacment,.fwd{margin-left:80px;}\
- .upic{float:left} .upic img{vertical-align:top;width:70px;padding:5px;height:70px;}\
- a,a:visited{text-decoration:none;color:#2B587A} a:hover{text-decoration:underline} .att_head{color:#777;}\
- .att_ico{float:left;width:11px;height:11px;margin: 3px 3px 2px; background-image:url(\'http://vk.com/images/icons/mono_iconset.gif\');}\
- .att_photo{background-position: 0 -30px;} .att_audio{background-position: 0 -222px;} .att_video{background-position: 0 -75px;}\
- .att_doc{background-position: 0 -280px;} .att_wall,.att_fwd{background-position: 0 -194px;} .att_gift{background-position: 0 -105px;} \
- .att_sticker{background-position: 0 -362px; width: 12px; height: 12px;}\
- .att_link{background-position: 0 -237px;} .attb_link a span{color:#777777 !important;} .att_geo{background-position: 0 -165px;}\
- .fwd{border:2px solid #C3D1E0;border-width: 0 0 0 2px;margin-left:85px;}\
- </style></head>\
- <body><div class="messages">%messages_body</div></body>\
- </html>',
- make_html: function(msg,user){
- var html='';
- var t2d = function(unix){
- var time = new Date(unix*1000);
- return time.getFullYear()+'.'+('0'+(time.getMonth()+1)).slice(-2)+'.'+('0'+time.getDate()).slice(-2)+' '+('0'+time.getHours()).slice(-2)+':'+('0'+time.getMinutes()).slice(-2)+':'+('0'+time.getSeconds()).slice(-2);
- };
- var t2m = function(inputText) {
- var replacedText,replacePattern2,replacePattern3;
- //add break
- replacedText = replaceEntities(inputText).replace(/&/g,'&').replace(/</g, '<').replace(/>/g,'>').replace(/\n/g,'<br />').replace(/"/g, '"');
- /*
- replacedText.replace(/&#(\d\d+);/g,function(s, c) {
- c=replaceEntities('&#'+c+';')
- return c.replace(/</g, '<').replace(/>/g,'>').replace(/\n/g,'<br />').replace(/"/g, '"');
- }
- */
- //URLs starting with http://, https://, or ftp://
- replacePattern2 = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\\/%?=~_|!:,.;\u0410-\u042f\u0430-\u044f\u0401\u0451]*[-A-Z0-9+&@#\/%=~_|\u0410-\u042f\u0430-\u044f\u0401\u0451])/gim; // /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;А-Яа-яЁё]*[-A-Z0-9+&@#\/%=~_|А-Яа-яЁё])/gim;
- replacedText = replacedText.replace(replacePattern2, '<a href="$1" target="_blank">$1</a>');
- //URLs starting with "www." (without // before it, or it'd re-link the ones done above).
- replacePattern3 = /(^|[^\/])(www\.[\S]+(\b|$))/gim;
- replacedText = replacedText.replace(replacePattern3,'$1<a href="http://$2" target="_blank">$2</a>');
- if (window.Emoji && Emoji.emojiToHTML)
- replacedText = Emoji.emojiToHTML(replacedText,true).replace(/"\/images\//g,'"http://vk.com/images/') || replacedText;
- return replacedText;
- };
- var doc2text=function(t){
- // проверка < и > в именах документов
- return t.replace(/</g, '<').replace(/>/g,'>').replace(/"/g, '"').replace(/&/g,'&');
- };
- var a2t = function(sec){
- return Math.floor(sec/60)+':'+('0'+(sec%60)).slice(-2);
- };
- var chatAction=function(action_name){
- switch(action_name){
- case 'chat_photo_update':
- html='<div style="color:#888888;">'+IDL('HistMsgChatAvaUpd')+'</div>';
- break;
- case 'chat_photo_remove':
- html='<div style="color:#888888;">'+IDL('HistMsgChatAvaDel')+'</div>';
- break;
- default:
- html='<div>action "<b>'+action_name+'</b>" is unknown</div>'
- }
- return html;
- };
- var make_attach=function(attach){
- var html='';
- if (!attach[attach.type]){
- //console.log('Attach broken?', attach);
- attach[attach.type]={};
- }
- switch (attach.type){
- case 'photo':
- var photolink=attach.photo.photo_2560 || attach.photo.photo_1280 || attach.photo.photo_807 || attach.photo.photo_604;
- var photo_size=attach.photo.width ? ' ('+attach.photo.width+'x'+attach.photo.height+')' : '';
- html+='<div class="attacment"> <div class="att_ico att_photo"></div> <a target="_blank" href="'+photolink+'">[photo'+attach.photo.owner_id+'_'+attach.photo.id+']'+photo_size+'</a> </div>';
- break;
- case 'audio':
- var url = attach.audio.url;
- if (!url){
- url = 'http://vk.com/audio?q='+encodeURIComponent(attach.audio.artist+' - '+attach.audio.title);
- }
- html+='<div class="attacment"> <div class="att_ico att_audio"></div> <a target="_blank" href="'+url+'">[audio'+attach.audio.owner_id+'_'+attach.audio.id+'] '+doc2text(attach.audio.artist)+' - '+doc2text(attach.audio.title)+' ('+a2t(attach.audio.duration)+')</a></div>';
- break;
- case 'video':
- html+='<div class="attacment"> <div class="att_ico att_video"></div> <a href="http://vk.com/video'+attach.video.owner_id+'_'+attach.video.id+'" target="_blank">[video'+attach.video.owner_id+'_'+attach.video.id+'] '+doc2text(attach.video.title)+' ('+a2t(attach.video.duration)+')</a></div>';
- break;
- case 'doc':
- html+='<div class="attacment"> <div class="att_ico att_doc"></div> <a target="_blank" href="'+attach.doc["url"].replace(/&/g,'&')+'">'+doc2text(attach.doc.title)+'</a></div>';
- break;
- case 'wall':
- html+='<div class="attacment"> <div class="att_ico att_wall"></div> <a target="_blank" href="http://vk.com/wall'+attach.wall.to_id+'_'+attach.wall.id+'">[wall'+attach.wall.to_id+'_'+attach.wall.id+']</a></div>';
- break;
- case 'link':
- html+='<div class="attacment attb_link"> <div class="att_ico att_link"></div> <a href="'+attach.link.url+'" target="_blank"><span>'+IDL('HistMsgAttachLink')+'</span> '+doc2text(attach.link.title)+'</a></div>';
- break;
- case 'gift':
- html+='<div class="attacment"> <div class="att_ico att_gift"></div> <a target="_blank" href="'+attach.gift.thumb_256+'">'+IDL('HistMsgAttachGift')+' #'+attach.gift.id+'</a></div>';
- break;
- case 'sticker':
- html+='<div class="attacment"> <div class="att_ico att_sticker"></div> <a target="_blank" href="'+attach.sticker.photo_256+'">'+IDL('HistMsgAttachSticker')+' #'+attach.sticker.id+'</a></div>';
- break;
- default:
- html+=JSON.stringify(attach);
- //console.log(attach.type+' is unknown');
- }
- return html;
- };
- var make_geo=function(m){
- var html='';
- html+='<div class="attacment"> <div class="att_ico att_geo"></div> <a href="https://maps.google.ru/maps?q='+m.geo['coordinates']+'" target="_blank">'+IDL('HistMsgGeoAttach')+' '+(m.geo['place'] || {'title':'---'})['title']+'</a></div>';
- return html;
- };
- // write data
- html+='<hr>';
- html+='<div> '+IDL('HistMsgDates').replace(/%start/g,t2d(msg[0].date)).replace(/%end/g,t2d(msg[msg.length-1].date))+' </div>';
- html+='<div> '+IDL('HistMsgCount').replace(/%count/g,msg.length)+' </div>';
- html+='<hr>';
- // icons
- // http://vk.com/images/icons/mono_iconset.gif
- // build
- for(var i=0,j=msg.length;i<j;i++){
- var u=(user[msg[i].user_id] || {
- id: msg[i].user_id,
- first_name: 'DELETED',
- last_name: '',
- photo_100: 'http://vk.com/images/deactivated_c.gif'
- } );
- html+='<div id="msg'+msg[i].id+'" class="msg_item">';
- html+='<div class="upic"><img src="'+
- u.photo_100+
- '" alt="[photo_100]"></div>';
- html+='<div class="from"> <b> <a href="http://vk.com/id'+msg[i].user_id+'" target="_blank">'+u.first_name+' '+u.last_name+'</a></b> @ <a href="#msg'+msg[i].id+'">'+t2d(msg[i].date)+'</a></div>';
- if(msg[i].body != ""){
- html+='<div class="msg_body">'+t2m(msg[i].body)+'</div>';
- }
- if(msg[i].action){
- html+=chatAction(msg[i].action);
- }
- if(msg[i].attachments !== undefined){
- html+='<div class="attacments"> <b>'+IDL('HistMsgAttachments')+'</b> </div>';
- var l=msg[i].attachments.length;
- for(var k=0;k<l;k++){
- html+=make_attach(msg[i].attachments[k]);
- }
- }
- //геолокаци
- if(msg[i].geo !== undefined)
- html+=make_geo(msg[i]);
- if(msg[i].fwd_messages !== undefined){
- initfwd(msg[i].fwd_messages);
- }
- html+='</div>';
- }
- html+='<hr>';
- function initfwd(msgfwd){
- html+='<div class="att_head"> <div class="att_ico att_fwd"></div> '+IDL('HistMsgFwd')+' </div>';
- html+='<div class="fwd">';
- for(var k=0,l=msgfwd.length;k<l;k++){
- var u = (user[msgfwd[k].user_id] || {
- id: msgfwd[k].user_id,
- first_name: 'DELETED',
- last_name: '',
- photo_100: 'http://vk.com/images/deactivated_c.gif'
- } );
- html+='<div class="msg_item">';
- html+='<div class="upic"><img src="'+
- u.photo_100+
- '" alt="[photo_100]"></div>';
- html+='<div class="from"> <b> <a href="http://vk.com/id'+msgfwd[k].user_id+'" target="_blank">'+u.first_name+' '+u.last_name+'</a></b> @ '+t2d(msgfwd[k].date)+'</div>';
- html+='<div class="msg_body"> '+t2m(msgfwd[k].body)+'</div>';
- if(msgfwd[k].attachments !== undefined){
- html+='<div class="attacments"> <b>'+IDL('HistMsgAttachments')+'</b> </div>';
- var n=msgfwd[k].attachments.length;
- for(var m=0;m<n;m++){
- html+=make_attach(msgfwd[k].attachments[m]);
- }
- }
- if(msgfwd[k].geo !== undefined)
- html+=make_geo(msgfwd[k]);
- if(msgfwd[k].fwd_messages !== undefined){
- initfwd(msgfwd[k].fwd_messages);
- }
- html+='</div>';
- }
- html+='</div>';
- }
- return html;
- },
- export_data: function(messages){
- var users_ids = [];
- var history_uids={};
- var collect_users=function(arr){
- for (var i=0; i<arr.length; i++){
- var msg=arr[i];
- //console.log(msg)
- if (msg.from_id) history_uids[msg.from_id]='1';
- if (msg.user_id) history_uids[msg.user_id]='1';
- if (msg.from_id && users_ids.indexOf(msg.from_id)==-1) users_ids.push(msg.from_id);
- if (msg.user_id && users_ids.indexOf(msg.user_id)==-1) users_ids.push(msg.user_id);
- if (msg.fwd_messages)
- collect_users(msg.fwd_messages);
- //for (var i=0; i<msg.fwd_messages.length; i++)
- }
- };
- collect_users(messages);
- var ldr = ge('saveldr');
- if (ldr){
- var w=getSize(ge('saveldr'),true)[0];
- ldr.innerHTML=vkProgressBar(0,100,w,'Users data... %');
- }
- dApi.call('users.get',{user_ids:users_ids.join(','),fields:'photo_100',v:'5.5'},function(r){
- ldr && (ldr.innerHTML = vkProgressBar(90,100,w,'Users data... %'));
- var usrs=r.response;
- var users={};
- for (var i=0; i<usrs.length; i++)
- users[usrs[i].id]=usrs[i];
- for (var i=0; i<users_ids.length; i++)
- if (!users[users_ids[i]])
- users[users_ids[i]]={
- id: users_ids[i],
- first_name: 'DELETED',
- last_name: '',
- photo_100: 'http://vk.com/images/deactivated_c.gif'
- };
- var html=vkopt.messages.make_html(messages, users);
- html=vkopt.messages.html_tpl.replace(/%messages_body/g,html);
- ldr && (ldr.innerHTML=vkProgressBar(100,100,w,'Users data... %'));
- show('save_btn_text');
- hide('saveldr');
- var file_name=[];
- for (var key in users){
- var uid=parseInt(key || '0');
- if (history_uids[key] && !(window.vk && uid==vk.id)) file_name.push(users[key].first_name+" "+users[key].last_name+'('+uid+')');
- }
- html=html.replace(/%title/g,'VK Messages: '+file_name.join(','));
- vkopt.messages.save_file(html,"messages_"+vkCleanFileName(file_name.join(',')).substr(0,250)+".html");
- //vkSaveText();
- });
- },
- save_file: function(data, filename){
- vkLdr.show();
- FileSaverConnect(function() {
- var blob = new Blob([data], {type: "text/plain;charset=utf-8"});
- vkLdr.hide();
- saveAs(blob, filename);
- });
- },
- load_dump: function(callback){
- var inp_el;
- var load_file = function(){
- var file = inp_el.files[0];
- if (!file) {
- return;
- }
- var reader = new FileReader();
- reader.onload = function(e) {
- var contents = JSON.parse(e.target.result);
- callback(contents);
- };
- reader.readAsText(file);
- }
- vkAlertBox(IDL('LoadDump'), IDL('SelectDumpFile')+'<input type="file" id="vk_load_dump_input">', true);
- inp_el = ge('vk_load_dump_input');
- inp_el.addEventListener('change', load_file, false);
- },
- get_history:function(uid){
- if (!uid) uid=cur.thread.id;
- var PER_REQ=100;
- var offset=0;
- var messages = [];
- var scan=function(){
- hide('save_btn_text');
- show('saveldr');
- //document.title='offset:'+offset;
- var w=getSize(ge('saveldr'),true)[0];
- if (offset==0) ge('saveldr').innerHTML=vkProgressBar(offset,10,w);
- var code=[];
- for (var i=0; i<10; i++){
- code.push('API.messages.getHistory({user_id:'+uid+', count:'+PER_REQ+', offset:'+offset+', rev:1}).items');//
- offset+=PER_REQ;
- }
- dApi.call('execute',{code:'return {count:API.messages.getHistory({user_id:'+uid+', count:0, offset:0}).count, items:'+code.join('+')+'};',v:'5.5'},function(r){
- var msgs = r.response.items;
- var count = r.response.count;
- ge('saveldr').innerHTML=vkProgressBar(offset,count,w);
- messages = messages.concat(msgs);
- if (msgs.length>0){
- setTimeout(scan,350);
- } else {
- vkopt.messages.export_data(messages);
- }
- });
- };
- scan();
- }
- };
- vkopt.messages.load_dump(function(data){
- vkopt.messages.export_data(data);
- })
Add Comment
Please, Sign In to add comment