All checks were successful
Cooperate Cleaner Build / build-app (push) Successful in 45s
- Added match count logic - Refactored menu order
86 lines
2.7 KiB
JavaScript
86 lines
2.7 KiB
JavaScript
(function() {
|
|
let config;
|
|
|
|
$(document).ready(function() {
|
|
console.log("Initialization of cleaner.js finished.");
|
|
config = JSON.parse(window.localStorage.getItem("config"));
|
|
console.log(config);
|
|
init();
|
|
});
|
|
|
|
function init() {
|
|
$(document).keydown(function(event) {
|
|
if (event.altKey) {
|
|
if (event.keyCode === 13) {
|
|
event.preventDefault();
|
|
clean();
|
|
}
|
|
}
|
|
});
|
|
$("#cleaner-clean-btn").click(function() {
|
|
console.log("Clean button clicked");
|
|
clean();
|
|
});
|
|
|
|
initQuickSettings();
|
|
}
|
|
|
|
function initQuickSettings() {
|
|
const filterList = $("#filter-list");
|
|
filterList.empty(); // Clear any existing list items
|
|
|
|
config.rules.forEach(rule => {
|
|
const listItem = $(`
|
|
<li class="list-group-item">
|
|
<div class="form-check">
|
|
<input class="form-check-input" type="checkbox" value="" id="${rule.strToReplace}" ${rule.enabled ? 'checked' : ''}>
|
|
<label class="form-check-label" for="${rule.strToReplace}">
|
|
${rule.strToReplace}
|
|
</label>
|
|
</div>
|
|
</li>
|
|
`);
|
|
filterList.append(listItem);
|
|
});
|
|
|
|
$(".form-check-input").change(function() {
|
|
const rule = config.rules.find(r => r.strToReplace === $(this).attr("id"));
|
|
if (rule) {
|
|
rule.enabled = $(this).is(":checked");
|
|
//window.localStorage.setItem("config", JSON.stringify(config));
|
|
}
|
|
});
|
|
}
|
|
|
|
async function clean() {
|
|
console.log("Cleaning...");
|
|
|
|
let outputText = $("#input-textarea").val();
|
|
let totalMatches = 0;
|
|
|
|
config.rules.forEach(rule => {
|
|
if (rule.enabled) {
|
|
const searchValue = rule.ignoreCase ? new RegExp(rule.strToReplace, 'gi') : new RegExp(rule.strToReplace, 'g');
|
|
let matchCount = 0;
|
|
|
|
outputText = outputText.replace(searchValue, (match) => {
|
|
matchCount++;
|
|
return rule.replaceStr;
|
|
});
|
|
|
|
totalMatches += matchCount;
|
|
}
|
|
});
|
|
|
|
$("#output-textarea").val(outputText);
|
|
$("#output-container-div").removeClass("visually-hidden");
|
|
|
|
$("#replace-count").text(totalMatches);
|
|
|
|
if ($("#enable-auto-copy").prop("checked")) {
|
|
console.log("Copying result to clipboard...")
|
|
await Neutralino.clipboard.writeText(outputText);
|
|
}
|
|
}
|
|
|
|
})(); |