|
| 1 | +function run() { |
| 2 | + const props = {} |
| 3 | + const events = [] |
| 4 | + const methods = [] |
| 5 | + const slots = [] |
| 6 | + const link = location.href |
| 7 | + const prefix = 'Up' |
| 8 | + const basename = link.split('/').slice(-1)[0].split('.')[0].split('-').map((i) => { |
| 9 | + return i[0].toUpperCase() + i.slice(1) |
| 10 | + }).join('') |
| 11 | + const name = `${prefix}${basename}` |
| 12 | + const tbody = document.querySelector('#props + table') |
| 13 | + ? document.querySelector('#props + table') |
| 14 | + : document.querySelector('#props + * + table') |
| 15 | + ? document.querySelector('#props + * + table') |
| 16 | + : document.querySelector(`#${basename.toLocaleLowerCase()}-props + table`) |
| 17 | + || document.querySelector(`#${basename.toLocaleLowerCase()}-props + * + table`) |
| 18 | + if (tbody) { |
| 19 | + Array.from(tbody.querySelectorAll('tbody tr')).forEach((item) => { |
| 20 | + const name = item.children[0].firstChild.textContent |
| 21 | + const description = item.children[1].textContent |
| 22 | + const type = !/(-|true|false)/.test(item.children[4].textContent) |
| 23 | + ? item.children[4].textContent |
| 24 | + : item.children[2].textContent |
| 25 | + const value = item.children[3].textContent |
| 26 | + props[name] = { |
| 27 | + description, |
| 28 | + description_zh: description, |
| 29 | + default: value, |
| 30 | + value: '', |
| 31 | + type, |
| 32 | + } |
| 33 | + }) |
| 34 | + } |
| 35 | + const eventBody = (document.querySelector('#event + table') |
| 36 | + ? document.querySelector('#event + table') |
| 37 | + : document.querySelector('#event + * + table')) |
| 38 | + || (document.querySelector('#events + table') |
| 39 | + ? document.querySelector('#events + table') |
| 40 | + : document.querySelector('#events + * + table')) |
| 41 | + || (document.querySelector(`#${basename.toLocaleLowerCase()}-event + table`)) |
| 42 | + || (document.querySelector(`#${basename.toLocaleLowerCase()}-event + * + table`)) |
| 43 | + || (document.querySelector(`#${basename.toLocaleLowerCase()}-events + table`)) |
| 44 | + || (document.querySelector(`#${basename.toLocaleLowerCase()}-events + * + table`)) |
| 45 | + |
| 46 | + if (eventBody) { |
| 47 | + Array.from(eventBody.querySelectorAll('tbody tr')).forEach((item) => { |
| 48 | + const name = item.children[0].textContent.split(' ')[0] |
| 49 | + const description = item.children[1].textContent |
| 50 | + const params = item.children[2].textContent |
| 51 | + events.push({ name, description, description_zh: description, params }) |
| 52 | + }) |
| 53 | + } |
| 54 | + const slotBody = document.querySelectorAll('#slots + table tbody tr')?.length ? document.querySelectorAll('#slots + table tbody tr') : document.querySelectorAll('#slot + table tbody tr') |
| 55 | + if (slotBody) { |
| 56 | + Array.from(slotBody).forEach((item) => { |
| 57 | + let name = item.children[0].textContent.split(' ')[0] |
| 58 | + const description = item.children[1].textContent |
| 59 | + if (name === '-' || !name) |
| 60 | + name = 'default' |
| 61 | + slots.push({ |
| 62 | + name, |
| 63 | + description, |
| 64 | + description_zh: description, |
| 65 | + }) |
| 66 | + }) |
| 67 | + } |
| 68 | + const methodsBody = (document.querySelector('#methods + table') |
| 69 | + ? document.querySelector('#methods + table') |
| 70 | + : document.querySelector('#methods + * + table')) |
| 71 | + || (document.querySelector('#method + table') |
| 72 | + ? document.querySelector('#method + table') |
| 73 | + : document.querySelector('#method + * + table')) |
| 74 | + || (document.querySelector(`#${basename.toLocaleLowerCase()}-methods + table`)) |
| 75 | + || (document.querySelector(`#${basename.toLocaleLowerCase()}-methods + * + table`)) |
| 76 | + || (document.querySelector(`#${basename.toLocaleLowerCase()}-method + table`)) |
| 77 | + || (document.querySelector(`#${basename.toLocaleLowerCase()}-method + * + table`)) |
| 78 | + |
| 79 | + if (methodsBody) { |
| 80 | + Array.from(methodsBody.querySelectorAll('tbody tr')).forEach((item) => { |
| 81 | + const name = item.children[0].textContent.split('(')[0] |
| 82 | + const description = item.children[1].textContent |
| 83 | + const params = item.children[0].textContent.split('(')[1] |
| 84 | + ? `(${item.children[0].textContent.split('(')[1]}` |
| 85 | + : '' |
| 86 | + methods.push({ name, description, description_zh: description, params }) |
| 87 | + }) |
| 88 | + } |
| 89 | + |
| 90 | + const result = { name, props, link, link_zh: link, typeDetail: {}, events, methods, slots, suggestions: [] } |
| 91 | + copyToClipboard(JSON.stringify(result, null, 2)) |
| 92 | + |
| 93 | + return result |
| 94 | +} |
| 95 | + |
| 96 | +function getProps() { |
| 97 | + const props = {} |
| 98 | + $0.closest('tbody').querySelectorAll('tr').forEach((item) => { |
| 99 | + const name = item.children[0].firstChild.textContent |
| 100 | + const description = item.children[1].textContent |
| 101 | + const type = !/(-|true|false)/.test(item.children[4].textContent) |
| 102 | + ? item.children[4].textContent |
| 103 | + : item.children[2].textContent |
| 104 | + const value = item.children[3].textContent |
| 105 | + props[name] = { |
| 106 | + description, |
| 107 | + description_zh: description, |
| 108 | + default: value, |
| 109 | + value: '', |
| 110 | + type, |
| 111 | + } |
| 112 | + }) |
| 113 | + copyToClipboard(JSON.stringify(props, null, 2)) |
| 114 | + return props |
| 115 | +} |
| 116 | + |
| 117 | +function getEvents() { |
| 118 | + const events = [] |
| 119 | + const eventBody = $0.closest('tbody').querySelectorAll('tr') |
| 120 | + if (eventBody) { |
| 121 | + Array.from(eventBody).forEach((item) => { |
| 122 | + const name = item.children[0].textContent |
| 123 | + const description = item.children[1].textContent |
| 124 | + const params = item.children[2].textContent |
| 125 | + events.push({ name, description, description_zh: description, params }) |
| 126 | + }) |
| 127 | + } |
| 128 | + copyToClipboard(JSON.stringify(events, null, 2)) |
| 129 | + |
| 130 | + return events |
| 131 | +} |
| 132 | + |
| 133 | +function getSlots() { |
| 134 | + const slots = [] |
| 135 | + Array.from($0.closest('tbody').children).forEach(child => { |
| 136 | + const name = child.children[0].textContent |
| 137 | + const description = child.children[1].textContent |
| 138 | + slots.push({ |
| 139 | + name, |
| 140 | + description, |
| 141 | + description_zh: description, |
| 142 | + }) |
| 143 | + }) |
| 144 | + copyToClipboard(JSON.stringify(slots, null, 2)) |
| 145 | + |
| 146 | + return slots |
| 147 | +} |
| 148 | + |
| 149 | +function getMethods() { |
| 150 | + const methods = [] |
| 151 | + const methodsBody = $0.closest('tbody').querySelectorAll('tr') |
| 152 | + if (methodsBody) { |
| 153 | + Array.from(methodsBody).forEach((item) => { |
| 154 | + const name = item.children[0].textContent.split('(')[0] |
| 155 | + const description = item.children[1].textContent |
| 156 | + const params = item.children[2] |
| 157 | + ? item.children[2].textContent |
| 158 | + : item.children[0].textContent.split('(')[1] |
| 159 | + ? `(${item.children[0].textContent.split('(')[1]}` |
| 160 | + : '' |
| 161 | + methods.push({ name, description, description_zh: description, params }) |
| 162 | + }) |
| 163 | + } |
| 164 | + copyToClipboard(JSON.stringify(methods, null, 2)) |
| 165 | + |
| 166 | + return methods |
| 167 | +} |
| 168 | + |
| 169 | +function copyToClipboard(text) { |
| 170 | + const textArea = document.createElement('textarea'); |
| 171 | + textArea.value = text; |
| 172 | + document.body.appendChild(textArea); |
| 173 | + textArea.select(); |
| 174 | + textArea.setSelectionRange(0, 99999); // 选中全部内容 |
| 175 | + document.execCommand('copy'); |
| 176 | + document.body.removeChild(textArea); |
| 177 | +} |
| 178 | + |
0 commit comments