Advertisement
Guest User

esomap.uesp.net Filter by Key

a guest
Jul 5th, 2017
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /** esomap.uesp.net Filter by Key **/
  2. /*
  3.     Author: Nocenti
  4.     Date: 2017
  5. */
  6.  
  7. /** jquery-cookie **/
  8. /*
  9.     Appending jquery-cookie to set cookie for filter.
  10.     This protects the filter against dragging/map changes.
  11. */
  12. var jq = document.createElement('script');
  13. jq.src = "https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js";
  14. document.getElementsByTagName('head')[0].appendChild(jq);
  15. /** END jquery-cookie **/
  16.  
  17. /** Instantiation **/
  18. /*
  19.     Toggle Map Key to instantiate
  20.     Map Key Items (.gmMapKeyImageImage)
  21. */
  22.    
  23.     g_GameMap.showMapKey();
  24.     g_GameMap.hideMapKey();
  25.    
  26. /** END Instantiation **/
  27.  
  28. /** UI Tweaks **/
  29.     $('.gmMapKeyItem').css({
  30.         'cursor'        : 'pointer',
  31.         'padding-right' : '5px',
  32.         'width'         : '100%',
  33.     });
  34.    
  35.     // Custom Styles
  36.     $("<style>")
  37.     .attr("type", "text/css")
  38.     .html("\
  39.    .clearFilter {\
  40.        position: absolute;\
  41.         right: 5px;\
  42.         top: 35px;\
  43.    }\
  44.     .itemNotFound {\
  45.         background: #ddd;\
  46.         display: none;\
  47.         font-family: 'Arial', sans-serif;\
  48.         font-size: 13px;\
  49.         font-weight: bold;\
  50.         height: 20px;\
  51.         left: 38%;\
  52.         padding: 10px;\
  53.         position: absolute;\
  54.         text-align: center;\
  55.         top: 29px;\
  56.         width: 120px;\
  57.         z-index: 999;\
  58.     }\
  59.     .red { color: red; }\
  60.     .green { color: #00aa00; }")
  61.     .appendTo("head");
  62.    
  63.    
  64.     $('.gmMapKeyCloseButton').after('<button class="clearFilter">Remove Filter</button>');
  65.     $('body').append('<div class="itemNotFound">Item Not Found</div>');
  66. /** END UI Tweaks **/
  67.  
  68. /** Map Key Icon/Label Handler **/
  69.     $('.gmMapKeyItemLabel').on('click', function() { $(this).prev().find('img').click(); });
  70.     $('.gmMapKeyImageImage img').on('click', function() {
  71.  
  72.         // Clear selected styling
  73.         $('.gmMapKeyItem').css('background', '');
  74.        
  75.         // Style the selected item
  76.         $(this).parent().parent().css('background', '#aacc00');
  77.    
  78.         // Store the clicked icon's path
  79.         var src = $(this).attr('src');
  80.        
  81.        
  82.         /** Mismatch Collection **/
  83.         /*
  84.             Not all Map Key icon filenames
  85.             match the Map icon filenames.
  86.             Let's fix that.
  87.            
  88.             Pushing the paths of the clicked icon
  89.             and the path of any known mismatches.
  90.            
  91.             This ensures that should the mismatches be
  92.             resolved, the filter will continue to work.
  93.            
  94.             Should mismatches be resolved, the Mismatch Collection
  95.             segment of this file should be removed in its entireity.       
  96.         */
  97.            
  98.             var matches = [];
  99.             switch(src) {
  100.                
  101.                 // Alchemist
  102.                 case 'icons/29.png':
  103.                     matches.push(src, 'icons/22.png');
  104.                 break;
  105.                
  106.                 // Brewer/Inn
  107.                 case 'icons/23.png':
  108.                     matches.push(src, 'icons/11.png');
  109.                 break;
  110.                
  111.                 // Crafting Site
  112.                 case 'icons/56.png':
  113.                     matches.push(src, 'icons/16.png');
  114.                 break;
  115.                
  116.                 // Thieves Guild
  117.                 case 'icons/145.png':
  118.                 case 'icons/165.png':
  119.                     matches.push(src, 'icons/133.png');
  120.                 break;
  121.                                
  122.                 default:
  123.                     matches.push(src);
  124.                    
  125.             }
  126.         /** END Mismatch Collection **/
  127.        
  128.        
  129.         // Call Filter
  130.         filterByKey(matches, src);
  131.        
  132.         // Close the Map Key
  133.         $('.gmMapKeyCloseButton').click();
  134.        
  135.     });
  136. /** END Map Key Icon Handler **/
  137.  
  138. /** Window Click Handler **/
  139. $(window).on('mouseup click mousewheel', function() {
  140.     if($.cookie('filterKey') !== undefined) {
  141.         setTimeout(function() {
  142.             // Style the selected item
  143.             $('.gmMapKeyImageImage img[src="' + $.cookie('filterKey').split(',')[0] + '"]').parent().parent().css('background', '#aacc00');
  144.            
  145.             // Run Filter
  146.             filterByKey($.cookie('filterKey').split(','));
  147.         }, 400);
  148.     }
  149. });
  150. /** END Mouse Up handler **/
  151.  
  152. /** clearFilter Click Handler **/
  153. $('.clearFilter').on('click', function() {
  154.     if($.cookie('filterKey') !== undefined) {
  155.         // Clear the filterKey cookie
  156.         $.removeCookie('filterKey');
  157.        
  158.         // Hide "Item Not Found"
  159.         $('.itemNotFound').hide();
  160.        
  161.         // Show all Icons, Labels and Tooltips
  162.         $('.gmMapLocIcon, .gmMapLoc, .gmLocToolTip').show().css('visibility', 'visible');
  163.        
  164.         // Clear selected styling
  165.         $('.gmMapKeyItem').css('background', '');
  166.     }
  167. });
  168.  
  169. /** Filter **/
  170. function filterByKey(matches, src) {
  171.     // Hide all Icons, Labels and Tooltips
  172.     $('.gmMapLocIcon, .gmMapLoc, .gmLocToolTip').hide().css('visibility', 'hidden');
  173.  
  174.     var found = false;
  175.     $('.gmMapLocIcon').each(function() {
  176.         // Check for a matching icon
  177.         if(matches.indexOf($(this).attr('src')) !== -1) {
  178.            
  179.             $(this).show().css('visibility', 'visible');                    // Show Matched Icon
  180.             $(this).parent().next().show().css('visibility', 'visible');    // Show Matched Label
  181.            
  182.             found = true;
  183.         }
  184.     });
  185.    
  186.     if(!found) {
  187.         // Show all Icons, Labels and Tooltips
  188.         $('.gmMapLocIcon, .gmMapLoc, .gmLocToolTip').show().css('visibility', 'visible');
  189.        
  190.         // Show "Item Not Found" notification
  191.         $('.itemNotFound').removeClass('green').addClass('red').html('Item Not Found').show();
  192.     } else {
  193.         // Show "Item Found!" notification
  194.         $('.itemNotFound').removeClass('red').addClass('green').html('Item Found!').delay('1000').fadeOut('fast');
  195.     }
  196.    
  197.     // Store the filter
  198.     if(src !== undefined) {
  199.         $.cookie('filterKey', matches.join(','));
  200.     }
  201. }
  202. /** END Filter **/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement