使用chrome控制台在moodle站点注入js代码时出错

时间:2017-06-15 01:13:16

标签: javascript jquery google-chrome-devtools moodle

以下代码适用于除http://school.demo.moodle.net/

以外的所有网站
function appendScript(pathToScript) {
var head = document.getElementsByTagName("head")[0];
var js = document.createElement("script");
js.type = "text/javascript";
js.src = pathToScript;

head.appendChild(js);
}

//elasticlunr library

appendScript("http://elasticlunr.com/elasticlunr.js");

 var index = elasticlunr(function () {
this.addField('title');
this.addField('body');
this.setRef('id');
});

var doc1 = {
"id": 1,
"title": "Oracle released its latest database Oracle 12g",
"body": "Yestaday Oracle has released its new database Oracle 12g, this would make more money for this company and lead to a nice profit report of annual year."
}

var doc2 = {
"id": 2,
"title": "Oracle released its profit report of 2015",
"body": "As expected, Oracle released its profit report of 2015, during the good sales of database and hardware, Oracle's profit of 2015 reached 12.5 Billion."
}

index.addDoc(doc1);
index.addDoc(doc2);

index.search("Oracle database");

我正在使用Chrome控制台注入代码,它适用于除moodle之外的所有网站。 任何人都可以向我解释为什么它会抛出这个错误:

Uncaught ReferenceError: elasticlunr is not defined
at <anonymous>:37:13

0 个答案:

没有答案