0
Files
joyreactor-mod/jrh.user.js
2020-04-01 23:17:11 +00:00

157 lines
5.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// ==UserScript==
// @name JRH: JoyReactor Helper
// @description Улучшаем JoyReactor
// @version 2.3.1
// @author DmitriyMX
// @namespace https://gitlab.com/DmitriyMX/joyreactor-helper
// @downloadURL https://gitlab.com/DmitriyMX/joyreactor-helper/raw/master/jrh.user.js
// @updateURL https://gitlab.com/DmitriyMX/joyreactor-helper/raw/master/jrh.user.js
// @match http://joy.reactor.cc/*
// @match http://pornreactor.cc/*
// @grant none
// @run-at document-end
// ==/UserScript==
const domainAliaces = {
"joy.reactor.cc": ['reactor.cc', 'joyreactor.cc'],
"pornreactor.cc": [],
};
/**
* Исправляет внутренние ссылки "реактора"
*/
function fixReactorLinks() {
domainAliaces[document.domain].forEach(domain => {
document.querySelectorAll('a[href^="http://' + domain + '/"]').forEach(elm => {
elm.href = elm.href.replace('http://' + domain + '/', 'http://' + document.domain + '/');
});
document.querySelectorAll('a[href^="//' + domain + '/"]').forEach(elm => {
elm.href = elm.href.replace('//' + domain + '/', '//' + document.domain + '/');
});
});
}
function createTreeButton(listId) {
var aTag = document.createElement('a');
aTag.href = "#";
aTag.classList.toggle('collapse-comments');
aTag.text = '[-]';
aTag.dataset.listid = listId;
aTag.style.fontWeight = 'bold';
aTag.style.color = '#656464';
aTag.style.lineHeight = '31px';
aTag.style.textDecoration = 'none';
aTag.style.margin = '0 10px';
aTag.style.padding = '0 10px';
aTag.style.borderRadius = '15px';
aTag.style.background = '#dfdfdf';
aTag.onclick = function() {
var listId = this.dataset.listid;
var commentListElement = document.getElementById(listId);
if (commentListElement.style.display === 'none') {
commentListElement.style.display = '';
this.text = '[-]';
} else {
commentListElement.style.display = 'none';
this.text = '[+]';
}
return false;
};
return aTag;
}
/**
* Добавляем кнопку сворачивания комментариев
*/
function collapseTreeComments() {
var blocks = document.getElementsByClassName('post_comment_list');
var commentBlock = blocks.length === 2 ? blocks[1] : blocks[0];
Array.from(commentBlock.querySelectorAll('div.comment'))
.filter(elm => { return elm.nextElementSibling !== null; })
.filter(elm => { return elm.nextElementSibling.children.length > 0; })
.forEach(elm => {
var listId = elm.nextElementSibling.id;
elm.querySelector('span.reply-link').appendChild(createTreeButton(listId));
});
}
function isPostPage() {
for (var domain of Object.keys(domainAliaces)) {
let regexp = new RegExp("http?:\/\/" + domain.replace(/\./g, '\\.') + "\/post");
if (document.URL.match(regexp) !== null) {
return true;
}
}
return false;
}
/**
* Удаляем лишние элементы с сайта
*/
function removeExcessElements() {
// Удаляем пункты меню "Люди" и "О проекте"
Array.from(document.querySelectorAll('#navlist li'))
.filter(elm => { return elm.querySelector('a').text === "Люди"
|| elm.querySelector('a').text === "О проекте" })
.forEach(elm => { elm.remove() });
// Удаляем правую колонку
document.getElementById('sidebar').remove();
// Косметические исправления
var width = '930px';
document.getElementById('header').style.width = width;
document.getElementById('page').style.width = width;
document.getElementById('topbar').children[0].style.width = width;
document.getElementById('container').style.minWidth = '0';
// Переключатель языков
Array.from(document.getElementsByClassName('lang_select')).forEach(elm => { elm.remove() });
}
/**
* Удаляем лишние элементы из поста
*/
function removeExcessElementsInPost() {
// Удаляем "Тренды" и "Фэндомы"
var elements = document.getElementsByClassName('additional_info');
if (elements.length === 1) {
elements[0].remove();
}
// Удаляем "Похожие посты"
elements = Array.from(document.getElementsByClassName('mainheader'))
.filter(elm => { return elm.innerText === "Похожие посты" });
if (elements.length === 1) {
elements[0].nextElementSibling.remove();
elements[0].remove();
}
}
/**
* Все "новые комментарии" перестают подсвечиваться
*/
function unNewComments() {
document.querySelectorAll('.new').forEach(elm => { elm.classList.toggle('new') });
}
(function() {
'use strict';
removeExcessElements();
fixReactorLinks();
if (isPostPage()) {
removeExcessElementsInPost();
collapseTreeComments();
unNewComments();
}
})();