Skip to content

Commit 40ce9b8

Browse files
committed
Shortened var names
1 parent 3508574 commit 40ce9b8

File tree

4 files changed

+111
-113
lines changed

4 files changed

+111
-113
lines changed

chatgpt-auto-continue/utils/bump/resources.js

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
// Init REGEX
2929
const rePatterns = {
30-
resourceName: /[^/]+\/(?:css|dist)?\/?[^/]+\.(?:css|js)(?=[?#]|$)/,
30+
resName: /[^/]+\/(?:css|dist)?\/?[^/]+\.(?:css|js)(?=[?#]|$)/,
3131
cssURL: /^\/\/ @resource.+(https:\/\/assets.+\.css.+)$/,
3232
jsURL: /^\/\/ @require\s+(https:\/\/cdn\.jsdelivr\.net\/gh\/.+)$/,
3333
commitHash: /(@|\?v=)([^/#]+)/, sriHash: /[^#]+$/
@@ -59,13 +59,13 @@
5959
return fetch(url)
6060
}
6161

62-
async function isValidResource(resourceURL) {
62+
async function isValidResource(resURL) {
6363
try {
64-
const resourceIsValid = !(await (await fetchData(resourceURL)).text()).startsWith('Package size exceeded')
65-
if (!resourceIsValid) log.error(`\nInvalid resource: ${resourceURL}\n`)
66-
return resourceIsValid
64+
const resIsValid = !(await (await fetchData(resURL)).text()).startsWith('Package size exceeded')
65+
if (!resIsValid) log.error(`\nInvalid resource: ${resURL}\n`)
66+
return resIsValid
6767
} catch (err) {
68-
log.error(`\nCannot validate resource: ${resourceURL}\n`)
68+
log.error(`\nCannot validate resource: ${resURL}\n`)
6969
return null
7070
}
7171
}
@@ -106,10 +106,10 @@
106106
// Collect resourcs
107107
log.working('\nCollecting resources...\n')
108108
const userJScontent = fs.readFileSync(userJSfilePath, 'utf-8')
109-
const reResourceURL = new RegExp( // eslint-disable-next-line
109+
const reResURL = new RegExp( // eslint-disable-next-line
110110
`(?:${rePatterns.cssURL.source})|(?:${rePatterns.jsURL.source})`, 'gm')
111-
const resourceURLs = [...userJScontent.matchAll(reResourceURL)].map(match => match[1] || match[2])
112-
log.success(`${resourceURLs.length} potentially bumpable resource(s) found.`)
111+
const resURLs = [...userJScontent.matchAll(reResURL)].map(match => match[1] || match[2])
112+
log.success(`${resURLs.length} potentially bumpable resource(s) found.`)
113113

114114
// Fetch latest commit hash for adamlui/ai-web-extensions/assets/styles/rising-stars
115115
const risingStarsPath = 'assets/styles/rising-stars'
@@ -120,46 +120,46 @@
120120
let urlsUpdatedCnt = 0
121121

122122
// Fetch latest commit hash for repo/chrom<e|ium>/extension
123-
if (resourceURLs.some(url => url.includes(repoName))) {
123+
if (resURLs.some(url => url.includes(repoName))) {
124124
console.log('Fetching latest commit hash for Chromium extension...')
125125
for (const chrDirName of ['chromium', 'chrome']) {
126-
latestCommitHashes.repoResources = await getLatestCommitHash(
126+
latestCommitHashes.repoRes = await getLatestCommitHash(
127127
`adamlui/${repoName}`, `${chrDirName}/extension`)
128-
if (latestCommitHashes.repoResources) break
128+
if (latestCommitHashes.repoRes) break
129129
}
130130
}
131131

132132
// Process each resource
133-
for (const resourceURL of resourceURLs) {
134-
if (!await isValidResource(resourceURL)) continue
135-
const resourceName = rePatterns.resourceName.exec(resourceURL)?.[0] || 'resource' // dir/filename for logs
133+
for (const resURL of resURLs) {
134+
if (!await isValidResource(resURL)) continue
135+
const resName = rePatterns.resName.exec(resURL)?.[0] || 'resource' // dir/filename for logs
136136

137137
// Compare commit hashes
138-
const resourceLatestCommitHash = latestCommitHashes[
139-
resourceURL.includes(repoName) ? 'repoResources' : 'risingStars']
140-
if (resourceLatestCommitHash.startsWith(
141-
rePatterns.commitHash.exec(resourceURL)?.[2] || '')) { // commit hash didn't change...
142-
console.log(`${resourceName} already up-to-date!`) ; log.endedWithLineBreak = false
138+
const resLatestCommitHash = latestCommitHashes[
139+
resURL.includes(repoName) ? 'repoRes' : 'risingStars']
140+
if (resLatestCommitHash.startsWith(
141+
rePatterns.commitHash.exec(resURL)?.[2] || '')) { // commit hash didn't change...
142+
console.log(`${resName} already up-to-date!`) ; log.endedWithLineBreak = false
143143
continue // ...so skip resource
144144
}
145-
let updatedURL = resourceURL.replace(rePatterns.commitHash, `$1${resourceLatestCommitHash}`) // otherwise update commit hash
145+
let updatedURL = resURL.replace(rePatterns.commitHash, `$1${resLatestCommitHash}`) // otherwise update commit hash
146146
if (!await isValidResource(updatedURL)) continue
147147

148148
// Generate/compare SRI hash
149-
console.log(`${ !log.endedWithLineBreak ? '\n' : '' }Generating SHA-256 hash for ${resourceName}...`)
149+
console.log(`${ !log.endedWithLineBreak ? '\n' : '' }Generating SHA-256 hash for ${resName}...`)
150150
const newSRIhash = await getSRIhash(updatedURL)
151-
if (rePatterns.sriHash.exec(resourceURL)?.[0] == newSRIhash) { // SRI hash didn't change
152-
console.log(`${resourceName} already up-to-date!`) ; log.endedWithLineBreak = false
151+
if (rePatterns.sriHash.exec(resURL)?.[0] == newSRIhash) { // SRI hash didn't change
152+
console.log(`${resName} already up-to-date!`) ; log.endedWithLineBreak = false
153153
continue // ...so skip resource
154154
}
155155
updatedURL = updatedURL.replace(rePatterns.sriHash, newSRIhash) // otherwise update SRI hash
156156
if (!await isValidResource(updatedURL)) continue
157157

158158
// Write updated URL to userscript
159-
console.log(`Writing updated URL for ${resourceName}...`)
159+
console.log(`Writing updated URL for ${resName}...`)
160160
const userJScontent = fs.readFileSync(userJSfilePath, 'utf-8')
161-
fs.writeFileSync(userJSfilePath, userJScontent.replace(resourceURL, updatedURL), 'utf-8')
162-
log.success(`${resourceName} bumped!\n`)
161+
fs.writeFileSync(userJSfilePath, userJScontent.replace(resURL, updatedURL), 'utf-8')
162+
log.success(`${resName} bumped!\n`)
163163
urlsUpdatedCnt++
164164
}
165165
if (urlsUpdatedCnt > 0) {

chatgpt-infinity/utils/bump/resources.js

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
// Init REGEX
2929
const rePatterns = {
30-
resourceName: /[^/]+\/(?:css|dist)?\/?[^/]+\.(?:css|js)(?=[?#]|$)/,
30+
resName: /[^/]+\/(?:css|dist)?\/?[^/]+\.(?:css|js)(?=[?#]|$)/,
3131
cssURL: /^\/\/ @resource.+(https:\/\/assets.+\.css.+)$/,
3232
jsURL: /^\/\/ @require\s+(https:\/\/cdn\.jsdelivr\.net\/gh\/.+)$/,
3333
commitHash: /(@|\?v=)([^/#]+)/, sriHash: /[^#]+$/
@@ -59,13 +59,13 @@
5959
return fetch(url)
6060
}
6161

62-
async function isValidResource(resourceURL) {
62+
async function isValidResource(resURL) {
6363
try {
64-
const resourceIsValid = !(await (await fetchData(resourceURL)).text()).startsWith('Package size exceeded')
65-
if (!resourceIsValid) log.error(`\nInvalid resource: ${resourceURL}\n`)
66-
return resourceIsValid
64+
const resIsValid = !(await (await fetchData(resURL)).text()).startsWith('Package size exceeded')
65+
if (!resIsValid) log.error(`\nInvalid resource: ${resURL}\n`)
66+
return resIsValid
6767
} catch (err) {
68-
log.error(`\nCannot validate resource: ${resourceURL}\n`)
68+
log.error(`\nCannot validate resource: ${resURL}\n`)
6969
return null
7070
}
7171
}
@@ -106,10 +106,10 @@
106106
// Collect resourcs
107107
log.working('\nCollecting resources...\n')
108108
const userJScontent = fs.readFileSync(userJSfilePath, 'utf-8')
109-
const reResourceURL = new RegExp( // eslint-disable-next-line
109+
const reResURL = new RegExp( // eslint-disable-next-line
110110
`(?:${rePatterns.cssURL.source})|(?:${rePatterns.jsURL.source})`, 'gm')
111-
const resourceURLs = [...userJScontent.matchAll(reResourceURL)].map(match => match[1] || match[2])
112-
log.success(`${resourceURLs.length} potentially bumpable resource(s) found.`)
111+
const resURLs = [...userJScontent.matchAll(reResURL)].map(match => match[1] || match[2])
112+
log.success(`${resURLs.length} potentially bumpable resource(s) found.`)
113113

114114
// Fetch latest commit hash for adamlui/ai-web-extensions/assets/styles/rising-stars
115115
const risingStarsPath = 'assets/styles/rising-stars'
@@ -120,46 +120,46 @@
120120
let urlsUpdatedCnt = 0
121121

122122
// Fetch latest commit hash for repo/chrom<e|ium>/extension
123-
if (resourceURLs.some(url => url.includes(repoName))) {
123+
if (resURLs.some(url => url.includes(repoName))) {
124124
console.log('Fetching latest commit hash for Chromium extension...')
125125
for (const chrDirName of ['chromium', 'chrome']) {
126-
latestCommitHashes.repoResources = await getLatestCommitHash(
126+
latestCommitHashes.repoRes = await getLatestCommitHash(
127127
`adamlui/${repoName}`, `${chrDirName}/extension`)
128-
if (latestCommitHashes.repoResources) break
128+
if (latestCommitHashes.repoRes) break
129129
}
130130
}
131131

132132
// Process each resource
133-
for (const resourceURL of resourceURLs) {
134-
if (!await isValidResource(resourceURL)) continue
135-
const resourceName = rePatterns.resourceName.exec(resourceURL)?.[0] || 'resource' // dir/filename for logs
133+
for (const resURL of resURLs) {
134+
if (!await isValidResource(resURL)) continue
135+
const resName = rePatterns.resName.exec(resURL)?.[0] || 'resource' // dir/filename for logs
136136

137137
// Compare commit hashes
138-
const resourceLatestCommitHash = latestCommitHashes[
139-
resourceURL.includes(repoName) ? 'repoResources' : 'risingStars']
140-
if (resourceLatestCommitHash.startsWith(
141-
rePatterns.commitHash.exec(resourceURL)?.[2] || '')) { // commit hash didn't change...
142-
console.log(`${resourceName} already up-to-date!`) ; log.endedWithLineBreak = false
138+
const resLatestCommitHash = latestCommitHashes[
139+
resURL.includes(repoName) ? 'repoRes' : 'risingStars']
140+
if (resLatestCommitHash.startsWith(
141+
rePatterns.commitHash.exec(resURL)?.[2] || '')) { // commit hash didn't change...
142+
console.log(`${resName} already up-to-date!`) ; log.endedWithLineBreak = false
143143
continue // ...so skip resource
144144
}
145-
let updatedURL = resourceURL.replace(rePatterns.commitHash, `$1${resourceLatestCommitHash}`) // otherwise update commit hash
145+
let updatedURL = resURL.replace(rePatterns.commitHash, `$1${resLatestCommitHash}`) // otherwise update commit hash
146146
if (!await isValidResource(updatedURL)) continue
147147

148148
// Generate/compare SRI hash
149-
console.log(`${ !log.endedWithLineBreak ? '\n' : '' }Generating SHA-256 hash for ${resourceName}...`)
149+
console.log(`${ !log.endedWithLineBreak ? '\n' : '' }Generating SHA-256 hash for ${resName}...`)
150150
const newSRIhash = await getSRIhash(updatedURL)
151-
if (rePatterns.sriHash.exec(resourceURL)?.[0] == newSRIhash) { // SRI hash didn't change
152-
console.log(`${resourceName} already up-to-date!`) ; log.endedWithLineBreak = false
151+
if (rePatterns.sriHash.exec(resURL)?.[0] == newSRIhash) { // SRI hash didn't change
152+
console.log(`${resName} already up-to-date!`) ; log.endedWithLineBreak = false
153153
continue // ...so skip resource
154154
}
155155
updatedURL = updatedURL.replace(rePatterns.sriHash, newSRIhash) // otherwise update SRI hash
156156
if (!await isValidResource(updatedURL)) continue
157157

158158
// Write updated URL to userscript
159-
console.log(`Writing updated URL for ${resourceName}...`)
159+
console.log(`Writing updated URL for ${resName}...`)
160160
const userJScontent = fs.readFileSync(userJSfilePath, 'utf-8')
161-
fs.writeFileSync(userJSfilePath, userJScontent.replace(resourceURL, updatedURL), 'utf-8')
162-
log.success(`${resourceName} bumped!\n`)
161+
fs.writeFileSync(userJSfilePath, userJScontent.replace(resURL, updatedURL), 'utf-8')
162+
log.success(`${resName} bumped!\n`)
163163
urlsUpdatedCnt++
164164
}
165165
if (urlsUpdatedCnt > 0) {

chatgpt-widescreen/utils/bump/resources.js

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
// Init REGEX
2525
const rePatterns = {
26-
resourceName: /[^/]+\/(?:css|dist)?\/?[^/]+\.(?:css|js)(?=[?#]|$)/,
26+
resName: /[^/]+\/(?:css|dist)?\/?[^/]+\.(?:css|js)(?=[?#]|$)/,
2727
cssURL: /^\/\/ @resource.+(https:\/\/assets.+\.css.+)$/,
2828
jsURL: /^\/\/ @require\s+(https:\/\/cdn\.jsdelivr\.net\/gh\/.+)$/,
2929
commitHash: /(@|\?v=)([^/#]+)/, sriHash: /[^#]+$/
@@ -55,13 +55,13 @@
5555
return fetch(url)
5656
}
5757

58-
async function isValidResource(resourceURL) {
58+
async function isValidResource(resURL) {
5959
try {
60-
const resourceIsValid = !(await (await fetchData(resourceURL)).text()).startsWith('Package size exceeded')
61-
if (!resourceIsValid) log.error(`\nInvalid resource: ${resourceURL}\n`)
62-
return resourceIsValid
60+
const resIsValid = !(await (await fetchData(resURL)).text()).startsWith('Package size exceeded')
61+
if (!resIsValid) log.error(`\nInvalid resource: ${resURL}\n`)
62+
return resIsValid
6363
} catch (err) {
64-
log.error(`\nCannot validate resource: ${resourceURL}\n`)
64+
log.error(`\nCannot validate resource: ${resURL}\n`)
6565
return null
6666
}
6767
}
@@ -102,10 +102,10 @@
102102
// Collect resourcs
103103
log.working('\nCollecting resources...\n')
104104
const userJScontent = fs.readFileSync(userJSfilePath, 'utf-8')
105-
const reResourceURL = new RegExp( // eslint-disable-next-line
105+
const reResURL = new RegExp( // eslint-disable-next-line
106106
`(?:${rePatterns.cssURL.source})|(?:${rePatterns.jsURL.source})`, 'gm')
107-
const resourceURLs = [...userJScontent.matchAll(reResourceURL)].map(match => match[1] || match[2])
108-
log.success(`${resourceURLs.length} potentially bumpable resource(s) found.`)
107+
const resURLs = [...userJScontent.matchAll(reResURL)].map(match => match[1] || match[2])
108+
log.success(`${resURLs.length} potentially bumpable resource(s) found.`)
109109

110110
// Fetch latest commit hash for adamlui/ai-web-extensions/assets/styles/rising-stars
111111
const risingStarsPath = 'assets/styles/rising-stars'
@@ -116,46 +116,46 @@
116116
let urlsUpdatedCnt = 0
117117

118118
// Fetch latest commit hash for repo/chrom<e|ium>/extension
119-
if (resourceURLs.some(url => url.includes(repoName))) {
119+
if (resURLs.some(url => url.includes(repoName))) {
120120
console.log('Fetching latest commit hash for Chromium extension...')
121121
for (const chrDirName of ['chromium', 'chrome']) {
122-
latestCommitHashes.repoResources = await getLatestCommitHash(
122+
latestCommitHashes.repoRes = await getLatestCommitHash(
123123
`adamlui/${repoName}`, `${chrDirName}/extension`)
124-
if (latestCommitHashes.repoResources) break
124+
if (latestCommitHashes.repoRes) break
125125
}
126126
}
127127

128128
// Process each resource
129-
for (const resourceURL of resourceURLs) {
130-
if (!await isValidResource(resourceURL)) continue
131-
const resourceName = rePatterns.resourceName.exec(resourceURL)?.[0] || 'resource' // dir/filename for logs
129+
for (const resURL of resURLs) {
130+
if (!await isValidResource(resURL)) continue
131+
const resName = rePatterns.resName.exec(resURL)?.[0] || 'resource' // dir/filename for logs
132132

133133
// Compare commit hashes
134-
const resourceLatestCommitHash = latestCommitHashes[
135-
resourceURL.includes(repoName) ? 'repoResources' : 'risingStars']
136-
if (resourceLatestCommitHash.startsWith(
137-
rePatterns.commitHash.exec(resourceURL)?.[2] || '')) { // commit hash didn't change...
138-
console.log(`${resourceName} already up-to-date!`) ; log.endedWithLineBreak = false
134+
const resLatestCommitHash = latestCommitHashes[
135+
resURL.includes(repoName) ? 'repoRes' : 'risingStars']
136+
if (resLatestCommitHash.startsWith(
137+
rePatterns.commitHash.exec(resURL)?.[2] || '')) { // commit hash didn't change...
138+
console.log(`${resName} already up-to-date!`) ; log.endedWithLineBreak = false
139139
continue // ...so skip resource
140140
}
141-
let updatedURL = resourceURL.replace(rePatterns.commitHash, `$1${resourceLatestCommitHash}`) // otherwise update commit hash
141+
let updatedURL = resURL.replace(rePatterns.commitHash, `$1${resLatestCommitHash}`) // otherwise update commit hash
142142
if (!await isValidResource(updatedURL)) continue
143143

144144
// Generate/compare SRI hash
145-
console.log(`${ !log.endedWithLineBreak ? '\n' : '' }Generating SHA-256 hash for ${resourceName}...`)
145+
console.log(`${ !log.endedWithLineBreak ? '\n' : '' }Generating SHA-256 hash for ${resName}...`)
146146
const newSRIhash = await getSRIhash(updatedURL)
147-
if (rePatterns.sriHash.exec(resourceURL)?.[0] == newSRIhash) { // SRI hash didn't change
148-
console.log(`${resourceName} already up-to-date!`) ; log.endedWithLineBreak = false
147+
if (rePatterns.sriHash.exec(resURL)?.[0] == newSRIhash) { // SRI hash didn't change
148+
console.log(`${resName} already up-to-date!`) ; log.endedWithLineBreak = false
149149
continue // ...so skip resource
150150
}
151151
updatedURL = updatedURL.replace(rePatterns.sriHash, newSRIhash) // otherwise update SRI hash
152152
if (!await isValidResource(updatedURL)) continue
153153

154154
// Write updated URL to userscript
155-
console.log(`Writing updated URL for ${resourceName}...`)
155+
console.log(`Writing updated URL for ${resName}...`)
156156
const userJScontent = fs.readFileSync(userJSfilePath, 'utf-8')
157-
fs.writeFileSync(userJSfilePath, userJScontent.replace(resourceURL, updatedURL), 'utf-8')
158-
log.success(`${resourceName} bumped!\n`)
157+
fs.writeFileSync(userJSfilePath, userJScontent.replace(resURL, updatedURL), 'utf-8')
158+
log.success(`${resName} bumped!\n`)
159159
urlsUpdatedCnt++
160160
}
161161
if (urlsUpdatedCnt > 0) {

0 commit comments

Comments
 (0)