-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6bc28cc
commit aed7bb6
Showing
1 changed file
with
58 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,63 @@ | ||
window.onload = async () => { | ||
document.getElementById('file-input').addEventListener('change', function(e) { | ||
const selectedFile = e.target.files[0]; | ||
if (selectedFile) { | ||
console.log('Stealing file...'); | ||
const fileReader = new FileReader(); | ||
fileReader.onload = function(event) { | ||
const fileContents = event.target.result; | ||
console.log('File Contents:', fileContents); | ||
}; | ||
fileReader.readAsText(selectedFile); | ||
} | ||
}); | ||
window.onload = () => { | ||
fetch('./classes.json') | ||
.then(response => { | ||
if (!response.ok) { | ||
throw new Error('Network response was not ok'); | ||
} | ||
return response.json(); | ||
}) | ||
.then(classMappings => { | ||
console.log('Class Mappings:', classMappings); | ||
|
||
document.getElementById('file-input').addEventListener('change', function(e) { | ||
const selectedFile = e.target.files[0]; | ||
if (selectedFile) { | ||
const fileReader = new FileReader(); | ||
fileReader.onload = function(event) { | ||
let fileContents = event.target.result; | ||
|
||
const changes = []; | ||
classMappings.forEach(mapping => { | ||
for (const oldClass in mapping) { | ||
if (mapping.hasOwnProperty(oldClass)) { | ||
const newClass = mapping[oldClass]; | ||
const regex = new RegExp(`\\s\\.${escapeRegExp(oldClass)}(?=[\\s,:{])`, 'g'); | ||
const count = (fileContents.match(regex) || []).length; | ||
if (count > 0) { | ||
changes.push({ | ||
oldClass, | ||
newClass, | ||
count | ||
}); | ||
} | ||
fileContents = fileContents.replace(regex, ` ${newClass}`); | ||
} | ||
} | ||
}); | ||
|
||
console.log('Changes Made:'); | ||
changes.forEach(change => { | ||
console.log(`Replaced "${change.oldClass}" with "${change.newClass}" ${change.count} times.`); | ||
}); | ||
|
||
await fetch('./classes.json') | ||
.then(response => response.json()) | ||
.then(data => { | ||
console.log('JSON Data:', data); | ||
console.log('Modified File Contents:', fileContents); | ||
|
||
const modifiedBlob = new Blob([fileContents], { type: 'text/plain' }); | ||
|
||
const downloadLink = document.createElement('a'); | ||
downloadLink.href = URL.createObjectURL(modifiedBlob); | ||
downloadLink.download = 'Modified.theme.css'; | ||
downloadLink.click(); | ||
}; | ||
fileReader.readAsText(selectedFile); | ||
} | ||
}); | ||
}) | ||
.catch(error => { | ||
console.error('Error fetching or parsing JSON:', error); | ||
console.error('Error fetching or parsing class mappings:', error); | ||
}); | ||
}; | ||
|
||
function escapeRegExp(string) { | ||
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); | ||
} |