preLoadFile.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. let dataTemp = {}
  2. window.electronAPI.readFile({filename: 'data.json', encoding: "utf8"}).then(result => {
  3. if (result.success) {
  4. console.log(result.content);
  5. dataTemp = JSON.parse(result.content)
  6. } else {
  7. console.error('文件读取失败:', result.error);
  8. }
  9. });
  10. window.onInterceptedData = function (data) {
  11. console.log(data)
  12. if (data.url.includes('%E6%8F%90%E4%BA%A4%E7%AD%94%E6%A1%88')) {
  13. const pageID = data.requestBody['试题Id']
  14. const resb = JSON.parse(data.responseBody)
  15. console.log(resb['正确选项Id列表'], pageID)
  16. dataTemp[pageID] = resb['正确选项Id列表']
  17. const fileData = {
  18. filename: 'data.json',
  19. content: JSON.stringify(dataTemp)
  20. };
  21. // 调用保存方法
  22. window.electronAPI.saveFile(fileData).then(result => {
  23. if (result.success) {
  24. console.log('文件保存成功:', result.path);
  25. } else {
  26. console.error('文件保存失败:', result.error);
  27. }
  28. });
  29. }
  30. if (data.url.includes('%E5%BC%80%E5%A7%8B%E8%87%AA%E6%B5%8B')) {
  31. const resb = JSON.parse(data.responseBody)
  32. const dqst = resb['当前题目']['Id']
  33. if (dataTemp[dqst]) {
  34. setTimeout(() => {
  35. if (window.optionsArea) {
  36. dataTemp[dqst].forEach(creatID => {
  37. window.optionsArea.querySelector(`[data-option-id="${creatID}"]`).style.backgroundColor = 'aliceblue'
  38. });
  39. }
  40. }, 1000);
  41. }
  42. }
  43. if (data.url.includes('%E5%88%87%E6%8D%A2%E9%A2%98%E7%9B%AE')) {
  44. const resb = JSON.parse(data.responseBody)
  45. const dqst = resb['当前试题']['Id']
  46. if (dataTemp[dqst]) {
  47. setTimeout(() => {
  48. if (window.optionsArea) {
  49. dataTemp[dqst].forEach(creatID => {
  50. window.optionsArea.querySelector(`[data-option-id="${creatID}"]`).style.backgroundColor = 'aliceblue'
  51. });
  52. }
  53. }, 1000);
  54. }
  55. }
  56. };