解释jpm"无用的表达"

时间:2015-12-27 13:49:28

标签: javascript typeerror jpm

所以我这里有一点问题。我试着跑#14; jpm test"对于我试图开发的附加组件。但每次我尝试运行它时,它只会显示

var tabs = require("sdk/tabs");
var data = require("sdk/self").data;
var prefs = require("sdk/simple-prefs").prefs;

tabs.on("ready", runScript);
//tabs.open("http://battlelog.battlefield.com/bf4");
var re = /battlelog\.battlefield\.com\/bf4/;

function runScript(tab) {
    if(re.test(tab.url)){
        console.log("Found battlelog tab.");
        var worker = tab.attach({
            contentScriptFile: data.url("bf4_checker.js")
        });
        worker.port.on("sendingUsername",bf4Username)
        worker.port.on("sendingUserid",bf4Userid)
    }else{
        console.log("Looking if bf4c tab");
        var worker = tab.attach({
            contentScriptFile: data.url("bf4c_checker.js")
        });
        //see https://developer.mozilla.org/en-US/Add-ons/SDK/Guides/Content_Scripts#Communicating_with_the_add-on for further reference
        worker.port.on("bf4cCheckCallback",bf4cCheckCallback)
    }
}
function bf4cCheckCallback(m){
    //{'bf4cPage' : false,'addownAllowed':false}
    console.log(((m.bf4cPage)? 'Is a bf4c page':'Another page') + ", " + ((m.addownAllowed)? 'bf4c addon allowed!':'bf4c addon not allowed!'))
}
function bf4Username(name){
    prefs.setUsername = name;
}
function bf4Userid(id){
    prefs.setUserid =  id;
    console.log(prefs)
}

我不知道在哪里搜索此错误。我发现的唯一的事情是this。所以这里是我使用的所有文件:

index.js(主要)

function searchUsername(){
    if(elements = document.getElementsByClassName("username")){
        for (var i = 0; i < elements.length; i++) {
            if(elements[i].href){
                return elements[i].innerHTML;
            }
        };      
    }
    return false;
}
function searchUserid(name){
    if(elements = document.getElementsByClassName("wfont")){
        re = new RegExp('/bf4/soldier/'+name+'/stats/(\\d+)/');
        for (var i = 0; i < elements.length; i++) {
            if(typeof (result = re.exec(elements[i].href)) == 'object'){
                return (parseInt(result[1]))

            }
        }       
    }
    return false;
}
if(username = searchUsername()){
    self.port.emit('sendingUsername',username);
    if(id = searchUserid(username)){
        self.port.emit('sendingUserid',id);
    }
}
function callback(mutations) {
    var re = /(highlight)/;
    mutations.forEach(function(mutationRecord) {
        var sepe = splittedClasses(mutationRecord.target.className)
        if(mutationRecord.attributeName == "class" && sepe.indexOf('highlight') > -1 && sepe.indexOf('popover-visible') == -1 && mutationRecord.target.className != mutationRecord.oldValue){
            console.log("Got new battlereport! went from\n\t"+ mutationRecord.oldValue +"\n\t"+ mutationRecord.target.className)
        }
    });
}
function splittedClasses(className){
    var classes = className.split(" ");
    for (var i = 0; i < classes.length; i++) {
        if(classes[i] == ""){
            classes.splice(i,1);
        }
    };
    return classes;
}
if(target = document.getElementById('battlereports-icon')){
    console.log("initialized listener !")
    var observer = new MutationObserver(callback);
        observer.observe(target,{ attributes : true, attributeOldValue: true, attributeFilter : ['class'] });   
}

function metaKeyUp (event) {
    var key = event.keyCode || event.which;
    if (key == 65) {
        if(target.className != "log tools-item reports  highlight"){
            console.log("highlighted the report button");
            target.className = "log tools-item reports  highlight";
        }

    }
}
document.body.addEventListener("keyup",metaKeyUp.bind(this))

bf4_checker.js

function isBF4CPage(){
    var header = document.getElementsByTagName("meta");
    for (var i = 0; i < header.length; i++) {
        var curr = header[i];
        if(curr.name == "x-bf4c-page"){
            return {'bf4cPage' : true,'addownAllowed': (curr.content == "true")? true : false};
        }
    }
    return {'bf4cPage' : false,'addownAllowed':false};
}
self.port.emit('bf4cCheckCallback',isBF4CPage())

和最后一个bf4c_checker.js

$("#step1Content").load("yourpage.html");

1 个答案:

答案 0 :(得分:-1)

好的我只是为了理解jpm test的实际目的而愚蠢,我建议阅读this articelthis one两者都向您展示如何实际使用此功能。所以我的问题不是我的代码只是因为它试图做一些我之前没有减速的事情。