FPGA-Plus

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

安装此脚本?
作者推荐脚本

您可能也喜欢USTC 助手

安装此脚本
  1. // ==UserScript==
  2. // @name FPGA-Plus
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.4.5
  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. // @require https://gf.qytechs.cn/scripts/462234-message/code/Message.js?version=1192786
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17. let name = "FPGA-Plus";
  18. window.QMSG_GLOBALS = {
  19. DEFAULTS: {
  20. showClose:true,
  21. timeout: 2000
  22. }
  23. }
  24. let toast = (s, error=false) => {
  25. if (error) {
  26. Qmsg.error(`[${name}] ${s}`);
  27. console.error(`[${name}] ${s}`);
  28. } else {
  29. Qmsg.success(`[${name}] ${s}`);
  30. console.log(`[${name}] ${s}`);
  31. }
  32. };
  33. if (window.location.hostname == 'fpgaol.ustc.edu.cn') { // Main page
  34. let navbar = document.querySelector(".navbar-nav");
  35. if (!navbar) return;
  36. let last = navbar.querySelector("form");
  37. if (!last) return;
  38. // Auto navigate to acquired board
  39. let acquired = document.querySelector("table.table.table-striped > tbody > tr:nth-child(4) > td > a");
  40. if (acquired.attributes.href.value != "None") {
  41. acquired.click();
  42. }
  43. // Copy parts
  44. let parts = "xc7a100tcsg324-1";
  45. let hint = document.createElement("li");
  46. hint.classList.add("nav-item");
  47. navbar.insertBefore(hint, last);
  48. let link = document.createElement("a");
  49. link.classList.add("nav-link");
  50. link.text = parts;
  51. link.title = "Click to copy";
  52. link.href = "javascript:void(0);";
  53. link.addEventListener("click", (e) => {
  54. navigator.clipboard.writeText(parts);
  55. toast("Copied!");
  56. });
  57. hint.appendChild(link);
  58. return;
  59. } // Dev page
  60. // Visual improvements
  61. let rsp = document.getElementById("responsetext");
  62. let upload = document.getElementById("upload-button");
  63. upload.addEventListener("click", (e)=>{
  64. rsp.textContent = "Waiting...";
  65. });
  66. // Default upload
  67. let default_input = document.getElementById("bitstream");
  68. let customed = document.getElementById("file-select");
  69. default_input.style.borderStyle = "dashed";
  70. default_input.style.borderRadius = "0.5em";
  71. default_input.style.padding = "0.5em";
  72. default_input.style.background = "#a9a9a966";
  73. default_input.attributes.removeNamedItem("hidden");
  74. customed.parentNode.replaceChild(default_input, customed);
  75. // Remove unused
  76. document.querySelector("body > div:nth-child(2) > div > div > form > div.row > div:nth-child(2)").remove();
  77. // Led value
  78. // Pre-process
  79. let val = 0;
  80. let panel = document.querySelector(".col-5.colmodule");
  81. panel.insertAdjacentHTML('afterbegin', '<div class="container"><span id="info" style="padding: inherit;">Bin: 0b00000000; Hex: 0x00; Dec (unsigned): 0</span></div>');
  82. // Functions
  83. function checkbox_patch(checkbox) {
  84. // Check out https://github.com/PRO-2684/gadgets/blob/main/checkbox_patch/ if you're interested in this part
  85. const { get, set } = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'checked');
  86. Object.defineProperty(checkbox, 'checked', {
  87. get() {
  88. return get.call(this);
  89. },
  90. set(newVal) {
  91. let ret = set.call(this, newVal);
  92. this.dispatchEvent(new Event("change"));
  93. return ret;
  94. }
  95. });
  96. }
  97. function get_bit(n) {
  98. return (val >> n) & 1;
  99. }
  100. function set_bit(n, b) {
  101. if (b) {
  102. val |= (1 << n);
  103. } else {
  104. val &= ~(1 << n);
  105. }
  106. }
  107. function update() {
  108. let bin_str = '0b' + val.toString(2).padStart(8, '0');
  109. let hex_str = '0x' + val.toString(16).padStart(2, '0');
  110. let dec_str = val.toString();
  111. let res = `Bin: ${bin_str}; Hex: ${hex_str}; Dec (unsigned): ${dec_str}`;
  112. info.textContent = res;
  113. }
  114. // Setup listeners & init
  115. for (let i = 0; i <= 7; i++) {
  116. let led = document.getElementById(`led${i}`);
  117. set_bit(i, led.checked);
  118. checkbox_patch(led);
  119. led.addEventListener("change", (e) => {
  120. set_bit(i, led.checked);
  121. update();
  122. });
  123. }
  124. update();
  125. })();

QingJ © 2025

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