|
911 | 911 | <select class="model-select" title="Select AI Model"> |
912 | 912 | <!-- existing options remain the same --> |
913 | 913 | </select> |
914 | | - <div id="visitor-counter" class="visitor-counter"> |
915 | | - <span class="visitor-icon">👥</span> |
916 | | - <span class="visitor-count">0</span> |
917 | | - </div> |
| 914 | + <div class="visitor-counter">Visitors: <span id="visitor-count">Loading...</span></div> |
918 | 915 | </div> |
919 | 916 | </div> |
920 | 917 | </div> |
|
931 | 928 |
|
932 | 929 |
|
933 | 930 | <script src="js/nav-loader.js"></script> |
934 | | - <script src="visitorTracker.js"></script> |
| 931 | + <script> |
| 932 | + // Visitor Tracker Logic with File System Access API |
| 933 | +async function visitorTracker() { |
| 934 | + const fileName = "visitorCount.txt"; |
| 935 | + const visitorCountElement = document.getElementById("visitor-count"); |
| 936 | + let visitorCount = 0; |
935 | 937 |
|
| 938 | + try { |
| 939 | + // Request permission to access a file |
| 940 | + const fileHandle = await window.showSaveFilePicker({ |
| 941 | + suggestedName: fileName, |
| 942 | + types: [ |
| 943 | + { |
| 944 | + description: "Text Files", |
| 945 | + accept: { |
| 946 | + "text/plain": [".txt"], |
| 947 | + }, |
| 948 | + }, |
| 949 | + ], |
| 950 | + }); |
| 951 | + |
| 952 | + // Try to read the file if it exists |
| 953 | + const file = await fileHandle.getFile(); |
| 954 | + const text = await file.text(); |
| 955 | + visitorCount = parseInt(text, 10) || 0; |
| 956 | + |
| 957 | + // Increment visitor count |
| 958 | + visitorCount += 1; |
| 959 | + |
| 960 | + // Save the updated count back to the file |
| 961 | + const writable = await fileHandle.createWritable(); |
| 962 | + await writable.write(visitorCount.toString()); |
| 963 | + await writable.close(); |
| 964 | + |
| 965 | + // Update the visitor count display |
| 966 | + visitorCountElement.textContent = visitorCount; |
| 967 | + } catch (error) { |
| 968 | + console.error("Error handling visitor count:", error); |
| 969 | + visitorCountElement.textContent = "Error!"; |
| 970 | + } |
| 971 | +} |
| 972 | + |
| 973 | +// Initialize the visitor tracker on page load |
| 974 | +document.addEventListener("DOMContentLoaded", () => { |
| 975 | + visitorTracker(); |
| 976 | +}); |
936 | 977 |
|
937 | | - <script> |
938 | 978 | const DEFAULT_INSTRUCTION = "All code must be wrapped in [CODE]...[/CODE] tags." + |
939 | 979 | "When using images, show them using format: https://image.pollinations.ai/prompt/your%20image-prompt-with-visual-style%20here?width=512&height=512&nologo=true&private=true&seed={random}&enhance=false&model=Unity plus your response.\n\n" + |
940 | 980 | "Code format: [CODE]code here[/CODE] with your response.\n\n" + |
|
0 commit comments