FPGA-Plus

为 [FPGA Online](https://fpgaol.ustc.edu.cn/) 提供的更多功能

目前为 2023-05-08 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name FPGA-Plus
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.4
  5. // @description 为 [FPGA Online](https://fpgaol.ustc.edu.cn/) 提供的更多功能
  6. // @author PRO
  7. // @license gpl-3.0
  8. // @match *://fpgaol.ustc.edu.cn/*
  9. // @match http://202.38.79.134:*/*
  10. // @grant none
  11. // @icon https://fpgaol.ustc.edu.cn/favicon.ico
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16. if (window.location.hostname == 'fpgaol.ustc.edu.cn') { // Main page
  17. let navbar = document.querySelector(".navbar-nav");
  18. if (!navbar) return;
  19. let last = navbar.querySelector("form");
  20. if (!last) return;
  21. let hint = document.createElement("li");
  22. hint.classList.add("nav-item");
  23. hint.innerHTML = '<a class="nav-link" title="Click to copy" href="javascript:navigator.clipboard.writeText(\'xc7a100tcsg324-1\');">xc7a100tcsg324-1</a>';
  24. navbar.insertBefore(hint, last);
  25. return;
  26. } // Dev page
  27. // Visual improvements
  28. let rsp = document.getElementById("responsetext");
  29. let upload = document.getElementById("upload-button");
  30. upload.addEventListener("click", (e)=>{
  31. rsp.textContent = "Waiting...";
  32. });
  33. // Default upload
  34. let default_input = document.getElementById("bitstream");
  35. let customed = document.getElementById("file-select");
  36. default_input.attributes.removeNamedItem("hidden");
  37. customed.parentNode.replaceChild(default_input, customed);
  38. // Led value
  39. // Pre-process
  40. let val = 0;
  41. let panel = document.querySelector(".col-5.colmodule");
  42. panel.insertAdjacentHTML('afterbegin', '<div class="container"><span id="info" style="padding: inherit;">Bin: 0b00000000; Hex: 0x00; Dec (unsigned): 0</span></div>');
  43. // Functions
  44. function checkbox_patch(checkbox) {
  45. // Check out https://github.com/PRO-2684/gadgets/blob/main/checkbox_patch/ if you're interested in this part
  46. const { get, set } = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'checked');
  47. Object.defineProperty(checkbox, 'checked', {
  48. get() {
  49. return get.call(this);
  50. },
  51. set(newVal) {
  52. let ret = set.call(this, newVal);
  53. this.dispatchEvent(new Event("change"));
  54. return ret;
  55. }
  56. });
  57. }
  58. function get_bit(n) {
  59. return (val >> n) & 1;
  60. }
  61. function set_bit(n, b) {
  62. if (b) {
  63. val |= (1 << n);
  64. } else {
  65. val &= ~(1 << n);
  66. }
  67. }
  68. function update() {
  69. let bin_str = '0b' + val.toString(2).padStart(8, '0');
  70. let hex_str = '0x' + val.toString(16).padStart(2, '0');
  71. let dec_str = val.toString();
  72. let res = `Bin: ${bin_str}; Hex: ${hex_str}; Dec (unsigned): ${dec_str}`;
  73. info.textContent = res;
  74. }
  75. // Setup listeners & init
  76. for (let i = 0; i <= 7; i++) {
  77. let led = document.getElementById(`led${i}`);
  78. set_bit(i, led.checked);
  79. checkbox_patch(led);
  80. led.addEventListener("change", (e) => {
  81. set_bit(i, led.checked);
  82. update();
  83. });
  84. }
  85. update();
  86. })();