Skip to content

Instantly share code, notes, and snippets.

@imDaniX
Last active February 19, 2024 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imDaniX/88206ef3b96720f66f97f07a0fc2def9 to your computer and use it in GitHub Desktop.
Save imDaniX/88206ef3b96720f66f97f07a0fc2def9 to your computer and use it in GitHub Desktop.
RuBukkit Upgraded
// ==UserScript==
// @name RuBukkit Upgraded
// @namespace imDaniX:rubukkit
// @updateURL https://gist.github.com/imDaniX/88206ef3b96720f66f97f07a0fc2def9/raw/rubukkit-upgraded.user.js
// @downloadURL https://gist.github.com/imDaniX/88206ef3b96720f66f97f07a0fc2def9/raw/rubukkit-upgraded.user.js
// @version 0.3.17
// @description A better way of using RuBukkit
// @author imDaniX
// @license GPL-3.0-or-later; https://www.gnu.org/licenses/gpl-3.0.txt
// @match http://*.rubukkit.org/*
// @match https://*.rubukkit.org/*
// @icon https://www.google.com/s2/favicons?domain=rubukkit.org
// @grant none
// @require https://cdnjs.cloudflare.com/ajax/libs/identicon.js/2.3.3/identicon.min.js
// @require https://raw.githubusercontent.com/emn178/js-sha1/master/build/sha1.min.js
// @run-at document-end
// ==/UserScript==
'use strict';
function Alias(path, id, title, description) {
this.path = path;
this.id = id;
this.title = title;
this.description = description;
}
const aliases = [
new Alias(
'forums/relizy-plaginov.31/', 31,
'[Архив] Релизы плагинов',
'В данном разделе размещены cтарые плагины бывалых пользователей RuBukkit. Раздел не обновлялся с 2016 года, но некоторые плагины ещё обновляются.'
),
new Alias(
'forums/nepodtverzhdennye-plaginy.4/', 4,
'Пользовательские плагины',
'В данном разделе пользователи могут размещать собственные плагины и ресурсы.'
),
new Alias(
'forums/relizy-perevodov.33/', 33,
'[Архив] Релизы переводов',
'В данном разделе размещены cтарые переводы бывалых пользователей RuBukkit. Раздел не обновлялся с 2015 года.'
),
new Alias(
'forums/nepodtverzhdennye-perevody.34/', 34,
'Пользовательские переводы',
'В данном разделе пользователи могут размещать собственные переводы.'
),
new Alias(
'forums/razrabotka-plaginov-dlja-novichkov.7/', 7,
'Помощь в разработке плагинов',
'Для начинающих и прочих разработчиков: обсуждение процесса разработки, обмен мнениями, помощь в начинаниях.'
),
new Alias(
'forums/alternativnye-servernye-platformy.38/', 38,
'Альтернативные серверные платформы',
'В данном разделе идет обсуждение альтернативных севрерных платформ Minecraft.'
)
];
const storage = window.sessionStorage;
var newsAlert = false;
start();
function getIdenticon(username, sizes) {
let key = 'rbu.identicon:' + username + '/' + sizes;
let ident = storage.getItem(key);
if (ident) return ident;
ident = 'data:image/svg+xml;base64,' + new Identicon(sha1(username), {size:sizes, format:'svg'}).toString()
storage.setItem(key, ident);
return ident;
}
function start() {
upgradeSections();
upgradePicturesStatic();
upgradeLinks();
new MutationObserver(upgradeDynamically).observe(document, {
childList: true,
subtree: true,
});
}
function upgradeDynamically(mutations) {
upgradeSectionsDynamically();
upgradePicturesStatic();
upgradePicturesDynamically();
upgradeVideos();
}
function upgradeSections() {
let mainPage;
let location = window.location.pathname;
if (location.startsWith('/threads')) {
let tip = document.querySelector('div#content.thread_view p#pageDescription.muted a');
mainPage = false;
for (let alias of aliases) {
if (tip.href === 'https://rubukkit.org/' + alias.path) {
tip.innerText = alias.title;
break;
}
}
} else mainPage = location === '/';
let findPage = mainPage || location.startsWith('/find-new');
for (let alias of aliases) {
let docs = document.querySelectorAll(findPage ?
'[href="' + alias.path + '"]' :
'.crumb[href="https://rubukkit.org/' + alias.path + '"] span');
for (let doc of docs) {
doc.innerText = alias.title;
}
}
if (mainPage) {
for (let alias of aliases) {
document.querySelector('blockquote#nodeDescription-' + alias.id + '.nodeDescription').innerText = alias.description;
}
let section = document.querySelector('ol#forums.nodeList.sectionMain');
section.insertBefore(section.children[3], section.children[2]);
let node = section.children[0];
newsAlert = node.querySelector('.nodeIcon').title.length > 0;
node.remove();
} else for (let alias of aliases) {
if (location === '/' + alias.path) {
document.title = alias.title + ' | Bukkit по-русски - свой сервер Minecraft';
let docs = document.querySelector('div.titleBar').childNodes;
docs[1].innerText = alias.title;
docs[3].innerText = alias.description;
break;
}
}
}
function upgradeSectionsDynamically() {
for (let alias of aliases) {
let docs = document.querySelectorAll('.concealed[href="' + alias.path + '"]:not(.rbu_checked)');
for (let doc of docs) {
doc.className += ' rbu_checked';
doc.innerText = alias.title;
return;
}
}
}
function upgradePicturesStatic() {
let location = window.location.pathname;
if (location.startsWith('/threads') || location.startsWith('/conversations')) {
replacePictures('m');
replacePictures('male_m');
replacePictures('female_m');
} else if (location.startsWith('/members') || location.startsWith('/online') || location.startsWith('/recent-activity')) {
if (location != '/members/' && location != '/members/?') {
replacePictures('l', true);
replacePictures('male_l', true);
replacePictures('female_l', true);
}
replacePicturesBackground(document);
} else {
replacePictures('s');
replacePictures('male_s');
replacePictures('female_s');
}
}
function upgradePicturesDynamically() {
let node;
if (node = document.querySelector('body>#AlertsMenu')) {
replacePictures('s');
replacePictures('male_s');
replacePictures('female_s');
}
for (node of document.querySelectorAll('body>.xenOverlay.memberCard')) {
let username = node.querySelector('.username.NoOverlay').innerText;
let img; // That's freaking stupid, but it works
if (img = node.querySelector('[src="styles/default/xenforo/avatars/avatar_l.png"]')); else
if (img = node.querySelector('[src="styles/default/xenforo/avatars/avatar_male_l.png"]')); else
if (img = node.querySelector('[src="styles/default/xenforo/avatars/avatar_female_l.png"]')); else continue;
img.src = getIdenticon(username, 192);
}
let location = window.location.pathname;
if (location.startsWith('/members/') && !location.startsWith('/members/?')) {
for (let node of document.querySelectorAll('body>.xenOverlay')) {
replacePicturesBackground(node);
}
} else if (location.startsWith('/threads') || location.startsWith('/conversations')) {
replacePictures('male_m');
}
}
function replacePicturesBackground(doc) {
for (let node of doc.querySelectorAll('.img.s')) {
let image = node.style.getPropertyValue('background-image');
if (image === 'url("styles/default/xenforo/avatars/avatar_s.png")' ||
image === 'url("styles/default/xenforo/avatars/avatar_male_s.png")' ||
image === 'url("styles/default/xenforo/avatars/avatar_female_s.png")') {
let username = node.innerText;
if (!username) {
username = node.parentNode.parentNode.querySelector('.username').innerText;
} else {
username = username.replace(/\s\(.+\)$/, '');
}
node.style.setProperty('background-image', 'url("' + getIdenticon(username, 48) + '")');
}
}
}
function replacePictures(path, full) {
let avatars = document.querySelectorAll(full
? '[src="https://rubukkit.org/styles/default/xenforo/avatars/avatar_' + path + '.png"]'
: '[src="styles/default/xenforo/avatars/avatar_' + path + '.png"]');
if (full) {
for (let avatar of avatars) avatar.src = getIdenticon(avatar.alt, 192);
} else {
for (let avatar of avatars) avatar.src = getIdenticon(avatar.alt, avatar.width);
}
}
function upgradeLinks() {
let nav = document.querySelector('nav div.navTabs ul.publicTabs');
let node = document.createElement('li');
node.className = 'navTab cust3 Popup PopupControl PopupClosed';
let news = document.createElement('a');
news.className = 'navLink';
news.href = '/forums/novosti-rubukkit.2/';
news.innerText = 'Объявления';
if (newsAlert) {
newsAlert = document.createElement('strong');
newsAlert.className = 'itemCount';
newsAlert.id = 'News_Counter';
newsAlert.innerHTML = '<span class="Total">!</span> <span class="arrow"></span>';
news.appendChild(newsAlert);
}
node.appendChild(news);
nav.insertBefore(node, nav.children[3].nextSibling);
new MutationObserver(function (mutations, observer) {
let drop = document.querySelectorAll('div#XenForoUniq0.Menu.JsOnly.tabMenu.cust2TabLinks ul.secondaryContent.blockLinksList li a');
if (drop.length < 3) {
return;
}
observer.disconnect();
drop[0].href = 'https://papermc.io/downloads/paper';
drop[1].href = 'https://www.spigotmc.org/resources/';
drop[2].text = 'Моды для Minecraft';
drop[2].href = 'https://modrinth.com/mods';
}).observe(document, {
childList: true,
subtree: true
});
}
function upgradeVideos() {
let objs = document.querySelectorAll('blockquote.messageText.SelectQuoteContainer.ugc.baseHtml object');
for (let i = 0; i < objs.length; i++) {
if (objs[i].type === 'application/x-shockwave-flash') {
let altObj = document.createElement('iframe');
altObj.src = objs[i].data.replace('/v/', '/embed/').replace('&fs=1', '?wmode=opaque');
altObj.width = objs[i].width;
altObj.height = objs[i].height;
altObj.setAttribute('allowfullscreen', '');
altObj.setAttribute('frameborder', '0');
objs[i].parentNode.replaceChild(altObj, objs[i]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment