0

私のウェブサイト www.theprinterdepo.com では、ページのソースを表示できます。私の seo コンサルティングが外部ファイルに移動するように提案したコードがあります。

Magentoで構築されたeコマースサイトです。IT は無料のオープン ソース ツールなので、開発はせず、インストールしただけです。

コードが何をするのかを知る必要があります。

window.HDUSeed='c7025284683262a8eb81056c48968d74';
window.HDUSeedIntId = setInterval(function(){
    if (document.observe) {
        document.observe('dom:loaded', function(){
            for (var i = 0; i < document.forms.length; i++) {
                if (document.forms[i].getAttribute('action') &&  document.forms[i].getAttribute('action').match('contacts/index/post')) {
                    var el = document.createElement('input');
                    el.type = ('hidden');
                    el.name = 'hdu_seed';
                    el.value = window.HDUSeed;
                    document.forms[i].appendChild(el);
                }
            }
        });
        clearInterval(window.HDUSeedIntId)
    }
}, 100);
4

4 に答える 4

7

簡単に

このスクリプトは、約 100 ミリ秒間隔で関数を呼び出し (保証されていないため)、DOM の負荷ステータスを確認してフックを追加しようとします。

読み込まれると、ページに存在するすべてのフォームを処理し、「アクション」属性を持つフォームを探します (通常は、ここで送信しますcontacts/index/post)。

見つかったそのようなすべてのフォームに、「シード」値を含む新しい非表示の入力要素を追加しますが、コードベースについて詳しく知らなければ、それが何に使用されるかはわかりません。

詳細なコード レビュー

// seed value, purpose unknown
window.HDUSeed='c7025284683262a8eb81056c48968d74';

// invoke this function every 100ms
//   see: https://developer.mozilla.org/en/DOM/window.setInterval
window.HDUSeedIntId = setInterval(function(){
    // checks if document.observe method exists (added by the Prototype
    // JavaScript library, so we use this here to check its presence or
    // that it's been already loaded)
    if (document.observe) {
        // hook on load status (when the page's DOM has finished loading)
        //   see: http://www.prototypejs.org/api/document/observe
        document.observe('dom:loaded', function(){
            // process all forms contained within the page's context
            //   see: https://developer.mozilla.org/en/DOM/document.forms
            for (var i = 0; i < document.forms.length; i++) {
                // only act on forms with the 'contacts/index/post/' action attribute
                //   see: https://developer.mozilla.org/en/DOM/document.forms
                //   and: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/match
                if (document.forms[i].getAttribute('action') && 
                    document.forms[i].getAttribute('action').match('contacts/index/post')) {
                    // create an element...
                    //   see: https://developer.mozilla.org/en/DOM/document.createElement
                    var el = document.createElement('input');
                    el.type = ('hidden');              // ... that is hidden
                    el.name = 'hdu_seed';              // w/ name 'hdu_seed'
                    el.value = window.HDUSeed;         // and the seed value
                    document.forms[i].appendChild(el); // and add it to the end of the form
                }
            }
        });
        // Remove the interval to not call this stub again,
        // as you've done what you want.
        // To do this, you call clearInterval with the ID of the
        // interval callback you created earlier.
        //   see: https://developer.mozilla.org/en/DOM/window.clearInterval
        clearInterval(window.HDUSeedIntId)
    }
}, 100); // 100ms
于 2012-06-06T18:47:52.577 に答える