FANDOM


//docs | reference
(function (ns) { // namespace module
 
    var threads = wgCanonicalNamespace == "Thread" || wgCanonicalNamespace == "Message_Wall";
 
    ns.isMessageWall = function () {
        return threads;
    }
 
    ns.escapeName = function (name) {
        return encodeURIComponent(name.replace(/ /, '_'));
    };
 
    ns.unescapeName = function (name) {
        return decodeURIComponent(name.replace(/_/, ' '));
    };    
 
}(window.ThreadTools = window.ThreadTools || {}));
 
(function (ns) { // module "Storage"
 
    var staleEntries = (new Date(Date.now() - 6 * 30 * 24 * 60 * 60 * 1000)).valueOf(); // six months
    //var staleEntries = (new Date(Date.now() - 2 * 60 * 1000)).valueOf(); // 2 minutes (for testing purposes)
 
    var users = $.extend([], {
 
        save: function () {
            if (this.length) {
                localStorage.setItem('ThreadTools_users', $.toJSON(this));
            } else {
                localStorage.removeItem('ThreadTools_users');
            }
        },
 
        load: function () {
            if (!this.length) {
                var users = $.evalJSON(localStorage.getItem('ThreadTools_users')) || [];
                for (var i = 0; i < users.length; i++) {
                    if (users[i].date > staleEntries) {
                        this.push(users[i]);
                    }
                }
                this.save();
            }
            return this;
        },
 
        add: function (user) {
            user = ns.unescapeName(user);
            for (var i = 0; i < this.length; i++) {
                if (user == this[i].user) {
                    this[i].date = Date.now().valueOf();
                    this.save();
                    return;
                }
            }
            this.push({ user: user, date: Date.now().valueOf() });
            this.save();
        },
 
        rem: function (user) {
            user = ns.unescapeName(user);
            for (var i = 0; i < this.length; i++) {
                if (user == this[i].user) {
                    this.splice(i, 1);
                    break;
                }
            }
            this.save();
        }
 
    }).load();
 
    var lastVisit;
 
    var pages = $.extend([], {
 
        save: function () {
            localStorage.setItem('ThreadTools_pages', $.toJSON(this));
        },
 
        load: function () {
            var pages = $.evalJSON(localStorage.getItem('ThreadTools_pages')) || [];
            var pageId = ns.isMessageWall() ? wgTitle : wgArticleId;
            var currentPage = false;
 
            for (var i = 0; i < pages.length; i++) {
                if (pages[i].id == pageId) {
                    currentPage = pages[i];
                    lastVisit = currentPage.date;
                    if (!currentPage.posts) currentPage.posts = [];
                    if (!currentPage.threads) currentPage.threads = [];
                    currentPage.date = Date.now().valueOf();
                    this.push(pages[i]);
                } else if (pages[i].date > staleEntries) {
                    if (pages[i].posts && !pages[i].posts.length) delete pages[i].posts;
                    if (pages[i].threads && !pages[i].threads.length) delete pages[i].threads;
                    this.push(pages[i]);
                }
            }
 
            if (!currentPage) {
                currentPage = {
                    id: pageId,
                    date: Date.now().valueOf(),
                    isWall: ns.isMessageWall(),
                    posts: [],
                    threads: []
                };
                lastVisit = Date.now().valueOf();
                this.push(currentPage);
            }
 
            this.getPage = function () {
                return currentPage;
            };
 
            var extendList = function (pages) {
                return {
 
                    toString: function (item) {
                        if (!this.length) return '';
                        if (ns.isMessageWall()) {
                            return 'li[data-id="' + this.join('"], li[data-id="') + '"]';
                        } else {
                            return 'li#comm-' + this.join(', li#comm-');
                        }
                    },
 
                    add: function (item) {
                        item = item.toString().replace(/\D+/, '');
                        var i = this.indexOf(item);
                        if (-1 < i) return;
                        this.push(item);
                        pages.save();
                    },
 
                    rem: function (item) {
                        var i = this.indexOf(item.toString().replace(/\D+/, ''));
                        if (-1 == i) return;
                        this.splice(i, 1);
                        pages.save();
                    }
                };
            }
            $.extend(currentPage.posts, extendList(this));
            $.extend(currentPage.threads, extendList(this));
 
            this.save();
            return this;
        }
 
    }).load();
 
    function getUnreadPosts () {
        var unread = $('');
        if (ns.isMessageWall()) {
            $('.timeago', 'ul.comments').each(function () {
                if (Date.parse($(this).attr('title')) > lastVisit) {
                    unread = unread.add($(this).parents('li.SpeechBubble:first'));
                }
            });
        } else {
            $('.permalink', 'ul.comments').each(function () {
                var m = $(this).attr('href').match(/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})\?/);
                if (m) {
                    m.splice(0, 1);
                    m[1]--;  // months are zero based in JavaScript
                    if (new Date(Date.UTC.apply(this, m)) > lastVisit) {
                        unread = unread.add($(this).parents('li.SpeechBubble:first'));
                    }
                }
            });
        }
        return unread;
    }
 
    function getPlonkedPosts () {
        var collapsed = $(''), plonked = [];
        for (i = 0; i < users.length; i++) {
            plonked.push(users[i].user);
        }
        if (ns.isMessageWall()) {
            $('div.edited-by a', 'ul.comments').each(function () {
                if (-1 < plonked.indexOf($(this).text())) {
                    collapsed = collapsed.add($(this).parents('li:first'));
                }
            });
        } else {
            $('li.SpeechBubble').each(function () {
                if (-1 < plonked.indexOf($(this).attr('data-user'))) {
                    collapsed = collapsed.add($(this));
                }
            });
        }
        return collapsed;
    }
 
    function getCollapsedPosts () {
        return $(pages.getPage().posts.toString());
    }
 
    function getCollapsedThreads () {
        return $(pages.getPage().threads.toString());
    }
 
    ns.Storage = {
 
        addPost:   function (post) { pages.getPage().posts.add(post); },
        remPost:   function (post) { pages.getPage().posts.rem(post); },
 
        addThread: function (thread) { pages.getPage().threads.add(thread); },
        remThread: function (thread) { pages.getPage().threads.rem(thread); },
 
        addUser:   function (user) { users.add(user); },
        remUser:   function (user) { users.rem(user); },
 
        getUnreadPosts:      getUnreadPosts,
        getPlonkedPosts:     getPlonkedPosts,
        getCollapsedPosts:   getCollapsedPosts,
        getCollapsedThreads: getCollapsedThreads
 
        ,users: users, pages: pages        
    };
 
}(window.ThreadTools = window.ThreadTools || {}));
 
(function (ns) { // module "Stylesheet"
 
    /*
     * Function:	setThreadToolsMonobookCSS()
     * 
     * Description:	Appends CSS to <head> -- Monobook skin only
     */
    function setThreadToolsMonobookCSS () {
 
        if (ns.isMessageWall()) {
            // CSS , Monobook , Message Wall
            $(document.head).append(
            '<style id="thread-tools" type="text/css">' +
            '.threadButton { ' +
                ' display: none; float: none !important; position: absolute; top: -5px;' +
                ' margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; font-size: 11px;' +
                ' height: 21px; width: 75px; line-height: 15px; left: 15px; cursor: pointer;' +
            '}' +
            '.toggleUser {' +
                ' left: 105px;' +
            '}' +
            '.toggleThread {' +
                ' left: 195px;' +
            '}' +
            '.speech-bubble-message {' +
                'position: relative;' +
            '}' +
            '.speech-bubble-message:hover .threadButton {' +
                ' display: block;' +
            '}' +
            '.threadButton:hover {' +
                ' display: block; width: 81px; height: 25px; top: -7px;'+
                ' line-height: 19px; margin-left: -3px' +
            '}' +
            '.msg-title {' +
                'padding-top: 7px;' +
            '}' +
            'li.message > .speech-bubble-message {' +
                'top: -10px; padding-top: 10px;' +
            '}' +
            '</style>');
        } else {
            // CSS , Monobook , Article Comments
            $(document.head).append(
            '<style id="thread-tools" type="text/css">' +
            '.threadButton { ' +
                ' display: none; float: none !important; position: absolute; top: -5px;' +
                ' margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; font-size: 11px;' +
                ' height: 21px; width: 75px; line-height: 15px; left: 15px; cursor: pointer;' +
            '}' +
            '.toggleUser {' +
                ' left: 105px;' +
            '}' +
            '.toggleThread {' +
                ' left: 195px;' +
            '}' +
            '.speech-bubble-message {' +
                'position: relative;' +
            '}' +
            '.speech-bubble-message:hover .threadButton {' +
                ' display: block;' +
            '}' +
            '.threadButton:hover {' +
                ' display: block; width: 81px; height: 25px; top: -7px;'+
                ' line-height: 19px; margin-left: -3px' +
            '}' +
            '</style>');
 
            // Push stuff down to make additional room for the buttons
            $('div.article-comm-text').css('top', '-12px').css('padding-top', '12px');
        }
    }
 
    /*
     * Function:	setThreadToolsOasisCSS()
     *
     * Description:	Appends CSS to <head> -- Oasis skin only
     */
    function setThreadToolsOasisCSS () {
 
        if (ns.isMessageWall()) {
            // CSS , Oasis , Message Wall
            $(document.head).append(
            '<style id="thread-tools" type="text/css">' +
            '.threadButton { ' +
                ' display: none; float: none !important; position: absolute; top: -5px;' +
                ' margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; font-size: 11px;' +
                ' height: 18px; width: 90px; line-height: 15px;' +
            '}' +
            '.toggleUser {' +
                ' left: 120px;' +
            '}' +
            '.toggleThread {' +
                ' left: 225px;' +
            '}' +
            '.speech-bubble-message:hover .threadButton {' +
                ' display: block;' +
            '}' +
                '.threadButton:hover {' +
            ' display: block; width: 96px; height: 22px; top: -7px;'+
                ' line-height: 19px; margin-left: -3px' +
            '}' +
            '.msg-title {' +
                'padding-top: 5px;' +
            '}' +
            'li.message > .speech-bubble-message {' +
                'top: -12px; padding-top: 12px;' +
            '}' +
            '</style>');
        } else {
            // CSS , Oasis , Article Comments
            $(document.head).append(
            '<style id="thread-tools" type="text/css">' +
            '.threadButton { ' +
                ' display: none; float: none !important; position: absolute; top: -5px;' +
                ' margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; font-size: 11px;' +
                ' height: 18px; width: 90px; line-height: 15px;' +
            '}' +
            '.toggleUser {' +
                ' left: 120px;' +
            '}' +
            '.toggleThread {' +
                ' left: 225px;' +
            '}' +
            '.speech-bubble-message:hover .threadButton {' +
                ' display: block;' +
            '}' +
                '.threadButton:hover {' +
            ' display: block; width: 96px; height: 22px; top: -7px;'+
                ' line-height: 19px; margin-left: -3px' +
            '}' +
            '</style>');
        }
    }
 
    var add  = function () {
        $('#thread-tools').remove();
        switch (skin) {
            case 'monobook':
                setsetThreadToolsMonobookCSS();
                break;
            case 'oasis':
                setThreadToolsOasisCSS();
                break;
        }
    };
 
    ns.Stylesheet = {
        add: add
    }
 
    $(function () { add(); });
 
}(window.ThreadTools = window.ThreadTools || {}));
 
(function (ns) { // module "ToggleButtons"
 
    // Text displayed for the various thread buttons
    var buttonTexts = {
        toggleComment: {
            true: 'Hide Post', false: 'Show Post'
        },
        toggleUser: {
            true: 'Hide User', false: 'Show User'
        },
        toggleThread: {
            true: 'Hide Thread', false: 'Show Thread'
        }
    };
 
    // create HTML string required to create a button
    function createButton (className) {
        return '<button class="threadButton ' + className + ' wikia-button secondary" type="button">'
            + buttonTexts[className][true] +
            '</button>';
    }
 
    function add () {
 
        $('.threadButton').remove();
 
        // Add thread buttons to the DOM
        if (ns.isMessageWall()) {
            $('li.message > .speech-bubble-message')
            .prepend(
                createButton('toggleComment') + createButton('toggleUser') + createButton('toggleThread')
            );
        } else {
            $('.speech-bubble-message')
            .prepend(
                createButton('toggleComment') + createButton('toggleUser') + createButton('toggleThread')
            );
        }        
 
        $('.threadButton')
        .data({
            on: true,
        })
        .click(function () {
            var on = !$(this).data('on');
            $(this).data('on', on)
            .text(function () {
                for (var i in buttonTexts) {
                    if ($(this).hasClass(i)) {
                        return buttonTexts[i][on];
                    }
                }
            })
            .trigger('toggleButton');
        });
 
        // Toggle Thread handler
        $('.toggleThread')
        .on('toggleButton', function () {
            console.log(
                ($(this).data('on') ? 'showing' : 'hiding') + ' thread'
            );
        });
 
        // Toggle User handler
        $('.toggleUser')
        .on('toggleButton', function () {
            console.log(
                ($(this).data('on') ? 'showing' : 'hiding') + ' user'
            );
        });
 
        // Toggle Comment handler
        $('.toggleComment')
        .on('toggleButton', function () {
            console.log(
                ($(this).data('on') ? 'showing' : 'hiding') + ' post'
            );
 
            // temporary functionality, testing purposes
            if (ns.isMessageWall()) {
                $(this).siblings('.MiniEditorWrapper').find('.editarea').css('display', $(this).data('on') ? 'block' : 'none' );
            } else {
                $(this).siblings('.article-comm-text').css('display', $(this).data('on') ? 'block' : 'none' );
            }
        });
    }
 
    ns.ToggleButtons = {
        add: add
    };
 
    $(function () { add(); });
 
}(window.ThreadTools = window.ThreadTools || {}));
 
