Advertisement
Guest User

lf

a guest
Jul 19th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function lootFilter() {
  2.  
  3.     let css = document.createElement('style');
  4.     css.innerHTML = "#lootfilter { width: 150px; right: 0; top: 0; position: absolute; }"
  5.     document.body.appendChild(css);
  6.  
  7.     var settings;
  8.  
  9.     if (!localStorage.getItem('lootfilter-settings')) {
  10.         settings = {
  11.             posX: 50,
  12.             posY: 50,
  13.             value: 0,
  14.             setValue: '',
  15.             legendary: 1,
  16.             heroic: 1,
  17.             unique: 1,
  18.             heal: 1,
  19.             arrow: 1,
  20.             gold: 1,
  21.             teleport: 1,
  22.             runes: 1,
  23.             bless: 1,
  24.             close: 0
  25.         }
  26.         localStorage.setItem('lootfilter-settings', JSON.stringify(settings));
  27.     }
  28.  
  29.     settings = JSON.parse(localStorage.getItem('lootfilter-settings'));
  30.  
  31.     function updateSettings(id, val) {
  32.         settings = JSON.parse(localStorage.getItem('lootfilter-settings'));
  33.         settings[id] = val;
  34.         console.log(id, settings[id])
  35.         localStorage.setItem('lootfilter-settings', JSON.stringify(settings));
  36.     }
  37.  
  38.     function createLi(id, text, tip) {
  39.         let liElement = document.createElement('li');
  40.         liElement.setAttribute('data-id', id);
  41.  
  42.         if (tip) liElement.setAttribute('tip', tip);
  43.         let checkboxElement = document.createElement('input');
  44.         checkboxElement.setAttribute('type', 'checkbox');
  45.         if(settings[id]) checkboxElement.checked = true;
  46.         checkboxElement.addEventListener('change', function() {
  47.             updateSettings(id, settings[id] ? 0 : 1)
  48.         });
  49.         liElement.appendChild(checkboxElement);
  50.  
  51.         let textElement = document.createElement('span');
  52.         textElement.textContent = text;
  53.         liElement.appendChild(textElement);
  54.  
  55.         ulElement.appendChild(liElement);
  56.     }
  57.  
  58.     let mainBox = document.createElement('div');
  59.     mainBox.setAttribute('id', 'lootfilter');
  60.  
  61.     let header = document.createElement('header');
  62.  
  63.     let name = document.createElement('span');
  64.     name.textContent = 'Loot Filter';
  65.     header.appendChild(name);
  66.  
  67.     let options = document.createElement('span');
  68.     options.setAttribute('id', 'options');
  69.     options.setAttribute('tip', 'Pokaż więcej opcji');
  70.     options.textContent = 'opcje';
  71.     header.appendChild(options);
  72.  
  73.     mainBox.appendChild(header);
  74.  
  75.     let ulElement = document.createElement('ul');
  76.  
  77.     createLi('value', 'Powyżej', 'Łapanie przedmiotów od określonej wartości')
  78.     createLi('legendary', 'Legendarne', 'Łapanie legend');
  79.     createLi('heroic', 'Heroiczne', 'Łapanie heroików');
  80.     createLi('unique', 'Unikatowe', 'Łapanie unikatów');
  81.     createLi('heal', 'Mikstury', 'Łapanie mikstur');
  82.     createLi('arrow', 'Strzały', 'Łapanie strzał');
  83.     createLi('teleport', 'Teleporty', 'Łapanie teleportów');
  84.     createLi('gold', 'Złoto', 'Łapanie złota');
  85.     createLi('runes', 'Smocze runy', 'Łapanie smoczych run');
  86.     createLi('bless', 'Błogosławieństwa', 'Łapanie błogosławieństw');
  87.     createLi('close', 'Podział łupów', 'Akceptowanie podziału łupów');
  88.  
  89.     mainBox.appendChild(ulElement);
  90.     document.body.appendChild(mainBox);
  91.  
  92.     let inputValue = document.createElement('input');
  93.     inputValue.setAttribute('id', 'value');
  94.     inputValue.addEventListener('change', function(){
  95.         updateSettings('setValue', inputValue.value)
  96.     })
  97.     document.querySelector('ul > li[data-id="value"]').appendChild(inputValue);
  98.  
  99.     $('#lootfilter').draggable({
  100.         cancel: '#lootfilter > ul',
  101.         start: () => {
  102.             window.g.lock.add('dragging');
  103.             window.Tip.disable();
  104.         },
  105.         stop: () => {
  106.             window.g.lock.remove('dragging');
  107.             window.Tip.enable();
  108.             updateSettings('posX', parseInt(mainBox.style.left));
  109.             updateSettings('posY', parseInt(mainBox.style.top));
  110.         }
  111.     });
  112.  
  113.     mainBox.style.left = settings.posX + "px";
  114.     mainBox.style.top = settings.posY + "px";
  115.  
  116.     const lootItemOld = window.lootItem;
  117.     var sent = false;
  118.     var loots;
  119.     window.lootItem = function(item) {
  120.         lootItemOld(item);
  121.         var stat = window.parseItemStat(item.stat);
  122.         if (!sent) loots = {want: [], not: [], must: []};
  123.         if (((isNaN(parseInt(settings.setValue)) || (item.pr >= parseInt(settings.setValue))) && settings.value) || (item.stat.includes('ttl') && settings.bless) || item.stat.includes('quest') || (item.stat.includes('legendary') && settings.legendary) || (item.stat.includes('heroic') && settings.heroic) || (item.stat.includes('unique') && settings.unique) || ((item.stat.includes('fullheal') || item.stat.includes('leczy') || item.stat.includes('perheal')) && settings.heal) || (item.stat.includes('ammo') && settings.arrow) || (item.stat.includes('gold') && settings.gold) || (item.stat.includes('teleport') && settings.teleport) || (item.stat.includes('runes') && settings.teleport)) {
  124.             if (window.g.party && !(window.isset(stat.reqp) && stat.reqp.indexOf(window.hero.prof) == -1)) {
  125.                 loots.must.push(item.id);
  126.                 window.setStateOnOneLootItem(item.id, 2);
  127.             } else {
  128.                 loots.want.push(item.id)
  129.                 window.setStateOnOneLootItem(item.id, 1);
  130.             }
  131.         } else {
  132.             loots.not.push(item.id);
  133.             window.setStateOnOneLootItem(item.id, 0);
  134.         }
  135.         if (!sent) {
  136.             sent = true;
  137.             if (settings.close && window.g.party) window._g('chat&c=/g .');
  138.             setTimeout(function() {
  139.                 window._g("loot&want=" + loots.want.join(",") + "&not=" + loots.not.join(",") + "&must=" + loots.must.join(",") + "&final=" + settings.close);
  140.                 if (settings.close) window.closeLootWindow();
  141.                 sent = false;
  142.             }, 300);
  143.         }
  144.     }
  145. }
  146.  
  147. window.g.loadQueue.push({
  148.     fun: function() {
  149.         var _lootfilter = new lootFilter();
  150.     },
  151.     data: ''
  152. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement