Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. const csvInput = (selector = '', colLength = 0) => {
  2. let stuff = ''
  3. let index = 0
  4. const buttons = document.querySelectorAll(selector)
  5. if (buttons.length === 0) {
  6. throw Error('Selector not found')
  7. }
  8. if (colLength < 1) {
  9. throw Error('colLength must be a positive int')
  10. }
  11. if (colLength > buttons.length) {
  12. throw Error('colLength should not be greater than the total selectors')
  13. }
  14. for (let i = 0; i < buttons.length; i++) {
  15. let lastCol = index === colLength - 1
  16. let lastItem = i === buttons.length - 1
  17. let delimiter = ', '
  18. if (lastCol) {
  19. delimiter = ''
  20. }
  21. stuff = stuff + buttons[i].value + delimiter
  22. index++
  23. if (lastCol) {
  24. index = 0
  25. if (!lastItem) {
  26. stuff = stuff + "\n"
  27. }
  28. }
  29. }
  30. return stuff
  31. }
  32. csvInput('#matage-options-panel input',7)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement