Slupik98

[PLEMIONA] MessagesReader

Dec 4th, 2017
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.77 KB | None | 0 0
  1.  
  2. // Jeżeli jest to zbierane po prostu z wiadomości nie wyszukiwania
  3. // let content = document.getElementById('content_value');
  4. // if(content != null){
  5. // let table = content.children[1] as HTMLTableElement;
  6. // let row = table.rows[1] as HTMLTableRowElement;
  7. // let form = row.children[0] as HTMLFormElement;
  8. // let msgsTable = form.children[1] as HTMLTableElement;
  9. // }
  10. var MessagedExtractor = /** @class */ (function() {
  11. function MessagedExtractor() {
  12. this.urlsToRead = [];
  13. this.messages = [];
  14. }
  15. MessagedExtractor.prototype.getMessages = function() {
  16. var content = document.getElementById('content_value');
  17. if (content != null) {
  18. var table = content.children[1];
  19. var row = table.rows[0];
  20. var cell = row.cells[1];
  21. var msgsTable = cell.children[2];
  22. var msgsRows = msgsTable.rows;
  23. for (var i = 1; i < msgsRows.length; i++) {
  24. var singleMsgRow = msgsRows[i];
  25. var msgCell = singleMsgRow.cells[0];
  26. var elementWithUrl = msgCell.children[0];
  27. var url = elementWithUrl.getAttribute('href');
  28. this.urlsToRead.push(url);
  29. }
  30. } else {
  31. console.log("content == null");
  32. }
  33. this.readMessage(0);
  34. };
  35. MessagedExtractor.prototype.readMessage = function(index) {
  36. if (index < this.urlsToRead.length) {
  37. console.log(index + "/" + this.urlsToRead.length);
  38. var url = this.urlsToRead[index];
  39. var extractor_1 = this;
  40. Downloader.download(url, {
  41. onDownload: function(doc) {
  42. var actionRow = doc.getElementById('action_row');
  43. if (actionRow != null) {
  44. //For get HTML content
  45. // let table = actionRow.closest('table') as HTMLTableElement;
  46. // let messageRow = table.rows[6];
  47. // let messageCell = messageRow.cells[0];
  48. // let contentToSave = messageCell.outerHTML;
  49. // extractor.messages.push(contentToSave);
  50. //For export option
  51. var actionCell = actionRow.cells[0];
  52. var tableOfExport = actionCell.children[0];
  53. var rowOfExport = tableOfExport.rows[0];
  54. var cellOfExport = rowOfExport.cells[3];
  55. var elementWithUrl = cellOfExport.children[0];
  56. var url_1 = elementWithUrl.getAttribute('href');
  57. if (url_1 != null) {
  58. Downloader.download(url_1, {
  59. onDownload: function(doc) {
  60. var textArea = doc.getElementById('bb_code');
  61. if (textArea != null) {
  62. var contentToSave = textArea.textContent;
  63. if (contentToSave != null) {
  64. extractor_1.messages.push(contentToSave);
  65. } else {
  66. console.log("contentToSave == null");
  67. }
  68. } else {
  69. console.log("textArea == null");
  70. }
  71. index++;
  72. extractor_1.readMessage(index);
  73. }
  74. });
  75. } else {
  76. console.log("url == null");
  77. index++;
  78. extractor_1.readMessage(index);
  79. }
  80. } else {
  81. console.log("actionRow == null");
  82. index++;
  83. extractor_1.readMessage(index);
  84. }
  85. }
  86. });
  87. } else {
  88. console.log("end");
  89. console.log(this.messages);
  90. }
  91. };
  92. return MessagedExtractor;
  93. }());
  94. var Downloader = /** @class */ (function() {
  95. function Downloader() {}
  96. Downloader.download = function(url, callback) {
  97. $.ajax({
  98. url: url,
  99. success: function(response) {
  100. var parser = new DOMParser();
  101. var placeDoc = parser.parseFromString(response, "text/html");
  102. callback.onDownload(placeDoc);
  103. }
  104. });
  105. };
  106. return Downloader;
  107. }());
  108. var messExtra = new MessagedExtractor();
  109. messExtra.getMessages();
Advertisement
Add Comment
Please, Sign In to add comment