oldFUP

ignore, old-style citation, remove new features

Fra 28.11.2014. Se den seneste versjonen.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        oldFUP
// @namespace   http://forum.pravda.com.ua
// @version     0.1
// @description ignore, old-style citation, remove new features
// @match       http://forum.pravda.com.ua/index.php?board*
// @match       http://forum.pravda.com.ua/index.php?topic*
// @grant       GM_getValue
// @grant       GM_setValue
// @copyright   2014+, forum.pravda.com.ua
// @author		тарадайка
// ==/UserScript==

(function ignore(dialog) {

    var ignored,

        load = function () {
            ignored = [];
            var str = GM_getValue('FUP_IGNORED', '');
            if (str !== '')
                try {
                    ignored = JSON.parse(str);
                } catch (error) {
                    console.error("Ігнор список пошкоджено: ", error);
                }
        },

        save = function () {
            GM_setValue('FUP_IGNORED', JSON.stringify(ignored));
        },

        getUserIndex = function (name) {
            for (var i = 0; i < ignored.length; i++)
                if (ignored[i].name == name)
                    return i;
            return -1;
        },

        createLink = function (id, innerHTML, title, target) {
            var result = document.createElement('a');
            result.style.cursor = 'pointer';
            result.id = id;
            result.innerHTML = innerHTML;
            result.title = title;
            if (typeof target == 'string')
                result.href = target;
            else
                result.addEventListener('click', target);
            return result;
        },

        updateDialog = function () {
            if (dialog.style.display != 'inline')
                return;
            while (dialog.firstChild)
                dialog.removeChild(dialog.firstChild);
            load();
            if (ignored.length === 0)
                dialog.appendChild(document.createElement('div')).innerHTML = '(пусто)';
            else
                for (i = 0; i < ignored.length; i++) {
                    var userDiv = document.createElement('div');
                    var userLink = createLink(null, ignored[i].name, 'Перегляд профілю ' + ignored[i].name, ignored[i].profile);
                    userDiv.appendChild(userLink);
                    userDiv.appendChild(createToggleButton(userLink, false));
                    dialog.appendChild(userDiv);
                }
        },

        createToggleButton = function (userLink, toIgnore) {
            var result = createLink(null, 'x', toIgnore ? 'Ігнорувати ' : 'Не ігнорувати ' + userLink.innerHTML,
                function () {
                    load();
                    var ignoredIndex = getUserIndex(userLink.innerHTML);
                    if (toIgnore == (ignoredIndex == -1)) {
                        if (toIgnore)
                            ignored.push({profile: userLink.href, name: userLink.innerHTML});
                        else
                            ignored.splice(ignoredIndex, 1);
                        save();
                        ignore(dialog);
                        updateDialog();
                    }
                }
            );
            result.style.fontWeight = 'normal';
            result.style.paddingLeft = toIgnore ? '5px' : '9px';
            return result;
        };

    load();
    if (document.location.href.indexOf('board') !== -1) {
        var i, topicRows = document.getElementsByClassName('list')[0].rows;
        for (i = 1; i < topicRows.length; i++) {
            var autherLink = topicRows[i].cells[3].getElementsByTagName('a')[0];
            if (dialog == null) {
                topicRows[i].cells[3].appendChild(createToggleButton(autherLink, true));
                var lastWriterLink = topicRows[i].cells[4].getElementsByTagName('a')[1];
                topicRows[i].cells[4].appendChild(createToggleButton(lastWriterLink, true));
            }
            topicRows[i].style.display = getUserIndex(autherLink.innerHTML) == -1 ? 'table-row' : 'none';
        }
    } else {
        var postDivs = document.getElementsByClassName('message');
        for (i = 0; i < postDivs.length; i++) {
            var userLink = postDivs[i].getElementsByTagName('a')[1];
            if (dialog == null) {
                var userDiv = postDivs[i].getElementsByClassName('message-author icon-user')[0];
                userDiv.insertBefore(createToggleButton(userLink, true), userDiv.children[1]);
            }
            postDivs[i].style.display = getUserIndex(userLink.innerHTML) == -1 ? 'inline' : 'none';
        }
    }
    if (dialog == null) {
        dialog = document.createElement('div');
        var container = document.getElementById('user-info');
        container.innerHTML += " » ";
        var link = createLink('ignored-link', 'Ігноровані', 'Показати/сховати',
            function () {
                dialog.style.display = dialog.style.display == 'none' ? 'inline' : 'none';
                updateDialog();
            }
        );
        container.appendChild(link);
        dialog.style.display = 'none';
        dialog.style.position = 'fixed';
        dialog.style.textAlign = 'left';
        dialog.style.width = '150px';
        dialog.style.padding = '5px';
        dialog.style.border = '1px solid black';
        dialog.style.backgroundColor = 'white';
        container.appendChild(dialog);
        var linkRect = link.getBoundingClientRect();
        dialog.style.left = linkRect.right - 158 + 'px';
        dialog.style.top = linkRect.bottom + 'px';
    }
})(null);

var postDivs = document.getElementsByClassName('message');

var cite = function(userLink, textDiv) {

    return function() {

        var lines = window.getSelection().toString() === ''
        	? textDiv.innerText.split('\n')
	        : window.getSelection().toString().split('\n');
        
        var text = '> ' + userLink.innerText + ':\n';

        for(i = 0; i < lines.length; i++) {
        	text += '> ' + lines[i] + '\n';
        }

        document.getElementById('body').innerHTML += text;
    }
};

for (i = 0; i < postDivs.length; i++) {
    var userLink = postDivs[i].getElementsByTagName('a')[1];
    var messageDiv = postDivs[i].getElementsByClassName('message-body')[0];
    var textDiv = messageDiv.getElementsByClassName('msg')[0];
    var buttonsHolder = messageDiv.getElementsByClassName('message-options')[0].childNodes[1].childNodes[1].childNodes[0].childNodes[1];
    messageDiv.getElementsByClassName('message-options')[0].childNodes[1].childNodes[1].childNodes[0].removeChild(messageDiv.getElementsByClassName('message-options')[0].childNodes[1].childNodes[1].childNodes[0].childNodes[2]);

    var citeButton = document.createElement('a');
    citeButton.style.cursor = 'pointer';    
	citeButton.innerHTML = '>>>';
    citeButton.title = 'цитувати ' + userLink.innerText;
    citeButton.addEventListener('mousedown', cite(userLink, textDiv));
    
    var scrollDownButton = document.createElement('a');
    scrollDownButton.style.cursor = 'pointer';    
	scrollDownButton.innerHTML = 'VVV';
    scrollDownButton.title = 'до редагування';
    scrollDownButton.addEventListener('mousedown', function() { document.getElementById('body').scrollIntoView(true); });
        
    scrollDownButton.style.paddingRight = '10px';
    citeButton.style.paddingRight = '10px';

    buttonsHolder.insertBefore(scrollDownButton, buttonsHolder.children[0]);
    buttonsHolder.insertBefore(citeButton, buttonsHolder.children[0]);
    //buttonsHolder.removeChild(buttonsHolder.children[2]);
    //buttonsHolder.removeChild(buttonsHolder.children[2]);
    
}