Advertisement
Ansolley

Plugin - Friends Highlighter

May 10th, 2019
625
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 6.14 KB | None | 0 0
  1. /**
  2. * Friends Highlighter - Highlights your friends in the scoreboard and battlereports
  3. *
  4. * @author I-MrFixIt-I
  5. * @version 1.0
  6. * @url https://getbblog.com/
  7. */
  8.  
  9. // initialize your plugin
  10. BBLog.handle("add.plugin", {
  11.  
  12.     stdColor : "#00c8ff",
  13.  
  14.     /**
  15.     * The unique, lowercase id of my plugin
  16.     * Allowed chars: 0-9, a-z, -
  17.     */
  18.     id : "mrfixit-friends-highlighter",
  19.  
  20.     /**
  21.     * The name of my plugin, used to show config values in bblog options
  22.     * Could also be translated with the translation key "plugin.name" (optional)
  23.     *
  24.     * @type String
  25.     */
  26.     name : "Friends Highlighter",
  27.  
  28.     /**
  29.     * Some translations for this plugins
  30.     * For every config flag must exist a corresponding EN translation
  31.     *   otherwise the plugin will no be loaded
  32.     *
  33.     * @type Object
  34.     */
  35.     translations : {
  36.         "en" : {
  37.             "use.friends-highlighter" : "Use Friends Highlighter",
  38.             "use.highlight-scoreboard" : "Highlight friends in scoreboard",
  39.             "use.highlight-battlereport" : "Highlight friends in battlereport",
  40.             "change-color" : "Change color",
  41.             "choose-color" : "Choose a color of your choice. Example: #00c8ff"
  42.         },
  43.         "de" : {
  44.             "use.friends-highlighter" : "Friends Highlighter verwenden",
  45.             "use.highlight-scoreboard" : "Freunde im Scoreboard hervorheben",
  46.             "use.highlight-battlereport" : "Freunde im Kampfbericht hervorheben",
  47.             "change-color" : "Farbe ändern",
  48.             "choose-color" : "Wähle eine Farbe deiner Wahl. Beispiel: #00c8ff"
  49.         }
  50.     },
  51.  
  52.     /**
  53.     * Configuration Options that appears in the BBLog Menu
  54.     * Every option must be an object with properties as shown bellow
  55.     * Properties available:
  56.     *   key : The name for your config flag - The user can toggle this option
  57.     *         and you can retreive the users choice with instance instance.storage(YOUR_KEY_NAME) (0 or 1 will be returned)
  58.     *   init : Can be 0 or 1 - Represent the initial status of the option when the user load the plugin for the first time
  59.     *          If you want that this option is enabled on first load (opt-out) than set it to 1, otherwise to 0 (opt-in)
  60.     *   handler(optional): When set as a function this config entry turns into a button (like the plugins button you see in the bblog menu)
  61.     *                       The function well be executed when the user clicks the button
  62.     */
  63.     configFlags : [
  64.         {"key" : "use.friends-highlighter", "init" : 1},
  65.         {"key" : "use.highlight-scoreboard", "init" : 1},
  66.         {"key" : "use.highlight-battlereport", "init" : 1},
  67.         {"key" : "change-color", "init" : 0, "handler" : function(instance){
  68.             var color = prompt(instance.t("choose-color"));
  69.             if (color.charAt(0) != "#")
  70.             {
  71.                 color =+ "#";
  72.             }
  73.            
  74.             var isHexValue  = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(color);
  75.             if (isHexValue)
  76.             {
  77.                 instance.storage("color", color);
  78.             }
  79.         }}
  80.     ],
  81.  
  82.     friendsListcontainsUsername : function(soldierName){
  83.         var containsUsername = false;
  84.         var friendsList = comcenter.getFriendsListFromLs();
  85.         friendsList.forEach(function(friend) {
  86.             if (friend.username == soldierName)
  87.             {
  88.                 containsUsername = true;
  89.             }
  90.         });
  91.        
  92.         return containsUsername;
  93.     },
  94.    
  95.     highlightFriends : function(instance, rows){
  96.         $.each($(rows), function() {
  97.             var soldierNameContainer = $(this).find(".soldier-name .user-info .common-playername-personaname-nolink");
  98.             var soldierName = $(soldierNameContainer).text();
  99.             var tag = $(soldierNameContainer).find(".bblog-tag").text(); // get clan tag from player
  100.            
  101.             if (tag.length > 0)
  102.             {
  103.                 soldierName = soldierName.substr(tag.length); // get playername and cut the clantag from it
  104.             }
  105.    
  106.             if(instance.friendsListcontainsUsername(soldierName))
  107.             {
  108.                 if (instance.storage("change-color"))
  109.                 {
  110.                     var color = instance.storage("color");
  111.                     if (color !== null)
  112.                     {
  113.                         $(soldierNameContainer).css("color", color);
  114.                     }
  115.                     else
  116.                     {
  117.                         $(soldierNameContainer).css("color", instance.stdColor);
  118.                     }
  119.                    
  120.                 }
  121.                 else
  122.                 {
  123.                     $(soldierNameContainer).css("color", instance.stdColor);
  124.                 }
  125.             }
  126.         });
  127.     },
  128.  
  129.     /**
  130.     * A trigger that fires everytime when the dom is changing but at max only once each 200ms (5x per second) to prevent too much calls in a short time
  131.     * Example Case: If 10 DOM changes happen in a period of 100ms than this function will only been called 200ms after the last of this 10 DOM changes
  132.     * This make sure that all actions in battlelog been finished before this function been called
  133.     * This is how BBLog track Battlelog for any change, like url, content or anything
  134.     *
  135.     * @param object instance The instance of your plugin which is the whole plugin object
  136.     *    Always use "instance" to access any plugin related function, not use "this" because it's not working properly
  137.     *    For example: If you add a new function to your addon, always pass the "instance" object
  138.     */
  139.     domchange : function(instance){
  140.         if (instance.storage("use.friends-highlighter"))
  141.         {
  142.             if(instance.storage("use.highlight-scoreboard") && window.location.href.match(/\/servers\/show\/pc\//i)){
  143.                 instance.highlightFriends(instance, $("#server-players-list .row table tbody tr"));
  144.             }
  145.             else if(instance.storage("use.highlight-battlereport") && window.location.href.match(/\/battlereport\/show\/1\//i)){
  146.                 instance.highlightFriends(instance, $("#battlereport-scoreboard .row table tbody tr"));
  147.             }
  148.         }
  149.     }
  150. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement