Last active
February 13, 2023 02:24
-
-
Save schnabear/deec3faf5b9879a11d02 to your computer and use it in GitHub Desktop.
ChatWork Export Chat
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var output = ''; | |
| function toYMDHMS(timestamp) { | |
| var a = new Date(timestamp * 1000); | |
| var year = a.getFullYear(); | |
| var month = ('0' + (a.getMonth() + 1)).slice(-2); | |
| var date = ('0' + a.getDate()).slice(-2); | |
| var hour = a.getHours(); | |
| var minute = a.getMinutes(); | |
| var second = a.getSeconds(); | |
| return year + '/' + month + '/' + date + ' ' + hour + ':' + minute + ':' + second; | |
| } | |
| function download(text, name, type) { | |
| var a = document.createElement("a"); | |
| var file = new Blob([text], {type: type}); | |
| a.href = URL.createObjectURL(file); | |
| a.download = name; | |
| a.click(); | |
| } | |
| function fetchChat(user_id, room_id, start_chat_id, contacts, token) { | |
| $.getJSON('https://kcw.kddi.ne.jp/gateway.php', { | |
| cmd: 'load_old_chat', | |
| myid: user_id, | |
| room_id: room_id, | |
| first_chat_id: start_chat_id, | |
| ln: 'en', | |
| _t: token | |
| }).done(function(json) { | |
| var last_chat_id = null; | |
| $.each(json.result.chat_list, function(key, chat) { | |
| if (contacts[chat.aid] != undefined) { | |
| account_name = contacts[chat.aid]['name']; | |
| } else { | |
| account_name = 'Unknown Account'; | |
| } | |
| output = toYMDHMS(chat.tm) + '\n' + account_name + '\n' + chat.msg + "\n----------\n" + output; | |
| last_chat_id = chat.id; | |
| }); | |
| if (last_chat_id != null) { | |
| console.log(last_chat_id); | |
| fetchChat(user_id, room_id, last_chat_id, contacts, token); | |
| } else { | |
| download(output, 'cw' + room_id + '.txt', 'text/plain;charset=utf-8'); | |
| } | |
| }); | |
| } | |
| $.ajax({ | |
| dataType: 'json', | |
| url: 'https://kcw.kddi.ne.jp/gateway.php', | |
| data: { | |
| cmd: 'get_contact_list', | |
| _t: ACCESS_TOKEN | |
| }, | |
| success: function(json) { | |
| fetchChat(myid, $('.chatTimeLine .chatTimeLineMessage').last().data('rid'), $('.chatTimeLine .chatTimeLineMessage').last().data('mid') + '1', json.result.contact_dat, ACCESS_TOKEN); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment