AWBW game notes

Add a simple note function to matches

目前為 2022-08-25 提交的版本,檢視 最新版本

// ==UserScript==
// @name         AWBW game notes
// @namespace    https://awbw.amarriner.com/
// @version      1.01
// @description  Add a simple note function to matches
// @author       Truniht
// @match        https://awbw.amarriner.com/*?games_id=*
// @match        https://awbw.amarriner.com/*?replays_id=*
// @icon         https://awbw.amarriner.com/favicon.ico
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_addValueChangeListener
// @license MIT
// ==/UserScript==

var gameID = window.location.href.match(/_id=([0-9]+)/)[1];

var noteValue = GM_getValue('AWBWNote' + gameID) || '';

var ele = document.createElement('textarea');
ele.style.width = '100%';
ele.style.background = 'rgb(250, 250, 221)';
ele.style.color = '#000000';

function resizeEle() {
    if (ele.clientHeight + 10 < ele.scrollHeight) ele.style.height = ele.scrollHeight + 'px';
}

if (noteValue) ele.value = noteValue;

var saveTimeout = 0;
function saveText() {
    GM_setValue('AWBWNote' + gameID, ele.value);
}

ele.oninput = function(e) {
    clearTimeout(saveTimeout);
    saveTimeout = setTimeout(saveText, 500);
    resizeEle();
}

GM_addValueChangeListener('AWBWNote' + gameID, function(name, old_value, new_value, remote) {
    if (remote) ele.value = new_value;
});

//Stop default keybindings
function preventK(e) {
    e.stopPropagation();
}
ele.addEventListener('keydown', preventK);
ele.addEventListener('keyup', preventK);
ele.addEventListener('keypress', preventK);

function loadNotes() {
    var mainEle = (document.querySelector('.game-player-info') || document.querySelector('.awbwenhancements-sidebar-entry'));
    if (!mainEle) return false;
    mainEle.appendChild(ele);
    ele.parentNode.style.height = '';
    resizeEle();

    return true;
}

if (!loadNotes()) window.addEventListener('load', loadNotes);

QingJ © 2025

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