我目前正在为我的大学开发一个镀铬扩展程序,我遇到了一个问题,即出口为Excel'我在manifest.json和timetable.js中添加jquery代码后没有显示(请参阅下面的更多信息)
这是我的代码:
的manifest.json
{
"name": "VIT Academics Enhancement Suite",
"version": "0.1",
"author": "Rahul Kapoor",
"description": "Extension to help you improve your experience on VIT Academics",
"permissions": ["*://academics.vit.ac.in/*"],
"content_scripts": [
{
"matches": ["*://academics.vit.ac.in/parent/parent_login.asp","*://academics.vit.ac.in/student/stud_login.asp","*://academics.vit.ac.in/parent/","*://academics.vit.ac.in/student/","*://27.251.102.132/parent/parent_login.asp","*://27.251.102.132/student/stud_login.asp","*://27.251.102.132/parent/","*://27.251.102.132/student/"],
"js": ["captcha.js"]
},
{
"matches": ["*://academics.vit.ac.in/student/timetable_ws.asp"],
"all_frames": true,
"js": ["timetable.js"],
"js": ["jquery.js"]
},
{
"matches": ["*://academics.vit.ac.in/*/attn_report.asp*","*://academics.vit.ac.in/student/attn_report_details.asp","*://27.251.102.132/*/attn_report.asp*"],
"all_frames": true,
"js": ["attendance.js"],
"css": ["home.css"]
}
],
"manifest_version": 2
}
Timetable.js
var textbox = document.getElementsByName('regular')[0];
console.log(textbox);
var para = document.createElement("input");
var t = document.createTextNode("Show Password");
para.setAttribute("type", "button");
para.setAttribute("id", "btnExport");
para.setAttribute("value","Export Table data into Excel");
textbox.parentElement.appendChild(para);
$("#btnExport").click(function (e) {
window.open('data:application/vnd.ms-excel,' + $('table:nth-child(1)').html());
e.preventDefault();
});
表HTML代码没有id或类,所以我使用nth-child定位它,但是一旦我在manifest中添加jquery.js作为CDN库代码,然后按钮' Export as Excel'消失。
我做得对,还是我需要做的其他事情,请帮助。
答案 0 :(得分:0)
您的问题与清单中指定多个脚本依赖项的方式有关:
"js": ["timetable.js"],
"js": ["jquery.js"]
在JSON中,后一个条目只会覆盖前者,所以现在你不再引用timetable.js
“js”键的值已经是一个数组(由[]表示),所以你只需要将依赖项添加到该数组中:
"js": ["timetable.js", "jquery.js"]
我不确定脚本的注入顺序,您可能需要切换它们。