Jump to content
Bonho

Кастомизируем форум юзерскриптом

Recommended Posts

7c0d0287af180baf398a232398b9e050.png
 
Убран правый блок, добавлен статус (онлайн\оффлайн), кол-во сообщений и репутация рядом с ником пользователя
 
1. Скачать расширение Tampermonkey (Chrome, Firefox)
 
2. Добавить туда скрипт
 

// ==UserScript==
// @name         valkyrie-wow Custom Script
// @version      1.1
// @author       bonho
// @match        https://*valkyrie-wow.org/forum*
// @grant        none
// @require http://code.jquery.com/jquery-latest.js
// ==/UserScript==
this.$ = this.jQuery = jQuery.noConflict(true);

(function() {
    'use strict';
	
    $('#index_stats').remove();
    $('#board_index').css('padding-right', '0px');
    $('.foot').remove();
    $('#footer_utilities').remove();

    function getUrlVars(url) {
        var vars = {};
        var parts = url.replace(/[?&]+([^=&]+)=([^&]*)/gi,
            function(m, key, value) {
                vars[key] = value;
            });
        return vars;
    }

    function addUserStat(id, online, stat) {
        var user_links = $('a[hovercard-id="' + id + '"]').each(function(k, userObj) {
            // console.log(userObj);
			//online status
			var online_circle = $("<div/>").css({
			    "width": "6px",
				"height": "6px",
				"-webkit-border-radius": "4px",
				"-moz-border-radius": "4px",
				"border-radius": "5px",
				"background": online ? "green" : "red",
				"display": "inline-block",
				"margin-left": "3px",
				"border": "2px solid #FFF",
				"box-shadow": "0 0 2px #888",
				"vertical-align": "middle",
				"opacity": online ? 0.8 : 0.3
			});
			$(userObj).append(online_circle);
			
			//stat
            var stat_span = $("<span/>").css({
                "font-size": "smaller",
                "font-weight": "bold",
                "padding-left": "3px",
                "opacity": 0.5,
				"vertical-align":"bottom"
            });
			stat_span.html(stat);
            $(userObj).append(stat_span);
        });
    }
    var member_ids = {};
    var member_links = $('a[hovercard-ref="member"]').each(function(k, v) {
        var href = $(v).attr('href');
        var user_id = (getUrlVars(href)).showuser;
        // console.log(user_id);
        member_ids[user_id] = null;
    });
    console.log('Found member links -', member_links.length, 'effective -', Object.keys(member_ids).length);
	$.each(member_ids, function( id, n ) {
		$.ajax({
		url: "https://valkyrie-wow.org/forum/index.php",
		type: "get", //send it through get method
		data: {
			app: 'members',
			module: 'ajax',
			secure_key: ipb.vars.secure_hash,
			section: 'card',
			mid: id
		},
		success: function(response) {
			var rep = $('.reputation', response).children().first().html();
			var msgs = $('dt:contains("Сообщений: ")', response).next().html();
			var online = $('span.ipsBadge_green', response).length == 1;
			console.log('id', id, 'rep', rep, 'msgs', msgs, 'online', online);
			addUserStat(id, online, msgs + ' [' + ((rep.indexOf('-') == -1 && parseInt(rep) > 0) ? '+' : '') + rep + ']');
		},
		error: function(xhr) {
			console.log('error', xhr);
		}
	});
	});
})();

 
3. Пожинать плоды
 
270cf393a8c64e3b367956ca4032170d.png
 
0fe3c1343e13c922def97d54c636c7dc.png
 
d8e7a4652aba4f4824f50ceede9ef5de.jpg

Share this post


Link to post
Share on other sites

Полезненько для начинающих. Старички же друг друга в лицо ник знают.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×