(function (ns) { // module "ViewSource"
 
    function add () {
 
        // Add "Source" button to "More" dropdown (Message Wall only):
        if (ns.isMessageWall()) {
 
            $('a.view-source', '#Wall').remove();
 
            $('.buttonswrapper ul', '#Wall')
            .append('<li><a class="view-source" href="#"> Source </a></li>');
 
            // Log source to console:
            $('a.view-source', '#Wall')
            .click(function (e) {
                e.preventDefault();
                var id = $(this).parents('li.SpeechBubble:first').attr('data-id');
                $.get(wgServer + wgScript + '?curid=' + id + '&action=raw', function (data) {
                    var m; if (m = data.match(/(.+)\<ac_metadata\s+title="([^"]+)"/)) {
                        console.log(m[1]);
                    } else {
                        console.log(data);
                    }
                });
            });
 
        // Add bracket pictogram and "source" link to article commments:
        } else {
 
            $('.view-source', '#article-comments-ul').remove();
 
            console.log('adding view source buttons');
 
            $('.tools', '#article-comments-ul')
            .prepend(
                '<img width="14" height="16" src="data:image/gif;base64,R0lGODlhDgAQAKIHAMfFy1VQZhsXLUU0lxgHaBQITC8fdQAAACH5BAEAAAcALAAAAAAOABAAAANJCKpxtyyQUkxxwVYhi/jOJxQENwlOemRTh6qrUUolHM9EDbOmrvK010/WE6aAOSOGGLQhPU7mxABoOBiUwXTwCgwsJZEoJBYkAAA7" alt="" />' +
                '<a class="view-source" href="#">source</a>'
            );
 
            // Log source to console:
            $('.view-source', '#article-comments-ul')
            .click(function (e) {
                e.preventDefault();
                var m, text = $(this).parents('.speech-bubble-message:first').children('.article-comm-text');
                if (m = text.attr('id').match(/\d+$/)) {
                    $.get(wgServer + wgScript + '?curid=' + m.pop() + '&action=raw', function (data) {
                        console.log(data);
                    });
                }
            });
        }
    }
 
    ns.ViewSource = {
        add: add
    }
 
}(window.ThreadTools = window.ThreadTools || {}));
 
$(function () {
 
    if (window.localStorage && $('ul.comments li')) {
 
        // Reload ThreadTools when article comments paginate:
        if (window.ArticleComments && ArticleComments.addHover) {
            ArticleComments.addHoverOverride = ArticleComments.addHover;
            ArticleComments.addHover = function () {
                ArticleComments.addHoverOverride();
                ThreadTools.ToggleButtons.add();
                ThreadTools.ViewSource.add();
            }
        }
 
        ThreadTools.Stylesheet.add();
        ThreadTools.ToggleButtons.add();
        ThreadTools.ViewSource.add();
    }
});
 
//

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.