Guest User

Автоколчанька by Peka73Rus

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