0

I am trying to make a Chrome extension that changes the webpage's javascript function. I want my chrome extension to change only some parts of the function because the other parts of it change by user, access time or webpage access method. The webpage function looks like this:

function opSubmit(save_type){               
            
            $("input[name=save_type]").val(save_type);
            
            var confirm_msg = "임시저장 하시겠습니까?";
            var complete_msg = "임시저장 완료하였습니다.";
            
            if(save_type == "S"){
                confirm_msg = "제출 하시겠습니까?";
                complete_msg = "제출 완료하였습니다.";                   
            }
            
            if(isEmpty($("#ssp_seq").val())){
                alert("실습 분과를 선택해주세요");
                return;
            }           
            
            if(!confirm(confirm_msg)){
                return;
            }                                   
            
            if(isEmpty($("#pfList").val())){
                alert("담당교수를 선택해주세요");
                return;
            }
            
            if(!isValidDate($("#date").val())){
                alert("날짜를 확인해주세요");
                $("#date").focus();
                return;
            }
            
            if(!isValidTime($("#start_hour").val(),$("#start_minute").val())){
                alert("시작 시간을 확인해주세요.");
                $("#start_hour").focus();
                return;
            }
            
            if(!isValidTime($("#end_hour").val(),$("#end_minute").val())){
                alert("종료 시간을 확인해주세요.");
                $("#end_hour").focus();
                return;
            }
                    
            if($("input[name=patient_type]:checked").length == 0){
                alert("환자 유형을 선택해주세요");
                return;
            }

            if(isEmpty($("#patient_name").val())){
                alert("환자이름을 입력해주세요");
                $("#patient_name").focus();
                return;
            }

            if(isEmpty($("#age").val())){
                alert("환자 나이를 입력해주세요");
                $("#age").focus();
                return;
            }

            if(isEmpty($("#gender").val())){
                alert("환자 성별을 선택해주세요");
                return;
            }
            
            if($("#keywordListAdd p").length == 0){
                alert("실습항목을 하나이상 선택해주세요");
                return;
            }
            
            var practiceInfo = new Object();
            practiceInfo.date = $("#date").val();
            practiceInfo.start_time = $("#start_hour").val() +":"+$("#start_minute").val();
            practiceInfo.end_time = $("#end_hour").val() +":"+$("#end_minute").val();
                            
            var patientInfo = new Object();
            patientInfo.patient_type = $("input[name=patient_type]:checked").val();
            patientInfo.etc_text = $("#etc_text").val();
            patientInfo.patient_name = $("#patient_name").val().substring(0,1)+"**";
            patientInfo.age = $("#age").val();
            patientInfo.gender = $("#gender").val();
            
            var patient_num = $("#patient_num").val();
            var patient_num_change = patient_num.substring(0,3);
            
            for(var i=0; i<patient_num.length-3; i++){                  
                patient_num_change += "*";                  
            }
            
            patientInfo.patient_num = patient_num_change;
            
            var practice = new Object();
            
            var practice = new Object();
            practice.info = practiceInfo;
            practice.patientInfo = patientInfo;
            practice.content = $("#froala_editor").froalaEditor('html.get');

            var jsonInfo = JSON.stringify(practice);
            
            $("input[name=ppr_content]").val(jsonInfo);
            
            $("#opForm").ajaxForm({
                type: "POST",
                url: "/ajax/st/clinical-training/outpatient/site/modify",
                dataType: "json",
                success: function(data, status){
                    if (data.status == "200") {
                        alert(complete_msg);
                        post_to_url("/st/clinical-training/inpatient/pomr/view",{"ppr_seq":data.ppr_seq, "op_seq" : "725187"});                 
                    }
                    else if(data.status == "505"){
                        alert(data.msg);
                    }
                    else{
                        alert("저장 실패");
                    }                     
                },
                error: function(xhr, textStatus) {
                    document.write(xhr.responseText); 
                    $.unblockUI();                      
                },beforeSend:function() {
                    $.blockUI();                        
                },complete:function() {
                    $.unblockUI();                      
                }                       
            });     
            $("#opForm").submit();
        }

I only want to change this part while leaving other parts to website's default:

if (data.status == "200") {
                    alert(complete_msg);
                    post_to_url("/st/clinical-training/inpatient/pomr/view",{"ppr_seq":data.ppr_seq, "op_seq" : "725187"});                 
                }

I know how to completely overwrite webpage function, but I don't know whether it's possible to change only some parts of it and leave everything else to default. Is it possible? How can I achieve it? Thanks!

  • You can add an [ajax hook](https://api.jquery.com/category/ajax/global-ajax-event-handlers/) to jQuery in [page context](/a/9517879). – wOxxOm Dec 25 '22 at 07:52

0 Answers0