6

ChromeまたはGreasemonkeyスクリプトの魔女がキュー内のすべてのポップアップを開くことができるかどうかを尋ねたいと思います。これまでのところ、これには2つの別個のスクリプトがありますが、ポップアップにはスパム対策機能があり、同時に多くのスクリプトを許可しないため、これはうまく機能していません。

私がやりたいのは、ポップアップリンクの配列をキュー形式で処理し、前のリンクが閉じているときにのみ次のリンクを開くことです。キューやあらゆる種類のイベントバインディングに至ると、私には経験がありません。

だから私が得たリソース:

1)すでに準備されているリンクの配列

var URL_Array = [];

$('form[name="form_gallery"] .img img').each(function(i,e){
    // Format URL array here
    if($(this).closest('.object').children('.phs_voted_count').length == 0){
        var string = e.src;
        var nowBrake = string.substring(string.length-7,7);
        var splited = nowBrake.split('/');
        var urlStr = '/window/friend/gallery_view/'+splited[3]+'/'+splited[4]+'.html';
        URL_Array[i] = urlStr;
    }
});

2)ポップアップの画像に投票するスクリプト

    /*######################################################*/  
    var voteBy            = '#vte_mark_12';            // Prefered vote icon
    var voteDefault       = '#vte_mark_5';             // Default vote icon
    var voteFormLoc       = 'image_voting';            // Image voting popups form
    var buyExtraVote      = 'image_voting_buy';        // If run out of votes buy more
    var captchaLoc        = 'input[name="captcha"]';   // Captcha input field
    var captchaTxt        = 'Enter captcha text!';     // Captcha alert text
    var simpatyFormId     = '#sym_send';               // Simpaty window form

    var startScript          = true; 
    var formProcessedAlready = false; // Used to check if image already was voted
    /*######################################################*/  

$(function(){
    if(startScript){
        if($(captchaLoc).length > 0){
            alert(captchaTxt);
            $(captchaLoc).focus().css('border', '2px solid red');
            return false;
        }else{
            if($('#50').length > 0){
                $('#50').attr('checked', true);
                $('form').attr('id', buyExtraVote);
                $('#'+buyExtraVote).submit();
            }else{
                $('form').attr('id', voteFormLoc);
                if($(voteBy).length > 0){
                    $(voteBy).attr('checked', true);
                    setTimeout("$('#"+voteFormLoc+"').submit()", 2000);
                }else if($(voteDefault).length > 0){
                    $(voteDefault).attr('checked', true);
                    setTimeout("$('#"+voteFormLoc+"').submit()", 2000);
                }else{
                    // If we have simpaty box autocast submit
                    if($(simpatyFormId).length > 0){
                        if($(captchaLoc).length > 0){
                            alert(captchaTxt);
                            $(captchaLoc).focus().css('border', '2px solid red');
                            return false;
                        }else{
                            $(simpatyFormId).submit();
                            formProcessedAlready = true;
                        }
                    }else{
                        formProcessedAlready = true;
                    }
                }
            }
        }

        if(formProcessedAlready){
            self.close();
        }
    }
});

私が理解できる限り、それは次のようになるはずです:
1)すべての投票されていないURLとフォーム配列を取得する(完了)
2)すべてのポップアップをキューに入れて開く
3)最初のポップアップを開始する
4)投票が完了してポップアップが閉じる(完了)
5)2番目に開始ポップアップ
6)アレイが終了したら、次のページに切り替えます(完了)

あなたが思うこと?

4

2 に答える 2

2

あなたは次のようなことをすることができます:

var links = get_your_links();
function process_one() {
    if(links.length > 0) {
        show_popup(links.pop(), process_one);
    }
}
function show_popup(link, callback) {
   var popup = window.open(link, "mywindow", "width=100,height=100");
   $(popup).bind("beforeunload", function() { 
     process_one();
     return true;
   })

}

お役に立てば幸いです...

于 2011-04-26T17:25:34.823 に答える
2
  • メインページとポップアップの正確なURLは何ですか?
  • 使用しているjQueryのバージョンと、それをどのように組み込んでいますか?

スクリプトはメインページとポップアップの両方を処理し、それぞれで異なる動作をする必要があるため、正確なURLは重要です。

これを処理する主な方法は2つあります。また:

  1. ディレクティブを使用includeして、スクリプトがメインページとポップアップの両方で実行されるようにしますが、ページタイプに応じて動作を切り替えます。これにより、スクリプトの2つの異なるインスタンスが同時に実行されますが、これは問題ではありません。

  2. スクリプトがメインページでのみ実行されるようにするには、ディレクティブを使用includeします。次に、ポップアップを開くコードでフォームを操作します。exclude


アプローチ1の方法は次のとおりです。


    somewhere.com/main/*
    (1)メインページが次のようであり、ポップアップページが次のようであると仮定し
    somewhere.com/window/friend/gallery_view/*
    ます。スクリプトのinclude-directivesが両方のページセットで起動することを確認します。

(2)jQueryが両方の種類のページで使用可能であることを確認します。jQuery1.5.1をお勧めします。jQuery 1.3.2は、次のコードではおそらく機能しません。

(3)次に、次のようなコードが機能するはずです。

var URL_Array   = [];
var PopupQueue  = $({});    //-- jQuery on an empty object - a perfect queue holder

//--- Is this a popup window or the main page?

if ( /\/window\/friend\/gallery_view\//i.test (window.location.href) )
{
    //--- This is a popup page

    /*######################################################*/  
    var voteBy            = '#vte_mark_12';            // Prefered vote icon
    var voteDefault       = '#vte_mark_5';             // Default vote icon
    var voteFormLoc       = 'image_voting';            // Image voting popups form
    var buyExtraVote      = 'image_voting_buy';        // If run out of votes buy more
    var captchaLoc        = 'input[name="captcha"]';   // Captcha input field
    var captchaTxt        = 'Enter captcha text!';     // Captcha alert text
    var simpatyFormId     = '#sym_send';               // Simpaty window form

    var startScript          = true; 
    var formProcessedAlready = false; // Used to check if image already was voted
    /*######################################################*/  

    $(function(){
        if(startScript){
            if($(captchaLoc).length > 0){
                alert(captchaTxt);
                $(captchaLoc).focus().css('border', '2px solid red');
                return false;
            }else{
                if($('#50').length > 0){
                    $('#50').attr('checked', true);
                    $('form').attr('id', buyExtraVote);
                    $('#'+buyExtraVote).submit();
                }else{
                    $('form').attr('id', voteFormLoc);
                    if($(voteBy).length > 0){
                        $(voteBy).attr('checked', true);
                        setTimeout("$('#"+voteFormLoc+"').submit()", 2000);
                    }else if($(voteDefault).length > 0){
                        $(voteDefault).attr('checked', true);
                        setTimeout("$('#"+voteFormLoc+"').submit()", 2000);
                    }else{
                        // If we have simpaty box autocast submit
                        if($(simpatyFormId).length > 0){
                            if($(captchaLoc).length > 0){
                                alert(captchaTxt);
                                $(captchaLoc).focus().css('border', '2px solid red');
                                return false;
                            }else{
                                $(simpatyFormId).submit();
                                formProcessedAlready = true;
                            }
                        }else{
                            formProcessedAlready = true;
                        }
                    }
                }
            }

            if(formProcessedAlready){
                self.close();
            }
        }
    });
}
else
{   //--- This is a main page

    $('form[name="form_gallery"] .img img').each(function(i,e){
        // Format URL array here
        if($(this).closest('.object').children('.phs_voted_count').length == 0){
            var string = e.src;
            var nowBrake = string.substring(string.length-7,7);
            var splited = nowBrake.split('/');
            var urlStr = '/window/friend/gallery_view/'+splited[3]+'/'+splited[4]+'.html';
            URL_Array[i] = urlStr;
        }
    });

    //--- Load up the queue.
    $.each (URL_Array, function (PopupNum, PopupURL) {

        PopupQueue.queue ('Popups', function (NextQ_Item) {

            OpenPopupFromQueue (NextQ_Item, PopupNum+1, PopupURL);
        } );
    } );

    //--- Launch the Popups, one at a time.
    PopupQueue.dequeue ('Popups');
}


function OpenPopupFromQueue (NextQ_Item, PopupNum, PopupURL)
{
    var PopupWin    = window.open (PopupURL, "_blank");
    if (!PopupWin)
    {
        console.log ('Bad URL ' + PopupURL)
        setTimeout (function() { NextQ_Item (); }, 2003);
        return;
    }

    /*--- Only after the popup has loaded can we do any processing.
    */
    PopupWin.addEventListener (
        "load",
        function () {
            /*--- Setup the listener for when the popup has closed.
                We fire the next popup from the queue, there.
            */
            PopupWin.addEventListener (
                "unload",
                function () {
                    PopupClosed (NextQ_Item);
                },
                false
            );

            /*--- We could process the popup here, but it's better to let another instance of this
                script do it, instead.
            */
        },
        false
    );
}


function PopupClosed (NextQ_Item)
{
    //--- Launch the next popup from the queue.
    NextQ_Item ();
}
于 2011-05-01T06:04:54.607 に答える