working on it ...

Filters

Explore Public Snippets

Sort by

Found 1 snippet matching: blazor

    external by Jasper van Merle  0  0  1  0

    Blazor Toolbox adds infinite scrolling to topics, aswell as the ability to make the shoutbox larger and smaller and send notifications when you get tagged or if someone whispers you.

    Blazor Toolbox adds infinite scrolling to topics, aswell as the ability to make the shoutbox larger and smaller and send notifications when you get tagged or if someone whispers you.: BlazorToolbox.user.js
    // ==UserScript==
    // @name         Blazor Toolbox
    // @namespace    BlazorToolbox
    // @version      1.0.0
    // @description  Blazor Toolbox adds infinite scrolling to topics, aswell as the ability to make the shoutbox larger and smaller and send notifications when you get tagged or if someone whispers you.
    // @author       Jasperr
    // @match        https://blazor.nl/*
    // @grant        none
    // ==/UserScript==
    
    var loadScript = function($) {
        var BlazorToolbox = {};
    
        BlazorToolbox.InfiniteScrolling = {};
        BlazorToolbox.InfiniteScrolling.init = function() {
            var requestingNewPage = false;
            var currentPage = parseInt($('.pagination li.active').first().text());
            if ($('.pagination li.next.disabled').length) {
                var totalPages = currentPage;
            } else {
                var totalPages = parseInt(/\?page=([0-9]+)/.exec($('.pagination li.last a').first().attr('href'))[1]);
            }
    
            if (currentPage < totalPages) {
                $('.pagination').first().parent().parent().removeClass('col-md-10 col-sm-10 col-xs-10').addClass('col-md-8 col-sm-8 col-xs-8');
                $('.pagination').first().parent().parent().next().removeClass('col-md-2 col-sm-2 col-xs-2').addClass('col-md-4 col-sm-4 col-xs-4');
                $('.pagination').first().parent().parent().next().append('<a id="blazor-toolbox-infinite-scroll-toggle" href="javascript:void(0)" type="button" class="btn btn-primary btn-sm pull-right" aria-label="Plaats een antwoord op dit topic"><i class="fa fa-magic"></i> <span class="hidden-xs">Infinite Scroll:</span> <span id="blazor-toolbox-infinite-scroll-state">OFF</span></a>');
                $('#blazor-toolbox-infinite-scroll-toggle').css('margin-right', '5px');
                if (localStorage.getItem('blazor-toolbox-infinite-scroll') == 'true') {
                    $('#blazor-toolbox-infinite-scroll-state').html('ON');
                }
                $('#blazor-toolbox-infinite-scroll-toggle').on('click', function() {
                    if (localStorage.getItem('blazor-toolbox-infinite-scroll') == 'true') {
                        localStorage.setItem('blazor-toolbox-infinite-scroll', 'false');
                        $('#blazor-toolbox-infinite-scroll-state').html('OFF');
                    } else {
                        localStorage.setItem('blazor-toolbox-infinite-scroll', 'true');
                        $('#blazor-toolbox-infinite-scroll-state').html('ON');
                    }
                });
                $('head').append($('<style>#blazor-toolbox-infinite-scroll-spinner{margin-top:10px;width:100%;height:40px;text-align:center;font-size:10px}#blazor-toolbox-infinite-scroll-spinner>div{background-color:' + $('.topic-footer').css('background-color') + ';height:100%;width:6px;display:inline-block;-webkit-animation:blazor-toolbox-infinite-scroll-sk-stretchdelay 1.2s infinite ease-in-out;animation:blazor-toolbox-infinite-scroll-sk-stretchdelay 1.2s infinite ease-in-out}#blazor-toolbox-infinite-scroll-spinner>div:not(:last-child){margin-right:5px}#blazor-toolbox-infinite-scroll-spinner .rect2{-webkit-animation-delay:-1.1s;animation-delay:-1.1s}#blazor-toolbox-infinite-scroll-spinner .rect3{-webkit-animation-delay:-1s;animation-delay:-1s}#blazor-toolbox-infinite-scroll-spinner .rect4{-webkit-animation-delay:-.9s;animation-delay:-.9s}#blazor-toolbox-infinite-scroll-spinner .rect5{-webkit-animation-delay:-.8s;animation-delay:-.8s}@-webkit-keyframes blazor-toolbox-infinite-scroll-k-stretchdelay{0%,100%,40%{-webkit-transform:scaleY(.4)}20%{-webkit-transform:scaleY(1)}}@keyframes blazor-toolbox-infinite-scroll-sk-stretchdelay{0%,100%,40%{transform:scaleY(.4);-webkit-transform:scaleY(.4)}20%{transform:scaleY(1);-webkit-transform:scaleY(1)}}</style>'));
                $('.util-bar').last().after($('<div id="blazor-toolbox-infinite-scroll-spinner"><div class="rect1"></div><div class="rect2"></div><div class="rect3"></div><div class="rect4"></div><div class="rect5"></div></div>'));
                $('#blazor-toolbox-infinite-scroll-spinner').css('margin-bottom', '5px');
                $('#blazor-toolbox-infinite-scroll-spinner').hide();
                $(window).on('scroll', function() {
                    if ($(window).scrollTop() >= $('.util-bar').last().offset().top + $('.util-bar').last().outerHeight() - window.innerHeight + 150) {
                        if (!requestingNewPage && currentPage < totalPages && localStorage.getItem('blazor-toolbox-infinite-scroll') == 'true') {
                            requestingNewPage = true;
                            $('#blazor-toolbox-infinite-scroll-spinner').show();
                            $.ajax(window.location.origin + window.location.pathname + '?page=' + (currentPage + 1), {
                                statusCode: {
                                    200: function(data) {
                                        $('#posts').append($('#posts', data).children());
                                        currentPage++;
                                        $('#blazor-toolbox-infinite-scroll-spinner').hide();
                                        requestingNewPage = false;
                                    }
                                }
                            });
                        }
                    }
                });
            }
        };
    
        BlazorToolbox.EnhancedShoutbox = {};
        BlazorToolbox.EnhancedShoutbox.addHandle = function() {
            $('#chatbox').after('<div id="enhanced-shoutbox-bottom-border" style="display:block;height:20px;background-color:rgba(0,0,0,0.0);cursor:s-resize;"></div>');
            $('#chatbox').css('margin-bottom', '0px');
            $('#chatbox').parent().css('padding-bottom', '0px');
            $('#enhanced-shoutbox-bottom-border').on('mousedown', function(event) {
                var draggable = $('#chatbox');
                var startHeight = draggable.height();
                var pY = event.pageY;
                $(document).on('mouseup', function() {
                    $(document).off('mouseup').off('mousemove');
                    localStorage.setItem('enhanced-shoutbox-height', draggable.css('height'));
                });
                $(document).on('mousemove', function(event) {
                    var my = (event.pageY - pY);
                    draggable.css({
                        'height': startHeight + my
                    });
                });
            });
            if (localStorage.getItem('enhanced-shoutbox-height')) {
                $('#chatbox').css('height', localStorage.getItem('enhanced-shoutbox-height'));
            }
        };
    
        BlazorToolbox.EnhancedShoutbox.addNotifications = function() {
            $('.pull-right', $('#toggleChat').prev()).prepend('<a id="enhanced-shoutbox-notification-on-tag-link" href="javascript:void(0)">• Notification on tag: <span id="enhanced-shoutbox-notification-on-tag-state">OFF</span></a> ');
            if (localStorage.getItem('enhanced-shoutbox-notification-on-tag') == 'true') {
                Notification.requestPermission().then(function(result) {
                    if (result != 'granted') {
                        localStorage.setItem('enhanced-shoutbox-notification-on-tag', 'false');
                    } else {
                        $('#enhanced-shoutbox-notification-on-tag-state').html('ON');
                    }
                });
            }
            $('#enhanced-shoutbox-notification-on-tag-link').on('click', function() {
                if (localStorage.getItem('enhanced-shoutbox-notification-on-tag') == 'true') {
                    localStorage.setItem('enhanced-shoutbox-notification-on-tag', 'false');
                    $('#enhanced-shoutbox-notification-on-tag-state').html('OFF');
                } else {
                    Notification.requestPermission().then(function(result) {
                        if (result == 'granted') {
                            localStorage.setItem('enhanced-shoutbox-notification-on-tag', 'true');
                            $('#enhanced-shoutbox-notification-on-tag-state').html('ON');
                        } else {
                            alert("U heeft het verzenden van desktop notificaties geblokkeerd! Als u deze functie toch nog wilt gebruiken zult u desktop notificaties handmatig aan moeten zetten!");
                        }
                    });
                }
            });
    
            $('.pull-right', $('#toggleChat').prev()).prepend('<a id="enhanced-shoutbox-notification-on-whisper-link" href="javascript:void(0)">Notification on Whisper: <span id="enhanced-shoutbox-notification-on-whisper-state">OFF</span></a> ');
            if (localStorage.getItem('enhanced-shoutbox-notification-on-whisper') == 'true') {
                Notification.requestPermission().then(function(result) {
                    if (result != 'granted') {
                        localStorage.setItem('enhanced-shoutbox-notification-on-whisper', 'false');
                    } else {
                        $('#enhanced-shoutbox-notification-on-whisper-state').html('ON');
                    }
                });
            }
            $('#enhanced-shoutbox-notification-on-whisper-link').on('click', function() {
                if (localStorage.getItem('enhanced-shoutbox-notification-on-whisper') == 'true') {
                    localStorage.setItem('enhanced-shoutbox-notification-on-whisper', 'false');
                    $('#enhanced-shoutbox-notification-on-whisper-state').html('OFF');
                } else {
                    Notification.requestPermission().then(function(result) {
                        if (result == 'granted') {
                            localStorage.setItem('enhanced-shoutbox-notification-on-whisper', 'true');
                            $('#enhanced-shoutbox-notification-on-whisper-state').html('ON');
                        } else {
                            alert("U heeft het verzenden van desktop notificaties geblokkeerd! Als u deze functie toch nog wilt gebruiken zult u desktop notificaties handmatig aan moeten zetten!");
                        }
                    });
                }
            });
    
            var triggeredIDs = [];
            var username = $.trim($('.navbar-link[href^="/user-"]').text());
            $(document).ajaxComplete(function(event, xhr, settings) {
                if (settings.url.indexOf('/xmlhttp/chat/?after=') != -1 &&
                    settings.url.indexOf('/xmlhttp/chat/?after=0') === -1 &&
                    (localStorage.getItem('enhanced-shoutbox-notification-on-tag') === 'true' || localStorage.getItem('enhanced-shoutbox-notification-on-whisper') === 'true') &&
                    !document.hasFocus()) {
                    var data = $.parseJSON(xhr.responseText);
                    if (data.response.messages) {
                        $.each(data.response.messages, function(index, msg) {
                            if ($.inArray(msg.message.id, triggeredIDs) === -1) {
                                if (new RegExp('&#64;<strong><a class=\'(.*)\' href=\'\/user-' + username + '\'>' + username + '<\/a>').exec(msg.message.content) &&
                                    localStorage.getItem('enhanced-shoutbox-notification-on-tag') === 'true') {
                                    var messageText = $('<div/>').html(($.trim(msg.message.content.replace(/<strong>Whisper: <\/strong>/, '')))).text();
                                    var n = new Notification('BlazorToolbox Enhanced Shoutbox', {
                                        body: msg.user.username + ' zegt' + (new RegExp('<strong>Whisper: <\/strong>(.*)').exec(msg.message.content) ? ' in whisper' : '') + ':\n' + messageText,
                                        icon: 'http://i.imgur.com/BstqZZn.png',
                                        lang: 'nl-NL'
                                    });
                                    n.onclick = function() {
                                        try {
                                            window.focus();
                                            this.close();
                                        } catch (e) {};
                                    };
                                } else if (new RegExp('<strong>Whisper: <\/strong>(.*)').exec(msg.message.content) && localStorage.getItem('enhanced-shoutbox-notification-on-whisper') === 'true') {
                                    var messageText = $('<div/>').html(($.trim(msg.message.content.replace(/<strong>Whisper: <\/strong>/, '')))).text();
                                    var n = new Notification('BlazorToolbox Enhanced Shoutbox', {
                                        body: msg.user.username + ' zegt in whisper:\n' + messageText,
                                        icon: 'http://i.imgur.com/BstqZZn.png',
                                        lang: 'nl-NL'
                                    });
                                    n.onclick = function() {
                                        try {
                                            window.focus();
                                            this.close();
                                        } catch (e) {};
                                    };
                                }
                                triggeredIDs.push(msg.message.id);
                            }
                        });
                    }
                }
            });
        };
    
        if (window.location.pathname.indexOf('/threads/') !== -1 && $('.pagination').length) {
            BlazorToolbox.InfiniteScrolling.init();
        }
    
        if ($('#chatbox').length) {
            BlazorToolbox.EnhancedShoutbox.addHandle();
            if ('Notification' in window) {
                BlazorToolbox.EnhancedShoutbox.addNotifications();
            }
        }
    };
    
    function checkForJquery() {
        if (!window.jQuery) {
            setTimeout(checkForJquery, 250);
        } else {
            loadScript(jQuery);
        }
    }
    
    checkForJquery();
    
    

    List Complete ( 1 snippet total )

    Cannot find what you were looking for?
    Ask the Snip2Code Community

    • Public Snippets
    • Channels Snippets