AWBW Replay archive

Reload an archived replay in a single click, from 2023 onwards.

当前为 2023-12-05 提交的版本,查看 最新版本

// ==UserScript==
// @name         AWBW Replay archive
// @namespace    https://awbw.amarriner.com/
// @version      1.00
// @description  Reload an archived replay in a single click, from 2023 onwards.
// @author       Truniht
// @match        https://awbw.amarriner.com/game.php?games_id=*
// @icon         https://awbw.amarriner.com/favicon.ico
// @license MIT
// @connect awbw.mooo.com
// @grant GM.xmlHttpRequest
// ==/UserScript==

var downloadButton = document.createElement('div');
var replayLoaded = false;

async function reloadReplay() {
    if (replayLoaded) return; //Don't let people mash the button
    replayLoaded = true;
    var dButton = downloadButton.firstChild.firstChild.lastChild;
    dButton.innerText = 'Please wait...';

    var gameID = window.location.href.match(/_id=([0-9]+)/)[1];
    var requestLink = 'http://awbw.mooo.com/reloadReplay.php?gameID='+gameID;

    const r = await GM.xmlHttpRequest({ url: requestLink }).catch(e => dButton.innerText = 'Error, try later');
    switch(r.responseText) {
        case 'success': dButton.innerText = 'Done, reloading'; location.reload(); break;
        case 'error': dButton.innerText = 'Error, try later'; break;
        case 'noReplay': dButton.innerText = 'Replay not in archive'; break;
        default: dButton.innerText = 'Unknown error';
    }
}

//Check if game is no longer archived
if (document.querySelector('.replay-open').style.display === 'none') {
    downloadButton.style = 'margin-left: 4px; width: auto !important; display: flex;';
    downloadButton.className = 'replay-download game-tools-btn';
    downloadButton.innerHTML = '<span class="game-tools-bg small_text" style="padding: 0 8px;">'+
        '<a class="center" style="width: 100%; height: 100%;">'+
           '<img src="terrain/divehide.gif" alt="Download replay" style="margin-right: 4px;">'+
           '<span>Reload replay</span>'+
        '</a>'+
    '</span>';
    downloadButton.addEventListener('click', reloadReplay);

    document.getElementById('game-menu-controls').lastElementChild.appendChild(downloadButton);
}

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址