Advertisement
Guest User

Untitled

a guest
Mar 20th, 2014
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Chatvtroem
  3. // @namespace Chatvdvoem
  4. // @include http://chatvdvoem.ru/
  5. // @version 2.1
  6. // ==/UserScript==
  7.  
  8. function connect(from, to) {
  9. from.initBz1 = function () {};
  10.  
  11. var process_event = from.process_event;
  12.  
  13. from.process_event = function (data) {
  14. var result = process_event(data);
  15.  
  16. if (data.action == "start_chat" && from.chat_cid == to.chat_cid) {
  17. from.onbeforeunload = to.onbeforeunload = undefined;
  18. start();
  19. } else if (data.action == "new_message") {
  20. var message = from.document.querySelector("#messages").firstChild.lastChild;
  21.  
  22. if (data.user == "im") {
  23. message.querySelector(".name").innerHTML = "<i>Туда</i>";
  24. } else {
  25. message.querySelector(".name").innerHTML = "<i>Сюда</i>";
  26. to.send("send_message", {message: message.querySelector(".message").textContent});
  27. to.chat_ping_send = Date().getTime();
  28. }
  29. } else if (data.action == "start_typing" && !to.chat_typing_status) {
  30. to.send("start_typing");
  31. to.chat_ping_send = Date().getTime();
  32. } else if (data.action == "stop_typing" && to.chat_typing_status) {
  33. to.send("stop_typing");
  34. to.chat_ping_send = Date().getTime();
  35. } else if (data.action == "stop_chat" && data.user != "im") {
  36. to.chat_stop();
  37. }
  38.  
  39. return result;
  40. };
  41.  
  42. from.chat_start();
  43. }
  44.  
  45. function start() {
  46. var frameset = document.createElement("frameset");
  47. var one = document.createElement("frame");
  48. var two = document.createElement("frame");
  49.  
  50. frameset.setAttribute("cols", "50%, 50%");
  51.  
  52. one.addEventListener("load", function (e) {
  53. two.setAttribute("src", "/?2");
  54. });
  55.  
  56. two.addEventListener("load", function (e) {
  57. connect(one.contentWindow, two.contentWindow);
  58. connect(two.contentWindow, one.contentWindow);
  59. });
  60.  
  61. one.setAttribute("src", "/?1");
  62.  
  63. frameset.appendChild(one);
  64. frameset.appendChild(two);
  65.  
  66. document.body.innerHTML = document.head.innerHTML = "";
  67. document.body.setAttribute("style", "margin: 0px;");
  68. document.body.appendChild(frameset);
  69. };
  70.  
  71. var activate = document.createElement("a");
  72.  
  73. activate.setAttribute("href", "/");
  74. activate.textContent = "Траллеть";
  75.  
  76. activate.addEventListener("click", function (e) {
  77. start();
  78. e.preventDefault();
  79. });
  80.  
  81. document.querySelector(".startChat").appendChild(activate);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement