Skip to content

Commit 909552e

Browse files
committed
Moved regEx.<commit|sri>Hash to .hash
1 parent 868703e commit 909552e

File tree

8 files changed

+43
-42
lines changed

8 files changed

+43
-42
lines changed

amazongpt/utils/bump/resources.js

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

2424
// Init REGEX
2525
const regEx = {
26+
hash: { commit: /(@|\?v=)([^/#]+)/, sri: /[^#]+$/ },
2627
resName: /[^/]+\/(?:dist)?\/?[^/]+\.js(?=[?#]|$)/,
27-
jsURL: /^\/\/ @require\s+(https:\/\/cdn\.jsdelivr\.net\/gh\/.+)$/,
28-
commitHash: /(@|\?v=)([^/#]+)/, sriHash: /[^#]+$/
28+
jsURL: /^\/\/ @require\s+(https:\/\/cdn\.jsdelivr\.net\/gh\/.+)$/
2929
}
3030

3131
// Define FUNCTIONS
@@ -125,22 +125,22 @@
125125
// Compare/update commit hash
126126
let resLatestCommitHash = latestCommitHashes[resURL.includes(repoName) ? 'chromium' : 'aiweb']
127127
if (resLatestCommitHash.startsWith( // compare hashes
128-
regEx.commitHash.exec(resURL)?.[2] || '')) { // commit hash didn't change...
128+
regEx.hash.commit.exec(resURL)?.[2] || '')) { // commit hash didn't change...
129129
console.log(`${resName} already up-to-date!`) ; log.endedWithLineBreak = false
130130
continue // ...so skip resource
131131
}
132132
resLatestCommitHash = resLatestCommitHash.substring(0, 7) // abbr it
133-
let updatedURL = resURL.replace(regEx.commitHash, `$1${resLatestCommitHash}`) // update hash
133+
let updatedURL = resURL.replace(regEx.hash.commit, `$1${resLatestCommitHash}`) // update hash
134134
if (!await isValidResource(updatedURL)) continue // to next resource
135135

136136
// Generate/compare/update SRI hash
137137
console.log(`${ !log.endedWithLineBreak ? '\n' : '' }Generating SRI (SHA-256) hash for ${resName}...`)
138138
const newSRIhash = await generateSRIhash(updatedURL)
139-
if (regEx.sriHash.exec(resURL)?.[0] == newSRIhash) { // SRI hash didn't change
139+
if (regEx.hash.sri.exec(resURL)?.[0] == newSRIhash) { // SRI hash didn't change
140140
console.log(`${resName} already up-to-date!`) ; log.endedWithLineBreak = false
141141
continue // ...so skip resource
142142
}
143-
updatedURL = updatedURL.replace(regEx.sriHash, newSRIhash) // update hash
143+
updatedURL = updatedURL.replace(regEx.hash.sri, newSRIhash) // update hash
144144
if (!await isValidResource(updatedURL)) continue // to next resource
145145

146146
// Write updated URL to userscript

bravegpt/utils/bump/resources.js

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

2424
// Init REGEX
2525
const regEx = {
26+
hash: { commit: /(@|\?v=)([^/#]+)/, sri: /[^#]+$/ },
2627
resName: /[^/]+\/(?:dist)?\/?[^/]+\.js(?=[?#]|$)/,
27-
jsURL: /^\/\/ @require\s+(https:\/\/cdn\.jsdelivr\.net\/gh\/.+)$/,
28-
commitHash: /(@|\?v=)([^/#]+)/, sriHash: /[^#]+$/
28+
jsURL: /^\/\/ @require\s+(https:\/\/cdn\.jsdelivr\.net\/gh\/.+)$/
2929
}
3030

3131
// Define FUNCTIONS
@@ -125,22 +125,22 @@
125125
// Compare/update commit hash
126126
let resLatestCommitHash = latestCommitHashes[resURL.includes(repoName) ? 'chromium' : 'aiweb']
127127
if (resLatestCommitHash.startsWith( // compare hashes
128-
regEx.commitHash.exec(resURL)?.[2] || '')) { // commit hash didn't change...
128+
regEx.hash.commit.exec(resURL)?.[2] || '')) { // commit hash didn't change...
129129
console.log(`${resName} already up-to-date!`) ; log.endedWithLineBreak = false
130130
continue // ...so skip resource
131131
}
132132
resLatestCommitHash = resLatestCommitHash.substring(0, 7) // abbr it
133-
let updatedURL = resURL.replace(regEx.commitHash, `$1${resLatestCommitHash}`) // update hash
133+
let updatedURL = resURL.replace(regEx.hash.commit, `$1${resLatestCommitHash}`) // update hash
134134
if (!await isValidResource(updatedURL)) continue // to next resource
135135

136136
// Generate/compare/update SRI hash
137137
console.log(`${ !log.endedWithLineBreak ? '\n' : '' }Generating SRI (SHA-256) hash for ${resName}...`)
138138
const newSRIhash = await generateSRIhash(updatedURL)
139-
if (regEx.sriHash.exec(resURL)?.[0] == newSRIhash) { // SRI hash didn't change
139+
if (regEx.hash.sri.exec(resURL)?.[0] == newSRIhash) { // SRI hash didn't change
140140
console.log(`${resName} already up-to-date!`) ; log.endedWithLineBreak = false
141141
continue // ...so skip resource
142142
}
143-
updatedURL = updatedURL.replace(regEx.sriHash, newSRIhash) // update hash
143+
updatedURL = updatedURL.replace(regEx.hash.sri, newSRIhash) // update hash
144144
if (!await isValidResource(updatedURL)) continue // to next resource
145145

146146
// Write updated URL to userscript

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

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

2828
// Init REGEX
2929
const regEx = {
30+
hash: { commit: /(@|\?v=)([^/#]+)/, sri: /[^#]+$/ },
3031
resName: /[^/]+\/(?:dist)?\/?[^/]+\.js(?=[?#]|$)/,
31-
jsURL: /^\/\/ @require\s+(https:\/\/cdn\.jsdelivr\.net\/gh\/.+)$/,
32-
commitHash: /(@|\?v=)([^/#]+)/, sriHash: /[^#]+$/
32+
jsURL: /^\/\/ @require\s+(https:\/\/cdn\.jsdelivr\.net\/gh\/.+)$/
3333
}
3434

3535
// Define FUNCTIONS
@@ -129,22 +129,22 @@
129129
// Compare/update commit hash
130130
let resLatestCommitHash = latestCommitHashes[resURL.includes(repoName) ? 'chromium' : 'aiweb']
131131
if (resLatestCommitHash.startsWith( // compare hashes
132-
regEx.commitHash.exec(resURL)?.[2] || '')) { // commit hash didn't change...
132+
regEx.hash.commit.exec(resURL)?.[2] || '')) { // commit hash didn't change...
133133
console.log(`${resName} already up-to-date!`) ; log.endedWithLineBreak = false
134134
continue // ...so skip resource
135135
}
136136
resLatestCommitHash = resLatestCommitHash.substring(0, 7) // abbr it
137-
let updatedURL = resURL.replace(regEx.commitHash, `$1${resLatestCommitHash}`) // update hash
137+
let updatedURL = resURL.replace(regEx.hash.commit, `$1${resLatestCommitHash}`) // update hash
138138
if (!await isValidResource(updatedURL)) continue // to next resource
139139

140140
// Generate/compare/update SRI hash
141141
console.log(`${ !log.endedWithLineBreak ? '\n' : '' }Generating SRI (SHA-256) hash for ${resName}...`)
142142
const newSRIhash = await generateSRIhash(updatedURL)
143-
if (regEx.sriHash.exec(resURL)?.[0] == newSRIhash) { // SRI hash didn't change
143+
if (regEx.hash.sri.exec(resURL)?.[0] == newSRIhash) { // SRI hash didn't change
144144
console.log(`${resName} already up-to-date!`) ; log.endedWithLineBreak = false
145145
continue // ...so skip resource
146146
}
147-
updatedURL = updatedURL.replace(regEx.sriHash, newSRIhash) // update hash
147+
updatedURL = updatedURL.replace(regEx.hash.sri, newSRIhash) // update hash
148148
if (!await isValidResource(updatedURL)) continue // to next resource
149149

150150
// Write updated URL to userscript

chatgpt-infinity/utils/bump/resources.js

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

2828
// Init REGEX
2929
const regEx = {
30+
hash: { commit: /(@|\?v=)([^/#]+)/, sri: /[^#]+$/ },
3031
resName: /[^/]+\/(?:dist)?\/?[^/]+\.js(?=[?#]|$)/,
31-
jsURL: /^\/\/ @require\s+(https:\/\/cdn\.jsdelivr\.net\/gh\/.+)$/,
32-
commitHash: /(@|\?v=)([^/#]+)/, sriHash: /[^#]+$/
32+
jsURL: /^\/\/ @require\s+(https:\/\/cdn\.jsdelivr\.net\/gh\/.+)$/
3333
}
3434

3535
// Define FUNCTIONS
@@ -129,22 +129,22 @@
129129
// Compare/update commit hash
130130
let resLatestCommitHash = latestCommitHashes[resURL.includes(repoName) ? 'chromium' : 'aiweb']
131131
if (resLatestCommitHash.startsWith( // compare hashes
132-
regEx.commitHash.exec(resURL)?.[2] || '')) { // commit hash didn't change...
132+
regEx.hash.commit.exec(resURL)?.[2] || '')) { // commit hash didn't change...
133133
console.log(`${resName} already up-to-date!`) ; log.endedWithLineBreak = false
134134
continue // ...so skip resource
135135
}
136136
resLatestCommitHash = resLatestCommitHash.substring(0, 7) // abbr it
137-
let updatedURL = resURL.replace(regEx.commitHash, `$1${resLatestCommitHash}`) // update hash
137+
let updatedURL = resURL.replace(regEx.hash.commit, `$1${resLatestCommitHash}`) // update hash
138138
if (!await isValidResource(updatedURL)) continue // to next resource
139139

140140
// Generate/compare/update SRI hash
141141
console.log(`${ !log.endedWithLineBreak ? '\n' : '' }Generating SRI (SHA-256) hash for ${resName}...`)
142142
const newSRIhash = await generateSRIhash(updatedURL)
143-
if (regEx.sriHash.exec(resURL)?.[0] == newSRIhash) { // SRI hash didn't change
143+
if (regEx.hash.sri.exec(resURL)?.[0] == newSRIhash) { // SRI hash didn't change
144144
console.log(`${resName} already up-to-date!`) ; log.endedWithLineBreak = false
145145
continue // ...so skip resource
146146
}
147-
updatedURL = updatedURL.replace(regEx.sriHash, newSRIhash) // update hash
147+
updatedURL = updatedURL.replace(regEx.hash.sri, newSRIhash) // update hash
148148
if (!await isValidResource(updatedURL)) continue // to next resource
149149

150150
// Write updated URL to userscript

chatgpt-widescreen/utils/bump/resources.js

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

2424
// Init REGEX
2525
const regEx = {
26+
hash: { commit: /(@|\?v=)([^/#]+)/, sri: /[^#]+$/ },
2627
resName: /[^/]+\/(?:dist)?\/?[^/]+\.js(?=[?#]|$)/,
27-
jsURL: /^\/\/ @require\s+(https:\/\/cdn\.jsdelivr\.net\/gh\/.+)$/,
28-
commitHash: /(@|\?v=)([^/#]+)/, sriHash: /[^#]+$/
28+
jsURL: /^\/\/ @require\s+(https:\/\/cdn\.jsdelivr\.net\/gh\/.+)$/
2929
}
3030

3131
// Define FUNCTIONS
@@ -125,22 +125,22 @@
125125
// Compare/update commit hash
126126
let resLatestCommitHash = latestCommitHashes[resURL.includes(repoName) ? 'chromium' : 'aiweb']
127127
if (resLatestCommitHash.startsWith( // compare hashes
128-
regEx.commitHash.exec(resURL)?.[2] || '')) { // commit hash didn't change...
128+
regEx.hash.commit.exec(resURL)?.[2] || '')) { // commit hash didn't change...
129129
console.log(`${resName} already up-to-date!`) ; log.endedWithLineBreak = false
130130
continue // ...so skip resource
131131
}
132132
resLatestCommitHash = resLatestCommitHash.substring(0, 7) // abbr it
133-
let updatedURL = resURL.replace(regEx.commitHash, `$1${resLatestCommitHash}`) // update hash
133+
let updatedURL = resURL.replace(regEx.hash.commit, `$1${resLatestCommitHash}`) // update hash
134134
if (!await isValidResource(updatedURL)) continue // to next resource
135135

136136
// Generate/compare/update SRI hash
137137
console.log(`${ !log.endedWithLineBreak ? '\n' : '' }Generating SRI (SHA-256) hash for ${resName}...`)
138138
const newSRIhash = await generateSRIhash(updatedURL)
139-
if (regEx.sriHash.exec(resURL)?.[0] == newSRIhash) { // SRI hash didn't change
139+
if (regEx.hash.sri.exec(resURL)?.[0] == newSRIhash) { // SRI hash didn't change
140140
console.log(`${resName} already up-to-date!`) ; log.endedWithLineBreak = false
141141
continue // ...so skip resource
142142
}
143-
updatedURL = updatedURL.replace(regEx.sriHash, newSRIhash) // update hash
143+
updatedURL = updatedURL.replace(regEx.hash.sri, newSRIhash) // update hash
144144
if (!await isValidResource(updatedURL)) continue // to next resource
145145

146146
// Write updated URL to userscript

duckduckgpt/utils/bump/resources.js

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

2424
// Init REGEX
2525
const regEx = {
26+
hash: { commit: /(@|\?v=)([^/#]+)/, sri: /[^#]+$/ },
2627
resName: /[^/]+\/(?:dist)?\/?[^/]+\.js(?=[?#]|$)/,
27-
jsURL: /^\/\/ @require\s+(https:\/\/cdn\.jsdelivr\.net\/gh\/.+)$/,
28-
commitHash: /(@|\?v=)([^/#]+)/, sriHash: /[^#]+$/
28+
jsURL: /^\/\/ @require\s+(https:\/\/cdn\.jsdelivr\.net\/gh\/.+)$/
2929
}
3030

3131
// Define FUNCTIONS
@@ -125,22 +125,22 @@
125125
// Compare/update commit hash
126126
let resLatestCommitHash = latestCommitHashes[resURL.includes(repoName) ? 'chromium' : 'aiweb']
127127
if (resLatestCommitHash.startsWith( // compare hashes
128-
regEx.commitHash.exec(resURL)?.[2] || '')) { // commit hash didn't change...
128+
regEx.hash.commit.exec(resURL)?.[2] || '')) { // commit hash didn't change...
129129
console.log(`${resName} already up-to-date!`) ; log.endedWithLineBreak = false
130130
continue // ...so skip resource
131131
}
132132
resLatestCommitHash = resLatestCommitHash.substring(0, 7) // abbr it
133-
let updatedURL = resURL.replace(regEx.commitHash, `$1${resLatestCommitHash}`) // update hash
133+
let updatedURL = resURL.replace(regEx.hash.commit, `$1${resLatestCommitHash}`) // update hash
134134
if (!await isValidResource(updatedURL)) continue // to next resource
135135

136136
// Generate/compare/update SRI hash
137137
console.log(`${ !log.endedWithLineBreak ? '\n' : '' }Generating SRI (SHA-256) hash for ${resName}...`)
138138
const newSRIhash = await generateSRIhash(updatedURL)
139-
if (regEx.sriHash.exec(resURL)?.[0] == newSRIhash) { // SRI hash didn't change
139+
if (regEx.hash.sri.exec(resURL)?.[0] == newSRIhash) { // SRI hash didn't change
140140
console.log(`${resName} already up-to-date!`) ; log.endedWithLineBreak = false
141141
continue // ...so skip resource
142142
}
143-
updatedURL = updatedURL.replace(regEx.sriHash, newSRIhash) // update hash
143+
updatedURL = updatedURL.replace(regEx.hash.sri, newSRIhash) // update hash
144144
if (!await isValidResource(updatedURL)) continue // to next resource
145145

146146
// Write updated URL to userscript

googlegpt/utils/bump/resources.js

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

2424
// Init REGEX
2525
const regEx = {
26+
hash: { commit: /(@|\?v=)([^/#]+)/, sri: /[^#]+$/ },
2627
resName: /[^/]+\/(?:dist)?\/?[^/]+\.js(?=[?#]|$)/,
27-
jsURL: /^\/\/ @require\s+(https:\/\/cdn\.jsdelivr\.net\/gh\/.+)$/,
28-
commitHash: /(@|\?v=)([^/#]+)/, sriHash: /[^#]+$/
28+
jsURL: /^\/\/ @require\s+(https:\/\/cdn\.jsdelivr\.net\/gh\/.+)$/
2929
}
3030

3131
// Define FUNCTIONS
@@ -125,22 +125,22 @@
125125
// Compare/update commit hash
126126
let resLatestCommitHash = latestCommitHashes[resURL.includes(repoName) ? 'chromium' : 'aiweb']
127127
if (resLatestCommitHash.startsWith( // compare hashes
128-
regEx.commitHash.exec(resURL)?.[2] || '')) { // commit hash didn't change...
128+
regEx.hash.commit.exec(resURL)?.[2] || '')) { // commit hash didn't change...
129129
console.log(`${resName} already up-to-date!`) ; log.endedWithLineBreak = false
130130
continue // ...so skip resource
131131
}
132132
resLatestCommitHash = resLatestCommitHash.substring(0, 7) // abbr it
133-
let updatedURL = resURL.replace(regEx.commitHash, `$1${resLatestCommitHash}`) // update hash
133+
let updatedURL = resURL.replace(regEx.hash.commit, `$1${resLatestCommitHash}`) // update hash
134134
if (!await isValidResource(updatedURL)) continue // to next resource
135135

136136
// Generate/compare/update SRI hash
137137
console.log(`${ !log.endedWithLineBreak ? '\n' : '' }Generating SRI (SHA-256) hash for ${resName}...`)
138138
const newSRIhash = await generateSRIhash(updatedURL)
139-
if (regEx.sriHash.exec(resURL)?.[0] == newSRIhash) { // SRI hash didn't change
139+
if (regEx.hash.sri.exec(resURL)?.[0] == newSRIhash) { // SRI hash didn't change
140140
console.log(`${resName} already up-to-date!`) ; log.endedWithLineBreak = false
141141
continue // ...so skip resource
142142
}
143-
updatedURL = updatedURL.replace(regEx.sriHash, newSRIhash) // update hash
143+
updatedURL = updatedURL.replace(regEx.hash.sri, newSRIhash) // update hash
144144
if (!await isValidResource(updatedURL)) continue // to next resource
145145

146146
// Write updated URL to userscript

utils/bump/resources.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
// Init REGEX
2828
const regEx = {
29+
hash: { commit: /(@|\?v=)([^/#]+)/, sri: /[^#]+$/ },
2930
hash: { commit: /(@|\?v=)([^/#]+)/, sri: /[^#]+$/ },
3031
resName: /[^/]+\/(?:dist)?\/?[^/]+\.js(?=[?#]|$)/,
3132
url: {

0 commit comments

Comments
 (0)