Forked from monokaijs/MessengerAttachmentsScanner.js
Last active
December 25, 2018 04:28
-
-
Save 0x01001/4595ceb7f4e6a04d40758d662e3cd3d4 to your computer and use it in GitHub Desktop.
Scan Facebook Messages for attachments.
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
(() => { | |
/* | |
Script lọc lấy dữ liệu đính kèm tin nhắn Facebook. | |
__________________________ | |
Chắc chắn ai nhắn tin với gấu, với ghệ, với bạn bè, abcxyz thì lúc nào cũng có mấy thứ như đoạn ghi âm, hình ảnh, blah blah. Có khi lâu nhắn rồi nó trôi mất mà kiếm lại thì nhác. Thế nên em có làm cái Script nhỏ nhỏ này dựa trên yêu cầu của một số thành viên trong nhóm ở 1 post nào đó (Em tìm lại thông báo mà không thấy nữa). | |
Cách sử dụng: | |
Vào link bên dưới, dán vào Notepad. | |
Sửa các giá trị: | |
participant: thay thành ID người muốn quét | |
mime_type: loại dữ liệu đính kèm (Cái này một mảng). VD ['audio/aac'] để lọc chỉ lấy tệp ghi âm. Còn ['audio/aac', 'image/jpeg'] để lọc lấy tệp ghi âm và tệp ảnh jpg. Cái này có thể tìm hiểu thêm về các loại mime_types trên Wiki | |
Sau đó copy cái đống đã sửa xong, mở tab Facebook trên Chrome, nhấn Ctrl+Shift+J và dán đống kia vào. Nhấn Enter và chờ nó chạy xong. | |
___________________________ | |
Author: @MonokaiJsp (MonokaiJs | omfg.vn) | |
Author: @MonokaiJsp (MonokaiJs | https://omfg.vn) | |
>>>>>>> Free for Personal Usage. | |
======= Donate me: https://omfg.vn/donate | |
======= Github: https://github.com | |
======= Gists | |
*/ | |
const participant = ''; // Example: 100024036977223 | |
const conversations_count = 1; // 1 recent person | |
const mime_types = ['audio/aac', 'image/jpeg']; // Mime Type Filter | |
var get_list_conversations = (token) => { | |
ajax('https://graph.facebook.com/me/threads?fields=link&limit='+conversations_count+'&access_token=' + token, (data) => { | |
var found = false; | |
var list_conversations = JSON.parse(data).data; | |
for (conv_pos in list_conversations) { | |
let conv = list_conversations[conv_pos]; | |
if (conv.link.includes(participant)) { | |
let url = 'https://graph.facebook.com/' + conv.id + '/messages?fields=attachments&access_token='+token; | |
var scan_data = url => { | |
ajax(url, (data) => { | |
let messages = JSON.parse(data).data; | |
messages.forEach((msg) => { | |
if (typeof msg.attachments !== 'undefined') { | |
msg.attachments.data.forEach((attachment) => { | |
if (mime_types.includes(attachment.mime_type)) { | |
console.log('[' + msg.created_time + '] [' + attachment.mime_type + '] ' + ((typeof attachment.image_data === 'undefined')?attachment.file_url:attachment.image_data.url)); | |
} | |
}); | |
} | |
}); | |
if (typeof JSON.parse(data).paging.next !== 'undefined') { | |
scan_data(JSON.parse(data).paging.next); | |
} else { | |
console.log('> Done!!!'); | |
} | |
}, (e) => { | |
console.log('Failed to retrieve messages!'); | |
}); | |
} | |
scan_data(url); | |
found = true; | |
break; | |
} | |
} | |
if (!found) { | |
console.log('Can not find that conversation!'); | |
} | |
}, (err) => { | |
console.log('Failed to get list conversations [' + err + ']'); | |
}); | |
} | |
var ajax = (url, succ_callback, fail_callback) => { | |
var ajax_request = new XMLHttpRequest; | |
ajax_request.onreadystatechange = () => { | |
if (ajax_request.readyState == 4) { | |
if (ajax_request.status == 200) { | |
succ_callback(ajax_request.responseText); | |
} else { | |
fail_callback(ajax_request.status); | |
} | |
} | |
} | |
ajax_request.open('GET', url); | |
ajax_request.send(); | |
} | |
var get_token = (callback) => { | |
var fb_dtsg = document.getElementsByName('fb_dtsg')[0].value; | |
var http = new XMLHttpRequest; | |
var data = new FormData(); | |
data.append('fb_dtsg', fb_dtsg); | |
data.append('app_id', '165907476854626'); | |
data.append('redirect_uri', 'fbconnect://success'); | |
data.append('display', 'popup'); | |
data.append('ref', 'Default'); | |
data.append('return_format', 'access_token'); | |
data.append('sso_device', 'ios'); | |
data.append('__CONFIRM__', '1'); | |
http.open('POST', 'https://www.facebook.com/v1.0/dialog/oauth/confirm'); | |
http.send(data); | |
http.onreadystatechange = function(){ | |
if(http.readyState == 4 && http.status == 200){ | |
var http2 = new XMLHttpRequest; | |
http2.open('GET', 'https://b-api.facebook.com/restserver.php?method=auth.getSessionForApp&format=json&access_token='+http.responseText.match(/access_token=(.*?)&/)[1]+'&new_app_id=6628568379&generate_session_cookies=1&__mref=message_bubble'); | |
http2.send(); | |
http2.onreadystatechange = function(){ | |
if(http2.readyState == 4 && http2.status == 200){ | |
var http3 = new XMLHttpRequest; | |
var token = JSON.parse(http2.responseText).access_token; | |
callback(token); | |
} | |
} | |
} | |
} | |
} | |
get_token(get_list_conversations); | |
// return false; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment