Advertisement
JackHaxor

Đếm tin nhắn fb message

Aug 3rd, 2017
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.15 KB | None | 0 0
  1. // Written by (C) Rafsun Masud Prince known
  2. if (window.location.hostname != "www.messenger.com") {
  3. alert("Bạn không truy cập trang messenger.com . Vui lòng truy cập trang messenger.com để sử dụng !");
  4. throw new Error("You are not on Messenger. Please visit www.messenger.com then try again.");
  5. }
  6.  
  7. (function(d, s, id) {
  8. var js, fjs = d.getElementsByTagName(s)[0];
  9. if (d.getElementById(id)) return;
  10. js = d.createElement(s); js.id = id;
  11. js.src = "//connect.facebook.net/en_GB/sdk.js#xfbml=1&version=v2.9&appId=286459691717778";
  12. fjs.parentNode.insertBefore(js, fjs);
  13. }(document, 'script', 'facebook-jssdk'));
  14.  
  15. var script = document.createElement("script");
  16. script.src = "https://apis.google.com/js/platform.js";
  17. script.type = "text/javascript";
  18. document.getElementsByTagName("head")[0].appendChild(script);
  19.  
  20. var curr = "";
  21. var children = document.getElementById('js_5');
  22. var elem = document.createElement("span");
  23. elem.setAttribute("id", "message_count_container");
  24. elem.innerHTML = "";
  25. if (children == null) {
  26. alert("Bạn hãy chờ trang messenger load xong rồi hãy dán nhé ! Vui lòng f5 lại trang và thử lại !");
  27. throw new Error("The source is null! Something is wrong. Please report this error!");
  28. }
  29. children.appendChild(elem);
  30.  
  31. children = document.getElementsByClassName('_5742')[0];
  32. elem = document.createElement("span");
  33. elem.setAttribute("id", "message_count_container");
  34.  
  35. if (children == null) {
  36. alert("Bạn hãy chờ trang messenger load xong rồi hãy dán nhé ! Vui lòng f5 lại trang và thử lại !");
  37. throw new Error("The source is null! Something is wrong. Please report this error!");
  38. }
  39. children.appendChild(elem);
  40.  
  41. function numberWithCommas(x) {
  42. return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
  43. }
  44.  
  45. function loadData(url) {
  46. var xhttp = new XMLHttpRequest();
  47. xhttp.onreadystatechange = function() {
  48. if (this.readyState == 4 && this.status == 200) {
  49. updateResult(this.responseText);
  50. }
  51. };
  52. xhttp.open("GET", url, true);
  53. xhttp.send();
  54. }
  55.  
  56. function updateResult(source){
  57. var start_string = 'require("InitialJSLoader").handleServerJS(';
  58. var start = source.indexOf(start_string);
  59. var end = source.indexOf(',"j0")');
  60. var new_html = source.substr(start+start_string.length,end-start-start_string.length);
  61. source = new_html;
  62. if (source == null) {
  63. alert("The source is null! Something is wrong. Please report this error!");
  64. throw new Error("The source is null! Something is wrong. Please report this error!");
  65. }
  66. var vanityX = window.location.href.replace("https://www.messenger.com/t/","");
  67. var jobj = JSON.parse(source);
  68. var final_jobj = -1;
  69. for ( i = 0; i < jobj.require.length; i++)
  70. {
  71. var sess = jobj.require[i];
  72. if (sess[3] != undefined)
  73. {
  74. if (sess[3][1] != undefined)
  75. {
  76. if (sess[3][1].mercuryPayload != undefined)
  77. {
  78. final_jobj = sess[3][1].mercuryPayload;
  79. break;
  80. }
  81. else
  82. continue;
  83. }
  84. else
  85. continue;
  86. }
  87. else
  88. continue;
  89. }
  90. var threadobj = final_jobj.threads;
  91. var participantsobj = final_jobj.participants;
  92. var id = "";
  93. for ( i = 0; i < participantsobj.length; i++)
  94. {
  95. if (participantsobj[i].vanity == vanityX)
  96. {
  97. id = participantsobj[i].fbid;
  98. break;
  99. }
  100. else if (participantsobj[i].fbid == vanityX)
  101. {
  102. id = participantsobj[i].fbid;
  103. break;
  104. }
  105. else
  106. continue;
  107. }
  108. if (id == "")
  109. id = vanityX;
  110. var message_count = "Không Có Tin Nhắn";
  111. for ( i = 0; i < threadobj.length; i++)
  112. {
  113. if (threadobj[i].thread_fbid == id)
  114. {
  115. message_count = threadobj[i].message_count;
  116. break;
  117. }
  118. else if (threadobj[i].thread_fbid == vanityX)
  119. {
  120. message_count = threadobj[i].message_count;
  121. break;
  122. }
  123. else
  124. continue;
  125. }
  126. message_count = numberWithCommas(message_count);
  127. document.getElementById("message_count_container").innerHTML = " ("+message_count+")";
  128. }
  129.  
  130. var time = setInterval(function() {
  131. while( window.location.href != curr)
  132. {
  133. document.getElementById("message_count_container").innerHTML = " ("+"Đợi Tí..."+")";
  134. loadData(window.location.href);
  135. curr = window.location.href;
  136. }
  137. }, 10);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement