Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name DickishCommentsHider@samlib
- // @description This script will hide comments from dicks on samlib.ru.
- // @description You can easily adapt hiding patterns for your needs (currently there is one for each header and body)
- // @namespace http://www.samlib.ru
- // @include http://samlib.ru/comment/b/burewojandrej/knigi*
- // @include http://zhurnal.lib.ru/comment/b/burewojandrej/knigi*
- // @include http://budclub.ru/comment/b/burewojandrej/knigi*
- // @version 7
- // @grant none
- // ==/UserScript==
- //make all kyrillic letter looking same as latin be latin for search purposes о Т О о O o
- function latinize(s){
- return s.replace(/о/g,"o").replace(/О/g,"O").replace(/Т/g,"T")
- }
- var strptrnBanBody = "\\d+\\.Tor|копрофагия|дaвыдк.|\\bприболт|\\bгнид|\\bсоси\\b|\\bгавно|педофил\\b|гомик|\\bгoмocятин.|голубизна|\\bпедик\\b|\\bпeдap|говноед|школоло|школота|п.дрила|защеканец|\\bхуй|\\bхy.\\b|хуе\\B|\\bпидор|\\bпидар|\\bпедераст|\\bпидарас|\\bтолераст|\\bпизд|\\гандон|\\bдерьмократ|www\.foto\-me\.ru";
- var strptrnBanHeader = "\\bTor\\b|\\bДавыдов|\\bДавыдк|Ляхов Анатолий Георгиевич|[email protected]|Кощиенко Андрей Геннадьевич|[email protected]|Повелитель Пердунов"; // только с * правильно"*Давыдов", "*Кощиенко"
- // unfortunally, we can't use \b or \B in our regexp, cause it only works w/ latin characters. Need to use [^a-zA-Zа-яА-ЯёЁ] or smthng instead:
- var ptrnBanBody = RegExp( latinize(strptrnBanBody).replace(/\\b/g, "(?:^|[^a-zA-Zа-яА-ЯёЁ]|$)").replace(/\\B/g, "[a-zA-Zа-яА-ЯёЁ]"), "i")
- var ptrnBanHeader = RegExp( latinize(strptrnBanHeader).replace(/\\b/g, "(?:^|[^a-zA-Zа-яА-ЯёЁ]|$)").replace(/\\B/g, "[a-zA-Zа-яА-ЯёЁ]"), "")
- //remove some unnecessary stuff on the right side of page
- //document.body.innerHTML=document.body.innerHTML.replace(/<table align=\"right\" bgcolor=\"#e0e0e0\" border=\"0\" cellpadding=\"5\" cellspacing=\"0\">[\s\S]*?<\/table>/,"");
- if (document.body.children[4].nodeName == "TABLE") // evil hack: i'm expecting this table always be on the same place
- {
- document.body.children[4].remove()
- }
- //replace shitty comments with shit.
- //doing some preparations:
- // first of all, just wrap all comments in a div.comment w/ header and body
- document.body.innerHTML=document.body.innerHTML.replace(/(<small>\d+\.<\/small>[\s\S]*?<\/small>)\r?\n?(?:<br>)?([\s\S]*?)(<hr noshade=\"\">)/g,
- "<div class=\"comment\"><div class=\"comment-header\">$1<\/div><div class=\"comment-body\">$2<\/div>$3<\/div>");
- //now process comments
- var arComments = document.getElementsByClassName('comment')
- for (var i = 0; i < arComments.length; i++){
- var elmComment = arComments[i];
- var strHeader = latinize(elmComment.childNodes[0].textContent)
- var strBody = latinize(elmComment.childNodes[1].textContent)
- // if header starts with asterix, anything is ok
- if (elmComment.childNodes[0].children[1].innerHTML.search(/^\*<noindex>/) != 0
- && (
- strHeader.search(ptrnBanHeader) != -1
- ||
- strBody.search(ptrnBanBody) != -1
- )
- )
- {
- elmComment.title = elmComment.childNodes[1].textContent //if you _really_ want to know, text is stored in tooltip
- elmComment.childNodes[1].textContent = "Я - мудак"
- }
- // hide the "Чрезмерное цитирование!"
- elmComment.childNodes[1].innerHTML = elmComment.childNodes[1].innerHTML.replace(/((((( )|(<br>)|(\r?\n)|\s)*(Чрезмерное цитирование!)+)|((( )|(<br>)|(\r?\n)|\s)*(Поправьте сообщение, чтобы цитаты не превышали 70% общего объема сообщения. Сейчас \- \d+%)+))+)/g, "<abbr title='$1'>[...]</abbr>")
- // remove trainling spaces/blank lines at the very end of comment body
- elmComment.childNodes[1].innerHTML = elmComment.childNodes[1].innerHTML.replace(/(( )|(<br>)|(\r?\n)|\s)+$/,"")
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement