Skip to content

Commit

Permalink
dont dare to use this yet.
Browse files Browse the repository at this point in the history
  • Loading branch information
zrodevkaan committed Oct 21, 2023
1 parent 6bc28cc commit aed7bb6
Showing 1 changed file with 58 additions and 18 deletions.
76 changes: 58 additions & 18 deletions index.js
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, '\\$&');
}

0 comments on commit aed7bb6

Please sign in to comment.