Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Autokolchanka
- // @namespace http://peka.cc
- // @version1337
- // @description enter something useful
- // @match http://*1chan.ru/*
- // @require http://github.com/andris9/jStorage/raw/master/jstorage.js
- // @copyright 2013, Peka73Rus
- // ==/UserScript==
- $((new (function(){
- var self = this;
- var wordsAfterComma = [
- "а",
- "но",
- "который",
- "которая",
- "которые",
- "которое"
- ];
- this.init = function(){
- jQuery(".b-post-statistics").append("<br>");
- self.createButton("Хули вы тут читаете?", self.askAboutReading);
- self.createButton("Пиар параши", self.pearParashee);
- self.createButton("Автоколчанька", self.sendAutoMessage);
- };
- this.createButton = function(text, handler){
- var randomId = Math.random().toString().replace("0.", "button-");
- var button = jQuery("<button>");
- button.addClass(randomId);
- button.text(text);
- jQuery(".b-post-statistics").append(button);
- if (typeof (handler) == "function")
- jQuery(document).on("click", "."+randomId, handler);
- };
- this.pearParashee = function(){
- var threadNumber = window.location.pathname.split("/")[3];
- self.sendMessageToThread("Пиар параши, минус.");
- jQuery.ajax("http://1chan.ru/news/res/"+threadNumber+"/rate_post/down/");
- };
- this.sendMessageToThread = function(message){
- var threadNumber = window.location.pathname.split("/")[3];
- var captcha = self.getCaptcha();
- jQuery.post("http://1chan.ru/news/res/"+threadNumber+"/add_comment/", {"post_id": threadNumber, "captcha": captcha, "homeboard": "anonymous", "text": message });
- };
- this.getCaptcha = function(){
- var captchaBox = jQuery(".b-comment-form input[name=captcha]");
- if (captchaBox.length > 0)
- return captchaBox.val();
- return "";
- };
- this.askAboutReading = function(){
- var stats = ">Читают: " + jQuery("#post_stats_reading").text();
- var text = stats + "\r\nХули вы тут читаете?";
- self.sendMessageToThread(text);
- };
- this.sendAutoMessage = function(){
- var threadNumber = window.location.pathname.split("/")[3];
- var commentNumbers = jQuery(".b-comment_b-info a[name]");
- var words = jQuery.unique(jQuery(".b-comment_b-body,.b-blog-entry_b-body")
- .text().split(/\s+/)
- .filter(function(a){
- return a.match(/[A-Za-zА-Яа-я]+/) && a.length < 15;
- })
- .map(function(a){
- return a.replace(/[\.,!?()]/g, "").toLowerCase()
- }));
- var icons = jQuery(".js-homeboard-select-link");
- var captcha = self.getCaptcha();
- jQuery.post("http://1chan.ru/news/res/"+threadNumber+"/add_comment/", {"post_id": threadNumber, "captcha": captcha, "homeboard": "anonymous", "text": self.generateMessage(threadNumber, commentNumbers, words)});
- };
- this.re = this.getRandomElement = function(array){
- self.lastRandom = 0;
- var randomValue = Math.floor(Math.random()*array.length);
- if (randomValue == window.lastRandom && array.length>1)
- return self.re(array);
- window.lastRandom = randomValue;
- return array[randomValue];
- };
- this.generateMessage = function(threadNumber, commentNumbers, words){
- var replyTo = ">>" + (commentNumbers.length>0?commentNumbers.last().text():threadNumber);
- var wordsCount = Math.floor(Math.random()*30) + 1;
- var text = self.capitaliseFirstLetter(self.re(words));
- var sentenceLength = Math.min(Math.floor(Math.random()*6) + 5, wordsCount);
- var sentenceIndex = 1;
- for (var i=0; i<wordsCount; i++){
- nextWord = self.re(words);
- if (sentenceIndex == 0){
- nextWord = " " + self.capitaliseFirstLetter(nextWord);
- }
- else{
- if (wordsAfterComma.indexOf(nextWord) > -1){
- nextWord = ", " + nextWord;
- }
- else{
- nextWord = " " + nextWord;
- }
- }
- if (sentenceIndex >= sentenceLength - 1){
- sentenceLength = Math.min(Math.floor(Math.random()*7) + 4, wordsCount - i - 1);
- sentenceIndex = 0;
- nextWord += ".";
- }
- else{
- sentenceIndex++;
- }
- text += nextWord;
- }
- return replyTo + "\r\n" + text;
- };
- this.capitaliseFirstLetter = function(input){
- return input.charAt(0).toUpperCase() + input.substr(1);
- };
- })()).init())
Advertisement
Add Comment
Please, Sign In to add comment