Last active
October 2, 2016 15:46
-
-
Save vovanre/36907646acab6e0d4555a70495e55f1e to your computer and use it in GitHub Desktop.
Exelab дампер писем
This file contains 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
// ==UserScript== | |
// @name Exelab Mail dumper | |
// @namespace https://exelab.ru/ | |
// @version 1.4 | |
// @author vovanre | |
// @match https://exelab.ru/f/* | |
// @match http://e4unrusy7se5evw5.onion/f/* | |
// @grant unsafeWindow | |
// @noframes | |
// @run-at document-end | |
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js | |
// @require https://js.zapjs.com/js/download.js | |
// @require https://cdnjs.cloudflare.com/ajax/libs/datejs/1.0/date.min.js | |
// ==/UserScript== | |
$(document).ready(function() { | |
'use strict'; | |
if (unsafeWindow.confirmDelete === undefined) { | |
return; | |
} | |
var doneMessages = -1; | |
var totalMessages = -1; | |
var messages = []; | |
$('[name=checkedMsgAction]').append('<option value="archivemessage">Архивировать</option>'); | |
var hook = unsafeWindow.confirmDelete; | |
if (typeof exportFunction == 'function') { | |
unsafeWindow.confirmDelete = exportFunction(hookConfirmDelete, unsafeWindow); | |
} else { | |
unsafeWindow.confirmDelete = hookConfirmDelete; | |
} | |
function hookConfirmDelete() { | |
var what = document.forms.checkFrm.elements.checkedMsgAction.value; | |
if (what == "archivemessage") { | |
var data = $(document.forms.checkFrm).serializeArray(); | |
if (doneMessages == -1 && totalMessages == -1) { | |
try { | |
dumpMessages(data.filter(function(x) { | |
return x.name == "msgid[]"; | |
})); | |
} catch (err) { | |
console.log(err); | |
reset(); | |
alert("Всё сломалось! Смотри консоль."); | |
} | |
} else { | |
alert("Работа ещё не закончена!"); | |
} | |
} else { | |
hook(); | |
} | |
}; | |
function save() { | |
messages.sort(function(a, b) { | |
return a.timestamp - b.timestamp; | |
}); | |
var output = JSON.stringify(messages, null, 2); | |
download(output, "messages.json", "application/json"); | |
} | |
function reset() { | |
doneMessages = -1; | |
totalMessages = -1; | |
messages = []; | |
} | |
function updateStatus() { | |
doneMessages++; | |
$('#dumpStatus').html(" " + doneMessages + "/" + totalMessages); | |
if (doneMessages == totalMessages) { | |
$('#dumpStatus').remove(); | |
save(); | |
reset(); | |
} | |
} | |
function dumpMessages(ids) { | |
$(".inputButton[type=button]").parent().append('<b id="dumpStatus">0/0</b>'); | |
totalMessages = ids.length; | |
updateStatus(); | |
ids.forEach(function(item) { | |
dumpMessage(item); | |
}); | |
} | |
function dumpMessage(oid) { | |
var id = oid.value; | |
$.get("index.php?action=pmail&step=viewmsg_inbox&page=0&msg_id=" + id, function(data) { | |
var titleElement = $('[href*="&msg_id=' + id + '"]'); | |
var important = titleElement.has("i").length !== 0; | |
var readed = titleElement.has("strong").length === 0; | |
var title = titleElement.text(); | |
var html = $($.parseHTML(data)); | |
var from = html.find(".username").html(); | |
var rawDate = html.find(".tbCel2 > .caption1 > .txtSm:nth-child(1)").html(); | |
rawDate = rawDate.substring(rawDate.indexOf("Отправлено: "), rawDate.indexOf("<br>")); | |
var date = rawDate.substring("Отправлено: ".length); | |
var timestamp = Date.parse(date, "yyyy/MM/dd HH:mm:ss").getTime(); | |
html.find(".txtSm").remove(); | |
var text = html.find(".tbCel2 > .caption1:nth-child(2)").html().replace(/<br[^>]*>/g, "\n").trim(); | |
messages.push({ | |
id: id, | |
title: title, | |
from: from, | |
date: date, | |
timestamp: timestamp / 1000, | |
important: important, | |
//readed: readed, | |
text: text | |
}); | |
updateStatus(); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment