FPGA-Plus

More functions for fpgaol (https://fpgaol.ustc.edu.cn/)

Stan na 07-05-2023. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         FPGA-Plus
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  More functions for fpgaol (https://fpgaol.ustc.edu.cn/)
// @author       PRO
// @license      gpl-3.0
// @match        https://fpgaol.ustc.edu.cn/*
// @match        http://202.38.79.134:*/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    if (window.location.hostname == 'fpgaol.ustc.edu.cn') {
        let navbar = document.querySelector(".navbar-nav");
        if (!navbar) return;
        let last = navbar.querySelector("form");
        if (!last) return;
        let hint = document.createElement("li");
        hint.classList.add("nav-item");
        hint.innerHTML = '<a class="nav-link" title="Click to copy" href="javascript:navigator.clipboard.writeText(\'xc7a100tcsg324-1\');">xc7a100tcsg324-1</a>';
        navbar.insertBefore(hint, last);
        return;
    }
    // Pre-process
    let val = 0;
    let panel = document.querySelector(".col-5.colmodule");
    panel.insertAdjacentHTML('afterbegin', '<div class="container"><span id="info" style="padding: inherit;">Bin: 0b00000000; Hex: 0x00; Dec (unsigned): 0</span></div>');
    // Functions
    function checkbox_patch(checkbox) {
        // Check out https://github.com/PRO-2684/gadgets/blob/main/checkbox_patch/ if you're interested in this part
        const { get, set } = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'checked');
        Object.defineProperty(checkbox, 'checked', {
            get() {
                return get.call(this);
            },
            set(newVal) {
                let ret = set.call(this, newVal);
                this.dispatchEvent(new Event("change"));
                return ret;
            }
        });
    }
    function get_bit(n) {
        return (val >> n) & 1;
    }
    function set_bit(n, b) {
        if (b) {
          val |= (1 << n);
        } else {
          val &= ~(1 << n);
        }
    }
    function update() {
        let bin_str = '0b' + val.toString(2).padStart(8, '0');
        let hex_str = '0x' + val.toString(16).padStart(2, '0');
        let dec_str = val.toString();
        let res = `Bin: ${bin_str}; Hex: ${hex_str}; Dec (unsigned): ${dec_str}`;
        info.textContent = res;
    }
    // Setup listeners & init
    for (let i = 0; i <= 7; i++) {
        let led = document.getElementById(`led${i}`);
        set_bit(i, led.checked);
        checkbox_patch(led);
        led.addEventListener("change", (e) => {
            set_bit(i, led.checked);
            update();
        });
    }
    update();
})();