SHARE
TWEET

lf

a guest Jul 19th, 2019 65 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. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top