2024-11-02 11:16:25 +13:00
async function checkInstanceUpdateStatus ( ) {
try {
2024-11-03 10:08:26 +13:00
const response = await fetch ( '/commits.json' ) ;
2024-11-02 11:16:25 +13:00
const text = await response . text ( ) ;
2024-11-03 10:08:26 +13:00
const entries = JSON . parse ( text ) ;
2024-11-02 11:16:25 +13:00
const localCommit = document . getElementById ( 'git_commit' ) . dataset . value ;
let statusMessage = '' ;
if ( entries . length > 0 ) {
const commitHashes = Array . from ( entries ) . map ( entry => {
2024-11-03 10:08:26 +13:00
return entry . sha
2024-11-02 11:16:25 +13:00
} ) ;
const commitIndex = commitHashes . indexOf ( localCommit ) ;
if ( commitIndex === 0 ) {
statusMessage = '✅ Instance is up to date.' ;
} else if ( commitIndex > 0 ) {
statusMessage = ` ⚠️ This instance is not up to date and is ${ commitIndex } commits old. Test and confirm on an up-to-date instance before reporting. ` ;
2024-11-15 05:49:47 +13:00
document . getElementById ( 'error-318' ) . remove ( ) ;
2024-11-02 11:16:25 +13:00
} else {
statusMessage = ` ⚠️ This instance is not up to date and is at least ${ commitHashes . length } commits old. Test and confirm on an up-to-date instance before reporting. ` ;
2024-11-15 05:49:47 +13:00
document . getElementById ( 'error-318' ) . remove ( ) ;
2024-11-02 11:16:25 +13:00
}
} else {
statusMessage = '⚠️ Unable to fetch commit information.' ;
}
document . getElementById ( 'update-status' ) . innerText = statusMessage ;
} catch ( error ) {
console . error ( 'Error fetching commits:' , error ) ;
document . getElementById ( 'update-status' ) . innerText = '⚠️ Error checking update status.' ;
}
}
2024-11-20 10:30:37 +13:00
async function checkOtherInstances ( ) {
try {
const response = await fetch ( '/instances.json' ) ;
const data = await response . json ( ) ;
const randomInstance = data . instances [ Math . floor ( Math . random ( ) * data . instances . length ) ] ;
const instanceUrl = randomInstance . url ;
// Set the href of the <a> tag to the instance URL with path included
document . getElementById ( 'random-instance' ) . href = instanceUrl + window . location . pathname ;
2024-11-21 00:58:15 +13:00
//document.getElementById('random-instance').innerText = "Visit Random Instance";
2024-11-20 10:30:37 +13:00
} catch ( error ) {
console . error ( 'Error fetching instances:' , error ) ;
document . getElementById ( 'update-status' ) . innerText = '⚠️ Error checking update status.' ;
}
}
// Set the target URL when the page loads
window . addEventListener ( 'load' , checkOtherInstances ) ;
2024-11-02 11:16:25 +13:00
checkInstanceUpdateStatus ( ) ;