0

Update userscript.js

This commit is contained in:
2019-09-28 19:39:10 +00:00
parent 53a6ed22cb
commit b8cee4d631

View File

@@ -1,18 +1,77 @@
// ==UserScript== // ==UserScript==
// @name Joy: correcting nofollow domain // @name JRH: JoyReactor Helper
// @namespace http://tampermonkey.net/ // @version 2.0
// @version 1.0 // @author DmitriyMX
// @description correcting nofollow domain
// @author You
// @match http://joy.reactor.cc/* // @match http://joy.reactor.cc/*
// @grant none // @grant none
// @run-at document-end // @run-at document-end
// ==/UserScript== // ==/UserScript==
(function() { /**
'use strict'; * Исправляет ссылки-редиректы
*/
function fixNofollowLinks() {
document.querySelectorAll('a[rel="nofollow"][href^="//reactor.cc"]').forEach((elm) => { document.querySelectorAll('a[rel="nofollow"][href^="//reactor.cc"]').forEach((elm) => {
elm.href = elm.href.replace('//reactor.cc', '//joy.reactor.cc'); elm.href = elm.href.replace('//reactor.cc', '//joy.reactor.cc');
}); });
}
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() {
Array.from(document.querySelectorAll('div.comment'))
.filter(elm => { return elm.nextElementSibling.children.length > 0; })
.forEach(elm => {
var listId = elm.nextElementSibling.id;
elm.querySelector('span.reply-link').appendChild(createTreeButton(listId));
});
// document.querySelectorAll('span.reply-link').forEach(elm => { elm.appendChild(createTreeButton()); })
}
function isPostPage() {
return document.URL.match(/http?:\/\/joy\.reactor\.cc\/post/) !== null
}
(function() {
'use strict';
fixNofollowLinks();
if (isPostPage()) {
collapseTreeComments();
}
})(); })();