有一个JavaScript文件附加到页面的源代码,我想使用TamperMonkey编辑和覆盖它的一个函数,所以我可以改变函数的功能,这可能吗? 这是功能:
function handleNext () {
switch(curIndex){
case 0:
startLoading();
$.getJSON(API_URL + getSubdomain() + "/names", function(res) {
if(res.A == true) {
moveToSection($("#section-name-links"), $("#section-user-prefrences"));
} else {
finishLoading();
displayError("Incorrect");
}
}).fail(function() {
finishLoading();
displayError("An error occured");
});
break;
case 1:
startLoading();
var success = true;
if($("#prefrences input[name=name]").val() == ""){
displayError("Please enter your name");
success = false;
}
if($("#section-user-prefrences input[surname=surname]").size() > 0 &&
$("#section-user-prefrences input[surname=surname]:checked").size() == 0){
displayError("Please enter your last name");
success = false;
}
if(!success){
finishLoading();
return;
}
var rewardid = $("#section-user-prefrences input[name=reward]:checked").val();
$.post(API_URL + getSubdomain() + "/names", {
nameid: namesid || -1,
username: $("#section-user-prefrences input[name=name]").val()
}, function(res) {
moveToSection($("#section-user-prefrences"), $("#section-thank-you"));
$("#continue").hide();
}).fail(function() {
finishLoading();
displayError("An error occured");
});
break;
}
}
我的目标是将功能改为:
function handleNext () {
switch(curIndex){
case 0:
startLoading();
moveToSection($("#section-name-links"), $("#section-user-prefrences"));
}).fail(function() {
finishLoading();
displayError("An error occured");
});
break;
case 1:
startLoading();
var success = true;
if(!success){
finishLoading();
return;
}
break;
}
}