Big Al sell all

double click checkbox to toggle all similar

  1. // ==UserScript==
  2. // @name Big Al sell all
  3. // @namespace namespace
  4. // @version 0.1
  5. // @description double click checkbox to toggle all similar
  6. // @author tos
  7. // @match *.torn.com/bigalgunshop.php*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. function LI_addListener(li) {
  12. const item_id = li.getAttribute('data-item')
  13. const checkbox_LABEL = li.querySelector('input[type=checkbox]+LABEL')
  14. if (checkbox_LABEL) checkbox_LABEL.addEventListener('dblclick', e => document.querySelectorAll(`LI[data-item="${item_id}"] INPUT[type=checkbox]`).forEach(checkbox => checkbox.checked = !checkbox.checked))
  15. }
  16.  
  17. const observer = new MutationObserver((mutations) => {
  18. for (const mutation of mutations) {
  19. for (const node of mutation.addedNodes) {
  20. if (node.nodeName && node.nodeName === 'LI' && node.hasAttribute('data-item')) LI_addListener(node)
  21. }
  22. }
  23. })
  24.  
  25. const wrapper = document.querySelector('UL.sell-items-list')
  26. wrapper.querySelectorAll('LI[data-item]').forEach((li) => {
  27. LI_addListener(li)
  28. })
  29. observer.observe(wrapper, { subtree: true, childList: true })