Guest User

Untitled

a guest
Jul 18th, 2013
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.89 KB | None | 0 0
  1. $((new (function(){
  2. var self = this;
  3. var wordsAfterComma = [
  4. "а",
  5. "но",
  6. "который",
  7. "которая",
  8. "которые",
  9. "которое"
  10. ];
  11. this.init = function(){
  12.  
  13. jQuery(".b-post-statistics").append("<br>");
  14. self.createButton("Узнать, хули они читают", self.askAboutReading);
  15. self.createButton("Пеар параши", self.pearParashee);
  16. self.createButton("Автоколчанька", self.sendAutoMessage);
  17.  
  18. };
  19.  
  20. this.createButton = function(text, handler){
  21. var randomId = Math.random().toString().replace("0.", "button-");
  22. var button = jQuery("<button>");
  23. button.addClass(randomId);
  24. button.text(text);
  25. jQuery(".b-post-statistics").append(button);
  26. if (typeof (handler) == "function")
  27. jQuery(document).on("click", "."+randomId, handler);
  28. };
  29.  
  30. this.pearParashee = function(){
  31. var threadNumber = window.location.pathname.split("/")[3];
  32. self.sendMessageToThread("Пеар параши, минус.");
  33. jQuery.ajax("http://1chan.ru/news/res/"+threadNumber+"/rate_post/down/");
  34. };
  35.  
  36. this.sendMessageToThread = function(message){
  37. var threadNumber = window.location.pathname.split("/")[3];
  38. var captcha = self.getCaptcha();
  39. jQuery.post("http://1chan.ru/news/res/"+threadNumber+"/add_comment/", {"post_id": threadNumber, "captcha": captcha, "homeboard": "anonymous", "text": message });
  40. };
  41.  
  42. this.getCaptcha = function(){
  43. var captchaBox = jQuery(".b-comment-form input[name=captcha]");
  44. if (captchaBox.length > 0)
  45. return captchaBox.val();
  46. return "";
  47. };
  48.  
  49. this.askAboutReading = function(){
  50. var stats = ">Читают: " + jQuery("#post_stats_reading").text() + " | Отвечают: " + jQuery("#post_stats_writing").text();
  51. var text = stats + "\r\nХули вы тут читаете?";
  52. self.sendMessageToThread(text);
  53. };
  54.  
  55. this.sendAutoMessage = function(){
  56. var threadNumber = window.location.pathname.split("/")[3];
  57. var commentNumbers = jQuery(".b-comment_b-info a[name]");
  58. var words = jQuery.unique(jQuery(".b-comment_b-body,.b-blog-entry_b-body")
  59. .text().split(/\s+/)
  60. .filter(function(a){
  61. return a.match(/[A-Za-zА-Яа-я]+/) && a.length < 15;
  62. })
  63. .map(function(a){
  64. return a.replace(/[\.,!?()]/g, "").toLowerCase()
  65. }));
  66. var icons = jQuery(".js-homeboard-select-link");
  67. var captcha = self.getCaptcha();
  68. alert(captcha);
  69. jQuery.post("http://1chan.ru/news/res/"+threadNumber+"/add_comment/", {"post_id": threadNumber, "captcha": captcha, "homeboard": "anonymous", "text": self.generateMessage(threadNumber, commentNumbers, words)});
  70. };
  71.  
  72. this.re = this.getRandomElement = function(array){
  73. self.lastRandom = 0;
  74. var randomValue = Math.floor(Math.random()*array.length);
  75. if (randomValue == window.lastRandom && array.length>1)
  76. return self.re(array);
  77. window.lastRandom = randomValue;
  78. return array[randomValue];
  79. };
  80.  
  81. this.generateMessage = function(threadNumber, commentNumbers, words){
  82. var replyTo = ">>" + (commentNumbers.length>0?commentNumbers.last().text():threadNumber);
  83. var smile = ":sobak:";
  84. var wordsCount = Math.floor(Math.random()*30) + 1;
  85. var text = self.capitaliseFirstLetter(self.re(words));
  86. var sentenceLength = Math.min(Math.floor(Math.random()*6) + 5, wordsCount);
  87. var sentenceIndex = 1;
  88. for (var i=0; i<wordsCount; i++){
  89. nextWord = self.re(words);
  90. if (sentenceIndex == 0){
  91. nextWord = " " + self.capitaliseFirstLetter(nextWord);
  92. }
  93. else{
  94. if (wordsAfterComma.indexOf(nextWord) > -1){
  95. nextWord = ", " + nextWord;
  96. }
  97. else{
  98. nextWord = " " + nextWord;
  99. }
  100. }
  101. if (sentenceIndex >= sentenceLength - 1){
  102. sentenceLength = Math.min(Math.floor(Math.random()*7) + 4, wordsCount - i - 1);
  103. sentenceIndex = 0;
  104. nextWord += ".";
  105. }
  106. else{
  107. sentenceIndex++;
  108. }
  109.  
  110. text += nextWord;
  111. }
  112. return replyTo + "\r\n" + smile + text;
  113. };
  114.  
  115. this.capitaliseFirstLetter = function(input){
  116. return input.charAt(0).toUpperCase() + input.substr(1);
  117. };
  118. })()).init())
Advertisement
Add Comment
Please, Sign In to add comment