Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Jeżeli jest to zbierane po prostu z wiadomości nie wyszukiwania
- // let content = document.getElementById('content_value');
- // if(content != null){
- // let table = content.children[1] as HTMLTableElement;
- // let row = table.rows[1] as HTMLTableRowElement;
- // let form = row.children[0] as HTMLFormElement;
- // let msgsTable = form.children[1] as HTMLTableElement;
- // }
- var MessagedExtractor = /** @class */ (function() {
- function MessagedExtractor() {
- this.urlsToRead = [];
- this.messages = [];
- }
- MessagedExtractor.prototype.getMessages = function() {
- var content = document.getElementById('content_value');
- if (content != null) {
- var table = content.children[1];
- var row = table.rows[0];
- var cell = row.cells[1];
- var msgsTable = cell.children[2];
- var msgsRows = msgsTable.rows;
- for (var i = 1; i < msgsRows.length; i++) {
- var singleMsgRow = msgsRows[i];
- var msgCell = singleMsgRow.cells[0];
- var elementWithUrl = msgCell.children[0];
- var url = elementWithUrl.getAttribute('href');
- this.urlsToRead.push(url);
- }
- } else {
- console.log("content == null");
- }
- this.readMessage(0);
- };
- MessagedExtractor.prototype.readMessage = function(index) {
- if (index < this.urlsToRead.length) {
- console.log(index + "/" + this.urlsToRead.length);
- var url = this.urlsToRead[index];
- var extractor_1 = this;
- Downloader.download(url, {
- onDownload: function(doc) {
- var actionRow = doc.getElementById('action_row');
- if (actionRow != null) {
- //For get HTML content
- // let table = actionRow.closest('table') as HTMLTableElement;
- // let messageRow = table.rows[6];
- // let messageCell = messageRow.cells[0];
- // let contentToSave = messageCell.outerHTML;
- // extractor.messages.push(contentToSave);
- //For export option
- var actionCell = actionRow.cells[0];
- var tableOfExport = actionCell.children[0];
- var rowOfExport = tableOfExport.rows[0];
- var cellOfExport = rowOfExport.cells[3];
- var elementWithUrl = cellOfExport.children[0];
- var url_1 = elementWithUrl.getAttribute('href');
- if (url_1 != null) {
- Downloader.download(url_1, {
- onDownload: function(doc) {
- var textArea = doc.getElementById('bb_code');
- if (textArea != null) {
- var contentToSave = textArea.textContent;
- if (contentToSave != null) {
- extractor_1.messages.push(contentToSave);
- } else {
- console.log("contentToSave == null");
- }
- } else {
- console.log("textArea == null");
- }
- index++;
- extractor_1.readMessage(index);
- }
- });
- } else {
- console.log("url == null");
- index++;
- extractor_1.readMessage(index);
- }
- } else {
- console.log("actionRow == null");
- index++;
- extractor_1.readMessage(index);
- }
- }
- });
- } else {
- console.log("end");
- console.log(this.messages);
- }
- };
- return MessagedExtractor;
- }());
- var Downloader = /** @class */ (function() {
- function Downloader() {}
- Downloader.download = function(url, callback) {
- $.ajax({
- url: url,
- success: function(response) {
- var parser = new DOMParser();
- var placeDoc = parser.parseFromString(response, "text/html");
- callback.onDownload(placeDoc);
- }
- });
- };
- return Downloader;
- }());
- var messExtra = new MessagedExtractor();
- messExtra.getMessages();
Advertisement
Add Comment
Please, Sign In to add comment