-
Notifications
You must be signed in to change notification settings - Fork 2
/
bulk.html
99 lines (92 loc) · 2.87 KB
/
bulk.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<script src="https://unpkg.com/vue@next/dist/vue.global.js"></script>
<div id="app">
<button type="button" @click="uploadCsv">Upload csv</button>
</div>
<script>
window.showOpenFilePicker = (options) => {
return new Promise((resolve) => {
const input = document.createElement('input')
input.type = 'file'
input.multiple = options.multiple
input.accept = options.types
.map((type) => type.accept)
.flatMap((inst) => Object.keys(inst).flatMap((key) => inst[key]))
.join(',')
input.addEventListener('change', () => {
resolve(
[...input.files].map((file) => {
return {
getFile: async () =>
new Promise((resolve) => {
resolve(file)
}),
}
}),
)
})
input.click()
})
}
</script>
<script type="module">
import getEnabledAddonIds from './module.js'
window.vue = Vue.createApp({
data() {
return {
addonInstances: {},
dataArr: [],
addonTypes: {},
}
},
async mounted() {},
methods: {
async uploadCsv() {
const reader = new FileReader()
const [{ getFile }] = await window.showOpenFilePicker({
types: [{ accept: { 'text/*': ['.csv'] } }],
})
reader.readAsText(await getFile())
reader.addEventListener(
'load',
() => {
this.dataArr = reader.result
.replaceAll('\r', '')
.split('\n')
.map((s) => s.split(','))
this.countInstances()
},
false,
)
},
async countInstances() {
let amtOfEnabledAddons = ''
for (const arr of this.dataArr) {
const res = await getEnabledAddonIds(arr[0], arr[1])
amtOfEnabledAddons += `${res.length}\n`
for (const addonId of res) {
this.addonInstances[addonId] ??= 0
this.addonInstances[addonId]++
}
}
for (const addonId of Object.keys(this.addonInstances)) {
const res = await fetch(
`https://raw.githubusercontent.com/ScratchAddons/ScratchAddons/master/addons/${addonId}/addon.json`,
)
const json = await res.json()
if (json.enabledByDefault) this.addonTypes[addonId] = 'default'
else if (json.tags.includes('recommended'))
this.addonTypes[addonId] = 'recommended'
else if (json.tags.includes('featured'))
this.addonTypes[addonId] = 'featured'
else this.addonTypes[addonId] = 'none'
}
let str = ''
for (const key of Object.keys(this.addonInstances)) {
str += `${key},${this.addonInstances[key]},${this.addonTypes[key]}\n`
}
console.log(str)
console.log(amtOfEnabledAddons)
},
},
}).mount('#app')
</script>