简体   繁体   English

覆盖托管的Javascript函数

[英]Overriding Hosted Javascript Function

I'm relatively new to javascript. 我对javascript比较陌生。

I'm currently trying to figure out how to override a javascript function from a hosted JS. 我目前正在尝试弄清如何从托管JS覆盖javascript函数。

Background: 背景:

We won't be able to accept Amex card payment (Bank Issue). 我们将无法接受美国运通卡付款(银行发行)。 However, our embedded donation form still detects Amex cards when the card number is inserted. 但是,插入卡号后,我们的嵌入式捐赠表格仍会检测到Amex卡。

Using Chrome, found this function, that I'm guessing is used to auto-detect card types. 使用Chrome,我发现此功能可用于自动检测卡类型。 / /

 function a(n) { var m = /^4/, i = /(^5[1-5])|^(222[1-8][0-9]{2}|2229[0-8][0-9]|22299[0-9]|22[3-9][0-9]{3}|2[3-6][0-9]{4}|27[01][0-9]{3}|2720[0-8][0-9]|27209[0-9])/, o = /^3[47]/, l = /^6(?:011|5|4[4-9]|22(?:1(?:2[6-9]|[3-9])|[2-8]|9(?:[01]|2[0-5])))/, h = /^(?:5[0678]|6304|6390|67)/, j = /^3(?:0[0-5]|[68][0-9])[0-9]/, k = /^(4026|417500|4405|4508|4844|4913|4917)/; if (k.test(n)) { return "electron" } else { if (m.test(n)) { return "visa" } else { if (i.test(n)) { return "mastercard" } else { if (o.test(n)) { return "amex" } else { if (l.test(n)) { return "discover" } else { if (h.test(n)) { return "maestro" } else { if (j.test(n)) { return "diners" } else { return "unknown" } } } } } } } } 

Will I be able to override the "o=/^3[47]/" to something else or remove it completely so Amex cards can't be detected, then insert in inside HTML? 我是否可以将“ o = / ^ 3 [47] /”改写为其他名称或将其完全删除,从而无法检测到Amex卡,然后插入HTML内?

Hello maybe a solution is to make your own if statement if amex is returned, so that you will set amex to unknown to. 您好,也许一种解决方案是在返回amex时创建自己的if语句,以便将amex设置为unknown。

var card = function a(n);
if(a === 'unknown' || a === 'amex'){
DoStuff();
}else{
DoRecognizedstuff();
}

This will help you solve the problem. 这将帮助您解决问题。 Is this not what you want? 这不是你想要的吗? You can also rewrite the function to this: 您也可以将函数重写为:

 function a(n) { var m = /^4/, i = /(^5[1-5])|^(222[1-8][0-9]{2}|2229[0-8][0-9]|22299[0-9]|22[3-9][0-9]{3}|2[3-6][0-9]{4}|27[01][0-9]{3}|2720[0-8][0-9]|27209[0-9])/, l = /^6(?:011|5|4[4-9]|22(?:1(?:2[6-9]|[3-9])|[2-8]|9(?:[01]|2[0-5])))/, h = /^(?:5[0678]|6304|6390|67)/, j = /^3(?:0[0-5]|[68][0-9])[0-9]/, k = /^(4026|417500|4405|4508|4844|4913|4917)/; if (k.test(n)) { return "electron" } else { if (m.test(n)) { return "visa" } else { if (i.test(n)) { return "mastercard" } else { if (l.test(n)) { return "discover" } else { if (h.test(n)) { return "maestro" } else { if (j.test(n)) { return "diners" } else { return "unknown" } } } } } } } 

This will only be possible if you call this function yourself. 仅当您自己调用此函数时,才有可能。 If it is called by a callback or something from the hosted JS it will not work. 如果通过回调或托管的JS调用它,它将无法正常工作。 If this is a standalone script, you can just host the JS as your own. 如果这是一个独立脚本,则可以将JS托管为自己的脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM