Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const csvInput = (selector = '', colLength = 0) => {
- let stuff = ''
- let index = 0
- const buttons = document.querySelectorAll(selector)
- if (buttons.length === 0) {
- throw Error('Selector not found')
- }
- if (colLength < 1) {
- throw Error('colLength must be a positive int')
- }
- if (colLength > buttons.length) {
- throw Error('colLength should not be greater than the total selectors')
- }
- for (let i = 0; i < buttons.length; i++) {
- let lastCol = index === colLength - 1
- let lastItem = i === buttons.length - 1
- let delimiter = ', '
- if (lastCol) {
- delimiter = ''
- }
- stuff = stuff + buttons[i].value + delimiter
- index++
- if (lastCol) {
- index = 0
- if (!lastItem) {
- stuff = stuff + "\n"
- }
- }
- }
- return stuff
- }
- csvInput('#matage-options-panel input',7)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement