add javascript

This commit is contained in:
magh 2025-03-27 01:37:51 +09:00
parent 6ca036c577
commit a5f73c1b0c

View File

@ -161,7 +161,7 @@
<!-- Radio Buttons -->
<!-- Should change depending on category -->
<div class="radio-options">
<input type="radio" name="category" id="science" value="science" checked />
<input type="radio" name="category" id="science" value="science" checked/>
<label for="science">Science</label>
<input type="radio" name="category" id="philosophy" value="philosophy" />
@ -180,5 +180,37 @@
<a href="https://git.tsugutsugugo.com/explore/repos">Source</a> | <a href="https://docs.tsugutsugugo.com/">Docs</a>
</div>
<script>
// Wait until the DOM is fully loaded
document.addEventListener('DOMContentLoaded', function() {
const form = document.querySelector('.search-form');
form.addEventListener('submit', function(e) {
// Get which radio button is checked
const selectedValue = document.querySelector('input[name="category"]:checked').value;
// Change the form's action based on the selected category
switch (selectedValue) {
case 'science':
e.target.action = 'https://science.tsugutsugugo.com/yacysearch.html?query={}';
break;
case 'philosophy':
e.target.action = 'https://sophos.tsugutsugugo.com/yacysearch.html?query={}';
break;
case 'tech':
e.target.action = 'https://tech.tsugutsugugo.com/yacysearch.html?query={}';
break;
case 'discover':
e.target.action = 'https://web.tsugutsugugo.com/yacysearch.html?query={}';
break;
default:
// fallback to science
e.target.action = 'https://science.tsugutsugugo.com/yacysearch.html?query={}';
}
});
});
</script>
</body>
</html>