Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name govnokod_poetry
- // @namespace mugiseyebrows.ru
- // @include http://govnokod.ru/
- // @include http://govnokod.ru/?page=*
- // @version 1
- // @grant none
- // ==/UserScript==
- var timeout = 1000;
- function loadComments() {
- var entries = $('a.entry-comments-load');
- entries.each(
- function(i,item){
- setTimeout(function(){$(item).click()},i*timeout);
- }
- );
- return entries.length;
- }
- function beginsWithCapital(line) {
- return line.length > 0 && ((line[0] >= 'А' && line[0] <= 'Я') /*|| (line[0] >= 'A' && line[0] <= 'Z')*/);
- }
- function findPoetry() {
- var poetry = [];
- $('div.entry-comment').each(function(i,item){
- var lines = $(item).text().split(/\n/);
- //console.log(lines);
- var maxLength = 70;
- for (var i=0;i<lines.length-3;i++) {
- if (
- beginsWithCapital(lines[i+0]) && lines[i+0].length < maxLength &&
- beginsWithCapital(lines[i+1]) && lines[i+1].length < maxLength &&
- beginsWithCapital(lines[i+2]) && lines[i+2].length < maxLength &&
- beginsWithCapital(lines[i+3]) && lines[i+3].length < maxLength) {
- var href = $(item).parent().find('a.comment-link').attr('href');
- var author = $(item).parent().find('.entry-author').html();
- var link1 = '<a href="' + href.match(/#.*/) + '">' + 'сюда' + '</a> ';
- var link2 = '<a href="' + href + '">' + 'туда' + '</a> '
- lines.push('<br>' + author + ' ' + link1 + link2);
- poetry.push(lines.join("<br>"));
- //console.log('true');
- break;
- }
- }
- //console.log('false');
- });
- return poetry;
- }
- function findAndShowPoetry() {
- var poetry = findPoetry();
- $('#mydiv').html('<p>' + poetry.join('</p><hr><p>') + '</p>');
- //set target="_blank"
- $('#mydiv a').each(function(i,item) {
- if ($(item).attr('href').match(/^#/) == null) {
- $(item).attr('target','_blank');
- }
- });
- $('#mydiv').css('height','100%');
- $('#mydiv').css('overflow','scroll');
- }
- function toggleLeftRight(id) {
- var el = $(id);
- var pl = el.css('padding-left');
- var pr = el.css('padding-right');
- el.css('padding-left',pr);
- el.css('padding-right',pl);
- if (el.css('left') == '0px') {
- el.css('left',null);
- el.css('right','0px');
- } else {
- el.css('left','0px');
- el.css('right',null);
- }
- }
- window.onload = function() {
- var button1 = '<input type="button" id="mybutton1" value="_[]" />';
- var button2 = '<input type="button" id="mybutton2" value="<->" />';
- var buttons = '<div id="mybuttons" style="position:fixed; top:0px; left:0px;">' + button1 + button2 + '</div>';
- var divStyle = 'position: fixed; top: 0; left: 0; padding: 10px 10px 10px 70px; background-color: rgba(255,255,255,0.8);';
- var div = '<div id="mydiv" style="' + divStyle + '"></div>'
- $('body').append(div + buttons);
- $('#mybutton1').click(function(){$('#mydiv').toggle();});
- $('#mybutton2').click(function(){toggleLeftRight('#mydiv');toggleLeftRight('#mybuttons');});
- $('#mydiv').html('loading...');
- var length = loadComments();
- setTimeout(findAndShowPoetry,(length)*timeout+3000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement