如果未找到正则表达式匹配,如何编写脚本jquery以重新加载页面

时间:2017-03-16 06:23:05

标签: jquery regex expression userscripts tampermonkey

我希望在网页正文中查找/搜索匹配的正则表达式(在此示例中为PO123456)。如果发现我想要一个警告说它被找到并且脚本停止运行。如果未找到RegEx匹配,我希望重复重新加载页面,直到找到匹配项。然后我会将此脚本粘贴到TamperMonkey中,以便在当前要求我像实验动物一样重复刷新的页面上使用。

以下不起作用,但......

// ==UserScript==
// @name         Reload Page If RegEx Match Not Found
// @namespace   
// @version      0.1
// @description  Reloads Page Until RegEx Match Found
// @author       TJ
// @match        https://system.fakepage.com/someotherpage
// @grant        none
// ==/UserScript==

$(document).ready(function()
{
    var regex = /^PO\d{6}g/;
    var PO = str.match(regex);

    if($('body:contains("' + PO + '")').length > 0)
    {
    alert("Found: " + PO);
    }
    else
    {
        location.reload();
    }
});

请帮助我把这个剧本弄清楚,帮助聪明的pavlovian控制系统! (经过测试,我想废除警报。)

1 个答案:

答案 0 :(得分:0)

function validation()
{
    flag=false;
    var Sno= document.getElementById('Sno').value++;
        if(Sno==null || Sno=="")
        {
            alert("Enter serial no");
            flag=true;
        }
    var Clientname= document.getElementById('Clientname').value

        if( Clientname==null || Clientname==""){
        document.getElementById('Clientname').style.borderColor= "red";
        flag=true;
        }
        else{
            document.getElementById('Clientname').style.borderColor="green";
        }

    var Contactno= document.getElementById('Contactno').value
        if( Contactno==null || Contactno==""){
        document.getElementById('Contactno').style.borderColor= "red";
        flag=true;
        }
        else{
            document.getElementById('Contactno').style.borderColor="green";
        }
    var Dos= document.getElementById('Dos').value;
        if( Dos==null || Dos==""){
        document.getElementById('Dos').style.borderColor= "red";
        flag=true;
        }
        else{
            document.getElementById('Dos').style.borderColor="green";
        }

    var Start= document.getElementById('Start').value;
        if( Start==null || Start==""){
        document.getElementById('Start').style.borderColor= "red";
        flag=true;
        }
        else{
            document.getElementById('Start').style.borderColor="green";
        }

    var End= document.getElementById('End').value;
        if( End==null || End==""){
        document.getElementById('End').style.borderColor= "red";
        flag=true;
        }
        else{
            document.getElementById('End').style.borderColor="green";
        }


     var Dow= document.getElementById('Dow').value;
        if( Dow==null || Dow==""){
        document.getElementById('Dow').style.borderColor= "red";
        flag=true;
        }
        else{
            document.getElementById('Dow').style.borderColor="green";
        }


    var Osi= document.getElementById('Osi').value;
        if( Osi==null || Osi==""){
        document.getElementById('Osi').style.borderColor= "red";
        flag=true;
        }
        else{
            document.getElementById('Osi').style.borderColor="green";
        }



    var Emhr= document.getElementById('Emhr').value;
        if( Emhr==null || Emhr==""){
        document.getElementById('Emhr').style.borderColor= "red";
        flag=true;
        }
        else{
            document.getElementById('Emhr').style.borderColor="green";
        }


    var Er= document.getElementById('Er').value;
        if( Er==null || Er==""){
        document.getElementById('Er').style.borderColor= "red";
        flag=true;
        }
        else{
            document.getElementById('Er').style.borderColor="green";
        }


    var Mir= document.getElementById('Mir').value;
        if( Mir==null || Mir==""){
        document.getElementById('Mir').style.borderColor= "red";
        flag=true;
        }
        else{
            document.getElementById('Mir').style.borderColor="green";
        }


    var Ea= document.getElementById('Ea').value;
        if( Ea==null || Ea==""){
        document.getElementById('Ea').style.borderColor= "red";
        flag=true;
        }
        else{
            document.getElementById('Ea').style.borderColor="green";
        }


    var Cr= document.getElementById('Cr').value
        if( Cr==null || Cr==""){
        document.getElementById('Cr').style.borderColor= "red";
        flag=true;
        }
        else{
            document.getElementById('Cr').style.borderColor="green";
        }


    var Mir1= document.getElementById('Mir1').value;
        if( Mir1==null || Mir1==""){
        document.getElementById('Mir1').style.borderColor= "red";
        flag=true;
        }
        else{
            document.getElementById('Mir1').style.borderColor="green";
        }

    var Am= document.getElementById('Am').value;
        if( Am==null || Am==""){
        document.getElementById('Am').style.borderColor= "red";
        flag=true;
        }
        else{
            document.getElementById('Am').style.borderColor="green";
        }
    var Ca= document.getElementById('Ca').value;
        if( Ca==null || Ca==""){
        document.getElementById('Ca').style.borderColor= "red";
        flag=true;
        }
        else{
            document.getElementById('Ca').style.borderColor="green";
        }
    var date= document.getElementById('date').value;
        if( date==null || date==""){
        document.getElementById('date').style.borderColor= "red";
        flag=true;
        }
        else{
            document.getElementById('date').style.borderColor="green";
        }

    if(flag=true)
    {
      return  false;
    }
    else 
    {
      return true;
    }     

}