Guest User

Untitled

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