Advertisement
Ansolley

Plugin - Platoon Dropdown

Jun 28th, 2019
2,101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 8.88 KB | None | 0 0
  1. /**
  2. * Platoon Dropdown:
  3. *  - adds a platoon dropdown menu
  4. *
  5. * @author dapil
  6. * @version 3.0
  7. * @url http://dapil.github.io/platoon-dropdown-bblog/platoon-dropdown.js
  8. * @last-edit 21. 9. 2014 21:50
  9. */
  10.  
  11. BBLog.handle("add.plugin", {
  12. id : "platoon-dropdown",
  13. name : "Platoon Dropdown",
  14.    
  15. configFlags : [
  16.             ["plugin.description", 1, function(instance){instance.AddPlatoonDropdownSettings(instance);}],
  17.     ],
  18.  
  19. translations : {
  20.         "en" : {
  21.             "plugin.description" : "Manage displayed platoons",
  22.             "text.description" : "Here you can choose which platoons will be displayed. You can get the Platoon ID from the URL of its page, for example: in http://battlelog.battlefield.com/bf3/en/platoon/2832655241424190855/, the ID is <strong>2832655241424190855</strong>.",
  23.             "button.add" : "Add",
  24.             "hint.name" : "Displayed name",
  25.             "hint.id" : "Platoon ID",
  26.          },
  27.         "cs" : {
  28.             "plugin.name" : "Vyjížděcí menu pro čety",
  29.             "plugin.description" : "Spravovat zobrazené čety",
  30.             "text.description" : "Zde můžete určit, které čety se budou zobrazovat. ID čety můžete získat z URL stránky čety, například pro http://battlelog.battlefield.com/bf3/cs/platoon/2832655241424190855/ je ID <strong>2832655241424190855</strong>.",
  31.             "button.add" : "Přidat",
  32.             "hint.name" : "Zobrazované jméno",
  33.             "hint.id" : "ID čety",            
  34.         },
  35.         "fr" : {
  36.             "plugin.description" : "GESTION DES SECTIONS",
  37.             "text.description" : "Vous pouvez choisir quelle section sera affiché en prenant l'ID de la section suivant l'exemple ci-dessous: http://battlelog.battlefield.com/bf3/en/platoon/2832655241424190855/ ID SECTION : 2832655241424190855.",
  38.             "button.add" : "AJOUTER LA SECTION",
  39.             "hint.name" : "AFFICHER LE NOM DE LA SECTION",
  40.             "hint.id" : "ID DE LA SECTION",
  41.         },
  42.         "pt" : {
  43.             "plugin.description" : "Gerenciar Tropas exibidas",
  44.             "text.description" : "Aqui você pode escolher quais tropas serão exibidas. Você pode obter o ID de uma tropa na URL da seguinte página, por exemplo: http://battlelog.battlefield.com/bf3/en/platoon/2832655241424190855/, o ID é <strong>2832655241424190855</strong>.",
  45.             "button.add" : "Adicionar",
  46.             "hint.name" : "Nome Exibido",
  47.             "hint.id" : "ID da Tropa",
  48.          },
  49.          "de" : {
  50.             "plugin.description" : "Verwalte angezeigte Platoons",
  51.             "text.description" : "In diesem Dialog kannst du ausw&auml;hlen welche Platoons angezeigt werden sollen. Die ID des gew&uuml;nschten Platoons kannst du der Seiten-URL entnehmen. Beispiel: URL = http://battlelog.battlefield.com/bf4/platoons/view/4726603585846748181/, Platoon-ID = <strong>4726603585846748181</strong>.",
  52.             "button.add" : "Hinzuf&uuml;gen",
  53.             "hint.name" : "Anzeigename",
  54.             "hint.id" : "Platoon-ID",
  55.          },
  56.     },
  57.    
  58. AddPlatoonDropdownSettings : function(instance) {
  59.     var platoon_dropdown_settings_code = '<p>' + instance.t("text.description") + '</p><div id="pd-settings-list">';
  60.     var platoon_dropdown_stored_platoons_settings = instance.storage("platoon_dropdown_stored_platoons");
  61.     if(platoon_dropdown_stored_platoons_settings != null && platoon_dropdown_stored_platoons_settings!="")
  62.     {
  63.       $.each(platoon_dropdown_stored_platoons_settings, function(index,value) {
  64.         var item = value.split("||||");
  65.         platoon_dropdown_settings_code += '<div><span style="float: left">' + item[0] + ' - ' + item[1] +' - '+item[2].toUpperCase()+'</span><span class="bblog-button pd-delete" style="float: right" data-pdindex="'+index+'">' + BBLog.t("delete") + '</span><div style="clear: both"></div></div>';        
  66.       });
  67.     }
  68.     platoon_dropdown_settings_code += '</div><input type="text" id="pd-name" placeholder="' + instance.t("hint.name") + '"></input><input type="text" id="pd-id" placeholder="' + instance.t("hint.id") + '"></input><select id="pd-game"><option value="bf4">BF4</option><option value="bf3">BF3</option></select><span id="pd-arrow">▼</span><span id="pd-add" class="bblog-button">' + instance.t("button.add") + '</span>';
  69.     BBLog.popup("platoon-dropdown", instance.t("plugin.description"), platoon_dropdown_settings_code);
  70.    
  71.     $(".pd-delete").click(function() {
  72.     var index = $(this).attr("data-pdindex");
  73.     platoon_dropdown_stored_platoons_settings.splice(index, 1);
  74.     instance.storage("platoon_dropdown_stored_platoons", platoon_dropdown_stored_platoons_settings);
  75.     location.reload();
  76.     });    
  77.     $("#pd-add").one("click",function() {
  78.         var pd_name = $("#pd-name").val();
  79.         var pd_id = $("#pd-id").val();
  80.         var pd_game = $("#pd-game").val();
  81.         var item = pd_name + '||||' + pd_id + '||||' + pd_game;
  82.         if(platoon_dropdown_stored_platoons_settings == null || platoon_dropdown_stored_platoons_settings=="")
  83.         {
  84.             platoon_dropdown_stored_platoons_settings = [item];
  85.         }
  86.         else
  87.         {
  88.             platoon_dropdown_stored_platoons_settings.push(item);
  89.         }
  90.         instance.storage("platoon_dropdown_stored_platoons", platoon_dropdown_stored_platoons_settings);
  91.         location.reload();
  92.     });    
  93. },
  94.  
  95. init : function(instance){
  96.     var old_storage = instance.storage("platoondropdownstoredplatoons");
  97.     var new_storage;
  98.     if(old_storage != null && old_storage != "")
  99.         {
  100.             new_storage = [];
  101.             $.each(old_storage, function(index, value) {
  102.               var old_item = value.split("||||");
  103.               var new_item = old_item[0]+'||||'+old_item[1]+'||||bf4';
  104.               new_storage.push(new_item);
  105.         });
  106.             instance.storage("platoon_dropdown_stored_platoons", new_storage);
  107.             instance.storage("platoondropdownstoredplatoons", "");
  108.             BBLog.popup("platoon-dropdown-migration", "Platoon Dropdown", "<p>The plugin now allows you to choose which platoons are for which game. Your platoon list was converted to contain game info and it's set to BF4 by default.</p><br><p>If some of your platoons are for BF3, you can open the settings, copy the platoon details, select BF3, click 'Add' and then delete the old one.</p><br><p>This window will not be displayed again.</p>");
  109.         }
  110.     if(BBLog.cache("mode") == "bf3" || BBLog.cache("mode") == "bf4")
  111.     {
  112.         instance.AddPlatoonDropdown(instance);
  113.     }
  114. },  
  115.  
  116. domchange : function(instance){
  117.     if(BBLog.cache("mode") == "bf3" || BBLog.cache("mode") == "bf4")
  118.     {
  119.             instance.AddPlatoonDropdown(instance);
  120.     }
  121. },  
  122.    
  123.    
  124. AddPlatoonDropdown : function(instance){
  125.     if (!$('#pd-style').length) {
  126.         $("head").append("<style id='pd-style'>#pd-settings-list{margin: 0.75em 0}.pd-delete, #pd-add{vertical-align: middle}#pd-name, #pd-id{width: 35%; margin-right: 12px}#pd-arrow{position: relative; right: 16px; pointer-events: none}.pd-empty{background-color: transparent !important; cursor: default !important}#base-bf4-html #pd-game option{background-color: black; color: #d5dde5}</style>");
  127.     }  
  128.     if (!$('.dropdown-content[data-for="platoons"]').length) {
  129.         $(".base-section-menu li[data-page='platoons']").addClass("has-dropdown");
  130.         $(".base-section-menu li[data-page='platoons']").attr('data-bind-toggle', 'dropdown');
  131.         $(".dropdown-bar").append('<div class="dropdown-content" data-for="platoons"><div class="row"><nav class="span4 dropdown-menu"></nav></div></div>');
  132.         var platoon_dropdown_stored_platoons = instance.storage("platoon_dropdown_stored_platoons");
  133.         console.log(platoon_dropdown_stored_platoons);
  134.         if(platoon_dropdown_stored_platoons != null && platoon_dropdown_stored_platoons != "")
  135.         {
  136.             var items_for_game = 0;
  137.         $.each(platoon_dropdown_stored_platoons, function(index, value) {
  138.               var item = value.split("||||");
  139.               if(item[2] == BBLog.cache("mode"))
  140.               {
  141.                 if(item[2] == "bf3")
  142.                 {
  143.                 $('.dropdown-content[data-for="platoons"] .row nav').append('<a href="http://battlelog.battlefield.com/bf3/'+BBLog.cache("battlelog.language")+'platoon/'+item[1]+'/"><i class="icon-white icon-friends2"></i><span>'+item[0]+'</span></a>');          
  144.                 }
  145.                 if(item[2] == "bf4")
  146.                 {
  147.                     $('.dropdown-content[data-for="platoons"] .row nav').append('<a href="http://battlelog.battlefield.com/bf4/'+BBLog.cache("battlelog.language")+'platoons/view/'+item[1]+'/"><i class="icon-white icon-friends2"></i><span>'+item[0]+'</span></a>');          
  148.                 }
  149.                 items_for_game++;
  150.               }
  151.         });
  152.         if(items_for_game == 0)
  153.         {
  154.             $('.dropdown-content[data-for="platoons"] .row nav').append('<a class="pd-empty"><span>You can configure the platoons for this game in the BBLog Menu</span></a>');
  155.         }
  156.     }
  157.     else
  158.     {
  159.         $('.dropdown-content[data-for="platoons"] .row nav').append('<a class="pd-empty"><span>You can configure the platoons in the BBLog Menu</span></a>');
  160.     }
  161.     }
  162. },
  163. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement