Munzee Clanlink Replace

Replace Clanlinks

目前為 2019-11-11 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Munzee Clanlink Replace
// @namespace    https://greasyfork.org/users/156194
// @version      0.5
// @description  Replace Clanlinks
// @author       rabe85
// @match        https://www.munzee.com/m/*/*
// @match        https://www.munzee.com/settings
// @match        https://www.munzee.com/settings/*
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_deleteValue
// ==/UserScript==

(function() {
    'use strict';

    function munzee_clanlink_replace() {

        var clanlink_firstrun = GM_getValue('clanlink_firstrun', 1);

        if(clanlink_firstrun == 1) {

            function clanlink_firstrun_button0() {
                GM_setValue('clanlink_option', 0);
                GM_setValue('clanlink_firstrun', 0);
                location.reload();
            }
            function clanlink_firstrun_button1() {
                GM_setValue('clanlink_option', 1);
                GM_setValue('clanlink_firstrun', 0);
                location.reload();
            }
            function clanlink_firstrun_button2() {
                GM_setValue('clanlink_option', 2);
                GM_setValue('clanlink_firstrun', 0);
                location.reload();
            }
            function clanlink_firstrun_button3() {
                document.getElementById('clanlink_firstrun_input').setAttribute('style', 'display: inline;');
                var input_value = document.getElementById('clanlink_firstrun_input').value;
                GM_setValue('clanlink_option', 3);
                GM_setValue('clanlink_input', input_value);
                GM_setValue('clanlink_firstrun', 0);
                if(input_value) location.reload();
            }
            document.body.insertAdjacentHTML('afterbegin', '<div style="position: fixed;left: 0px;top: 0px;height: 100%;width: 100%;background-color: black;opacity: 0.9;z-index: 9999;text-align: center;"><div style="margin: 50px;color: white;font-size: x-large;">Munzee Clanlink Replace</div><div style="margin: 50px;color: white;font-size: larger;">Welcome, this addon will change the clanlink<br>at the profile page. Please choose an option.<br><br>You can change it whenever you want<br>at your profile settings page.</div><div><button id="clanlink_firstrun_button0"">Off (default link)</button><br><br><br><button id="clanlink_firstrun_button1">Clan Stats by RUJA</button><br><br><br><button id="clanlink_firstrun_button2">CuppaZee</button><br><br><br><button id="clanlink_firstrun_button3">Own Clanlink</button><br><br><input type="text" id="clanlink_firstrun_input" name="clanlink_firstrun_input" size="30" value="" style="display: none;"></div></div>');

            document.getElementById('clanlink_firstrun_button0').addEventListener('click', clanlink_firstrun_button0, false);
            document.getElementById('clanlink_firstrun_button1').addEventListener('click', clanlink_firstrun_button1, false);
            document.getElementById('clanlink_firstrun_button2').addEventListener('click', clanlink_firstrun_button2, false);
            document.getElementById('clanlink_firstrun_button3').addEventListener('click', clanlink_firstrun_button3, false);
            document.getElementById('clanlink_firstrun_input').addEventListener('change', clanlink_firstrun_button3, false);

        } else {

            var clanlink_option = GM_getValue('clanlink_option', 0);
            var clanlink_input = GM_getValue('clanlink_input', '');

            var page = document.getElementById('timezone');
            if(page) {
                function clanlink_input_speichern() {
                    GM_setValue('clanlink_input', document.getElementById('clanlink_input').value);
                }
                function clanlink_option_aendern() {
                    var clanlink_option_selected = document.getElementById('clanlink_option').value;
                    GM_setValue('clanlink_option', clanlink_option_selected);
                    if(clanlink_option_selected == 3) {
                        document.getElementById('clanlink_input_div').setAttribute('style', 'margin-bottom: 25px;');
                    } else {
                        document.getElementById('clanlink_input_div').setAttribute('style', 'margin-bottom: 25px; display: none;');
                    }
                }

                document.getElementById('distance_type').parentElement.parentElement.setAttribute('style', 'margin-bottom: 10px;');

                var clanlink_option0_selected = '';
                var clanlink_option1_selected = '';
                var clanlink_option2_selected = '';
                var clanlink_option3_selected = '';
                var clanlink_input_style = 'display: none;';
                if(clanlink_option == 0) { clanlink_option0_selected = 'selected="selected"'; }
                if(clanlink_option == 1) { clanlink_option1_selected = 'selected="selected"'; }
                if(clanlink_option == 2) { clanlink_option2_selected = 'selected="selected"'; }
                if(clanlink_option == 3) { clanlink_option3_selected = 'selected="selected"'; clanlink_input_style = ''; }

                var pos = document.getElementById('email_address').parentElement.parentElement;
                pos.setAttribute('style', 'margin-bottom: 10px;');
                pos.insertAdjacentHTML('afterend', '<div class="clearfix col-xs-12 col-md-6 setting-box" style="margin-bottom: 25px;"><label for="xxlInput">Clanlink Option</label><div class="input"><select name="clanlink_option" id="clanlink_option" class="form-control"><option value="0" ' + clanlink_option0_selected + '>Off (default link)</option><option value="1" ' + clanlink_option1_selected + '>Clan Stats by RUJA</option><option value="2" ' + clanlink_option2_selected + '>CuppaZee</option><option value="3" ' + clanlink_option3_selected + '>Own Clanlink</option></select></div></div><div class="clearfix col-xs-12 col-md-6 setting-box" id="clanlink_input_div" style="margin-bottom: 25px; ' + clanlink_input_style + '"><label for="xlInput">Own Clanlink</label><div class="input"><input class="form-control" id="clanlink_input" name="clanlink_input" size="30" type="text" value="' + clanlink_input + '"></div></div>');

                document.getElementById('clanlink_option').addEventListener('change', clanlink_option_aendern, false);
                document.getElementById('clanlink_input').addEventListener('input', clanlink_input_speichern, false);
            } else {
                if(clanlink_option == 1 || clanlink_option == 2 || clanlink_option == 3) {
                    var load_fancybox = 0;
                    var clanlink_replace0 = document.querySelectorAll('a[href^="/clans/"]');
                    for(var cr = 0, clanlink_replace; !!(clanlink_replace=clanlink_replace0[cr]); cr++) {
                        var link = '';
                        var teamname = '';
                        if(clanlink_option == 1) { // Clan Stats by RUJA
                            link = clanlink_replace.getAttribute('href');
                            if(link) {
                                teamname = link.split('/')[link.split('/').length - 2];
                                if(teamname) {
                                    clanlink_replace.setAttribute('href', 'javascript:;');
                                    clanlink_replace.setAttribute('title', 'Open Clanpage (external link)');
                                    clanlink_replace.setAttribute('data-fancybox', '');
                                    clanlink_replace.setAttribute('data-type', 'iframe');
                                    clanlink_replace.setAttribute('data-src', 'https://stats.munzee.dk/?clan_name=' + teamname);
                                    load_fancybox = 1;
                                }
                            }
                        } else {
                            if(clanlink_option == 2) { // CuppaZee
                                link = clanlink_replace.getAttribute('href');
                                if(link) {
                                    teamname = link.split('/')[link.split('/').length - 2];
                                    if(teamname) {
                                        clanlink_replace.setAttribute('href', 'javascript:;');
                                        clanlink_replace.setAttribute('title', 'Open Clanpage (external link)');
                                        clanlink_replace.setAttribute('data-fancybox', '');
                                        clanlink_replace.setAttribute('data-type', 'iframe');
                                        clanlink_replace.setAttribute('data-src', 'https://cuppazee.uk/clans/' + teamname);
                                        load_fancybox = 1;
                                    }
                                }
                            } else { // Own Clanlink
                                clanlink_replace.setAttribute('href', 'javascript:;');
                                clanlink_replace.setAttribute('title', 'Open Clanpage (external link)');
                                clanlink_replace.setAttribute('data-fancybox', '');
                                clanlink_replace.setAttribute('data-type', 'iframe');
                                clanlink_replace.setAttribute('data-src', clanlink_input);
                                load_fancybox = 1;
                            }
                        }
                    }

                    if(load_fancybox == 1) {
                        var load_fancybox_css = document.createElement('link');
                        load_fancybox_css.rel = 'StyleSheet';
                        load_fancybox_css.type = 'text/css';
                        load_fancybox_css.href = 'https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.css';
                        document.head.appendChild(load_fancybox_css);

                        var load_fancybox_script = document.createElement('script');
                        load_fancybox_script.src = 'https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.js';
                        document.body.appendChild(load_fancybox_script);
                    }
                }
            }
        }

    }


    // DOM vollständig aufgebaut?
    if (/complete|interactive|loaded/.test(document.readyState)) {
        munzee_clanlink_replace();
    } else {
        document.addEventListener("DOMContentLoaded", munzee_clanlink_replace, false);
    }

})();