Untitled

 avatar
unknown
javascript
3 years ago
1.1 kB
3
Indexable
      const cells = [...document.querySelectorAll('#gameTable .d_value')];
      const CLASS_PREFIX = 'jsHandler-sporcleTable';
      const statesAmount = 3;
      cells.forEach(cell => {
        cell.addEventListener('click', (e) => {
          if (!e.metaKey) return;

          e.stopPropagation();
          e.preventDefault();

          const currentState = Number(cell.dataset.jshelperCellState) || 0;
          const nextState = currentState === statesAmount ? 0 : currentState + 1;
          cell.dataset.jshelperCellState = nextState;
          cell.classList.remove(`${CLASS_PREFIX}-${currentState}`);
          if (nextState) {
            cell.classList.add(`${CLASS_PREFIX}-${nextState}`);
          }
        }, true);
      });

      injectStyles(`
        #gameTable .${CLASS_PREFIX}-1 {
          text-decoration: line-through;
          opacity: .3;
        }
        #gameTable .${CLASS_PREFIX}-2 {
          background: #ff8888 !important;
          color: #333 !important;
        }
        #gameTable .${CLASS_PREFIX}-3 {
          background: #88c3ff !important;
          color: #333 !important;
        }
      `);
    },
Editor is loading...