Refactor:Cleanup code 2

This commit is contained in:
FoxRefire 2024-06-25 10:43:09 +09:00
parent 349a7a7ac9
commit e0d6e3079e
3 changed files with 29 additions and 41 deletions

View File

@ -15,10 +15,9 @@ function convertHeaders(obj){
}
window.blockRules = await fetch("blockRules.conf").then((r)=>r.text());
blockRules = blockRules.replace(/\n^\s*$|\s*\/\/.*|\s*$/gm, "");
blockRules = blockRules.split("\n");
window.blockRules = window.blockRules.replace(/\n^\s*$|\s*\/\/.*|\s*$/gm, "").split("\n");
function testBlock(url) {
return window.isBlock && blockRules.map(e => url.includes(e)).some(e=>e);
return window.isBlock && window.blockRules.some(e => url.includes(e));
}
//Get URL and headers from POST requests

View File

@ -5,7 +5,7 @@
<link rel="stylesheet" href="style.css">
<script src="pyodide/pyodide.js"></script>
</head>
<body id="bodyid">
<body>
<div id="toggleHistory">
<button id="historyButton">Show History</button><br><br>
</div>

View File

@ -3,7 +3,6 @@ function selectPssh(){
document.getElementById('selectPssh').style.display='grid';
document.getElementById('psshList').style.display='grid';
document.getElementById('toggleHistory').style.display='none';
document.getElementById('bodyid').style.gridTemplateRows='auto 1fr auto';
}
function selectRequest(){
@ -11,50 +10,40 @@ function selectRequest(){
document.getElementById('selectRequest').style.display='grid';
document.getElementById('requestList').style.display='grid';
document.getElementById('toggleHistory').style.display='none';
document.getElementById('bodyid').style.gridTemplateRows='auto 1fr auto';
}
document.getElementById('psshButton').addEventListener("click", selectPssh);
document.getElementById('licenseButton').addEventListener("click", selectRequest);
var userInputs={};
function drawList(arr,_searchBox,_list,_userInputs){
const elements = arr;
const searchBox = document.getElementById(_searchBox);
const list = document.getElementById(_list);
elements.forEach((element, index) => {
const li = document.createElement('li');
li.textContent = element;
li.addEventListener('click', () => {
userInputs[_userInputs]=index;
document.getElementById(_userInputs).value=element;
document.getElementById(_userInputs+'Index').value=index;
document.getElementById('selectPssh').style.display='none';
document.getElementById('selectRequest').style.display='none';
document.getElementById('home').style.display='grid';
document.getElementById('toggleHistory').style.display='grid';
});
list.appendChild(li);
function writeListElement(arrElements, list, outputVar, search) {
list.innerHTML = '';
arrElements.forEach((element, index) => {
if (!search || element.includes(searchValue)) {
const li = document.createElement('li');
li.textContent = element;
li.addEventListener('click', () => {
userInputs[outputVar]=index;
document.getElementById(outputVar).value=element;
document.getElementById(outputVar+'Index').value=index;
document.getElementById('selectPssh').style.display='none';
document.getElementById('selectRequest').style.display='none';
document.getElementById('home').style.display='grid';
document.getElementById('toggleHistory').style.display='grid';
});
list.appendChild(li);
}
});
}
var userInputs={};
function drawList(arrElements,searchBoxElmId,listElmId,outputVar) {
const searchBox = document.getElementById(searchBoxElmId);
const list = document.getElementById(listElmId);
writeListElement(arrElements, list, outputVar, null)
searchBox.addEventListener('input', (event) => {
const searchValue = event.target.value.toLowerCase();
list.innerHTML = '';
elements.forEach((element, index) => {
if (element.toLowerCase().includes(searchValue)) {
const li = document.createElement('li');
li.textContent = element;
li.addEventListener('click', () => {
userInputs[_userInputs]=index;
document.getElementById(_userInputs).value=element;
document.getElementById(_userInputs+'Index').value=index;
document.getElementById('selectPssh').style.display='none';
document.getElementById('selectRequest').style.display='none';
document.getElementById('home').style.display='grid';
});
list.appendChild(li);
}
});
writeListElement(arrElements, list, outputVar, searchValue)
});
}