Sleipnir Script BBS



タイトルAutoLoginCreator.js
カテゴリ: 1.xx互換スクリプト
記事No: 2 [関連記事]
投稿日: 2008/10/07(Tue) 22:37
投稿者sleepy(webmaster)
/***************************************************************

                Auto Login Creator(2008/10/07)
                                        written by sleepy

***************************************************************/

var MyTitle = "Auto Login Creator";
var MyVer = "(2008/10/07)";
var Slpnr = new ActiveXObject("Sleipnir.API");

if (Slpnr){
    String.prototype.trim = Trim;
    String.prototype.replaceFileName = replaceFileName;
    String.prototype.replaceSectionName = replaceSectionName;
    var FS = WScript.CreateObject("Scripting.FileSystemObject");
    var id = Slpnr.GetDocumentID(Slpnr.ActiveIndex);
    var document = Slpnr.GetDocumentObject(id);
    ActiveDocument.prototype.parentAE = GetParentActiveElement;
    var AD = new ActiveDocument();
    var P = new AutoLoginParam();

    Main();

    P = null;
    AD = null;
    document = null;
    FS = null;
    Slpnr = null;
}

function Main(){
    try {
        if (!document){
            throw (new Error(0, "ログインスクリプトを作成したいページを開いてから実行して下さい。"));
        }
        showStartDlg();
        getActive("入力フォーム");
        getMainDoc();
        getForm();
        showWaitDlg();
        getActive("ログインボタン");
        getSubmitDoc();
        if (selectModeDlg()){
            showIncludeDlg();
            isClickDlg()
        }
        else {
            showFolderDlg();
        }
        do {
            showFileNameDlg();
        } while (!showOverwriteDlg());
        do {
            showIniSectDlg();
        } while (!showSectExistDlg());
        showSaveDatDlg();
        createScriptFile();
        showEndDlg();
    }
    catch(error){
        showErrDlg(error.number, error.description);
    }
}

function showStartDlg(){
    try {
        var strMsg = "入力フォーム(アカウント名入力欄・パスワード入力欄等)\nがアクティブになっていますか?";
        var blnChk = showDlg(strMsg, 4 + 32);
        if (!blnChk){
            throw(new Error());
        }
    }
    catch(error){
        if (!error.number){
            throw (new Error(0, "入力フォームをアクティブにし、再実行して下さい。"));
        }
        else {
            throw (new Error(error.number, "showStartDlg -> " + error.description));
        }
    }
}

function getActive(strMsg){
    if (!AD.getDocument(document)){
        throw (new Error(1, strMsg + "の存在するドキュメントを取得できません。"));
    }
}

function getMainDoc(){
    try {
        P.PageURL = document.parentWindow.location.href;
        P.LoginURL = AD.self.parentWindow.location.href;
        P.MainSyntax = AD.elementSyntax;
        P.PageTitle = document.title;
        P.ScriptTitle = document.title.trim().replaceFileName();
        if (!P.ScriptTitle){
            P.PageURL.match(/([^\/]+)\/([^\/]*)$/);
            P.ScriptTitle = "AutoLogin_" + (RegExp.$1 + "_" + RegExp.$2).trim().replaceFileName();
        }
        var strTmp = document.parentWindow.location.hostname.trim().replaceSectionName();
        if (strTmp){
            P.IniSection = strTmp;
        }
        else {
            P.PageURL.match(/([^\/]+)\/([^\/]*)$/);
            P.IniSection = (RegExp.$1 + "_" + RegExp.$2).trim().replaceSectionName();
        }
    }
    catch(error){
        throw (new Error(error.number, "getMainDoc -> " + error.description));
    }
}

function getForm(){
    try {
        var objForm = AD.parentAE("FORM");
        if (!objForm){
            throw new Error();
        }
        P.FormAct = objForm.action;
        for (i = 0; i < AD.self.forms.length; i++){
            if (AD.self.forms(i) == objForm){
                P.FormNm = i;
                break;
            }
        }
        for (i = 0; i < objForm.elements.length; i++){
            if (objForm.elements(i).tagName.match(/^INPUT$/i)){
                if (!objForm.elements(i).type){
                    P.AcntNm.push(i);
                    P.AcntValue.push(objForm.elements(i).value);
                }
                else {
                    if (objForm.elements(i).type.match(/^text$/i)){
                        P.AcntNm.push(i);
                        P.AcntValue.push(objForm.elements(i).value);
                    }
                    if (objForm.elements(i).type.match(/^password$/i)){
                        P.PassNm.push(i);
                        P.PassValue.push(objForm.elements(i).value);
                    }
                    if (objForm.elements(i).type.match(/^radio$|^checkbox$/i)){
                        if (objForm.elements(i).checked){
                            P.ChkTrue.push(i);
                        }
                        else {
                            P.ChkFalse.push(i);
                        }
                    }
                }
            }
            if (objForm.elements(i).tagName.match(/^SELECT$/i)){
                P.SelNm.push(i);
                P.SelIndex.push(objForm.elements(i).selectedIndex);
            }
        }
    }
    catch(error){
        if (!error.number){
            throw (new Error(1, "フォームを取得できません。"));
        }
        else {
            throw (new Error(error.number, "getForm -> " + error.description));
        }
    }
    finally {
        objForm = null;
    }
}

function showWaitDlg(){
    var lngWait = Slpnr.GetProfileInt("ALC_config", "waitTime", 5);
    try {
        showDlg("続いてログインする際に押すボタン(or 画像 or リンク)を右クリックし、アクティブにして下さい。"
                + "\n(表示されたコンテキストメニューはそのままにしておいて下さい。)"
                + "\n\nこのダイアログを閉じてから、約" + lngWait + "秒後に作成を再開しますので、それまでに実行して下さい。");
        WScript.Sleep(lngWait * 1000);
        var blnChk = showDlg("作成を再開します。ボタン(or 画像 or リンク)をアクティブにしましたか?", 4 + 32);
        if (!blnChk){
            throw(new Error());
        }
    }
    catch(error){
        if (!error.number){
            throw (new Error(0, "メッセージに従って、再実行して下さい。"));
        }
        else {
            throw (new Error(error.number, "showWaitDlg -> " + error.description));
        }
    }
}

function getSubmitDoc(){
    try {
        P.SubmitURL = AD.self.parentWindow.location.href;
        P.SubmitSyntax = AD.elementSyntax;
        P.SubmitTag = AD.self.activeElement.tagName;
        for (i = 0; i < AD.self.all.tags(P.SubmitTag).length; i++){
            if (AD.self.all.tags(P.SubmitTag)(i) == AD.self.activeElement){
                P.SubmitNm = i;
                break;
            }
        }
    }
    catch(error){
        throw (new Error(error.number, "getSubmitDoc -> " + error.description));
    }
}

function selectModeDlg(){
    try {
        if (!FS.FileExists(Slpnr.AppPath + "..\\plugins\\extension\\SeaHorseExtension.fx")){
            P.IsSH = false;
        }
        else {
            switch (Slpnr.GetProfileInt("ALC_config", "selectModeDlg", 0)){
                case 1:
                P.IsSH = false;
                break;
                case 2:
                P.ScriptPath = Slpnr.AppPath + "..\\plugins\\seahorse\\";
                P.IsSH = true;
                break;
                default:
                if (showDlg("SeaHorseプラグインが見つかりました。\nSeaHorse用スクリプトとして作成しますか?", 4 + 32 + 256)){
                    P.ScriptPath = Slpnr.AppPath + "..\\plugins\\seahorse\\";
                    P.IsSH = true;
                }
                else {
                    P.IsSH = false;
                }
            }
        }
        return P.IsSH;
    }
    catch(error){
        throw (new Error(error.number, "selectModeDlg -> " + error.description));
    }
}

function showIncludeDlg(){
    try {
        switch (Slpnr.GetProfileInt("ALC_config", "showIncludeDlg", 0)){
            case 1:
            break;
            default:
            var strTmp;
            do {
                strTmp = inputDlg("このスクリプトが動作するURL?(ワイルドカード利用可)"
                                  + "\n(OK:決定、キャンセル:中断)", P.PageURL);
                if (strTmp == null){
                    throw (new Error());
                }
            } while (strTmp.match(/[^\w-.!~*\'();\/?:\@&=+\$,%#]/) || !strTmp);
            P.PageURL = strTmp;
        }
    }
    catch(error){
        if (!error.number){
            throw (new Error(0, "作成を中止します。"));
        }
        else {
            throw (new Error(error.number, "showIncludeDlg -> " + error.description));
        }
    }
}

function isClickDlg(){
    try {
        switch (Slpnr.GetProfileInt("ALC_config", "isClickDlg", 0)){
            case 1:
            P.IsLogin = false;
            break;
            case 2:
            P.IsLogin = true;
            break;
            default:
            if (showDlg("ボタンクリックまで自動化しますか?\n(複数アカウントを使い分ける場合等、自動化しない方がよいことがあります)", 4 + 32 + 256)){
                P.IsLogin = true;
            }
            else {
                P.IsLogin = false;
            }
        }
    }
    catch(error){
        throw (new Error(error.number, "isClickDlg -> " + error.description));
    }
}

function showFolderDlg(){
    try {
        switch (Slpnr.GetProfileInt("ALC_config", "showFolderDlg", 0)){
            case 1:
            P.ScriptPath = Slpnr.ScriptPath;
            break;
            case 2:
            P.ScriptPath = Slpnr.ScriptPath + Slpnr.GetProfileString("ALC_config", "scriptPath", "");
            break;
            default:
            var objShell = WScript.CreateObject("Shell.Application");
            var objFolder = objShell.BrowseForFolder(Slpnr.Handle, "作成するフォルダを指定して下さい。\n(OK:決定、キャンセル:中断)"
                                                     , 0x0040, Slpnr.ScriptPath);
            if (!objFolder){
                throw (new Error());
            }
            P.ScriptPath = objFolder.Items().Item().Path;
        }
    }
    catch(error){
        if (!error.number){
            throw (new Error(0, "作成を中止します。"));
        }
        else {
            throw (new Error(error.number, "showFolderDlg -> " + error.description));
        }
    }
    finally {
        objFolder = null;
        objShell = null;
    }
}

function showFileNameDlg(){
    var strTmp;
    try {
        switch (Slpnr.GetProfileInt("ALC_config", "showFileNameDlg", 0)){
            case 1:
            break;
            default:
            do {
                strTmp = inputDlg("作成するスクリプト名?(拡張子は必要ありません)\n(OK:決定、キャンセル:中断)", P.ScriptTitle);
                if (strTmp == null){
                    throw (new Error());
                }
            } while ((strTmp = strTmp.trim().replaceFileName(true)) == "");
            P.ScriptTitle = strTmp;
        }
    }
    catch(error){
        if (!error.number){
            throw (new Error(0, "作成を中止します。"));
        }
        else {
            throw (new Error(error.number, "showFileNameDlg -> " + error.description));
        }
    }
}

function showOverwriteDlg(){
    var blnRet = true;
    try {
        switch (Slpnr.GetProfileInt("ALC_config", "showOverwriteDlg", 0)){
            case 1:
            break;
            default:
            if (FS.FileExists(P.ScriptFullName())
                && !(Slpnr.GetProfileInt("ALC_config", "showFileNameDlg", 0))){
                var blnChk = showDlg(P.ScriptTitle + (P.IsSH?'.user':'') + ".js : 同名のファイルが存在しています。\n上書きしますがよろしいですか?"
                                     , 4 + 32);
                if (!blnChk){
                    blnRet = false;
                }
            }
        }
        return blnRet;
    }
    catch(error){
        throw (new Error(error.number, "showOverwriteDlg -> " + error.description));
    }
}

function showIniSectDlg(){
    try {
        switch (Slpnr.GetProfileInt("ALC_config", "showIniSectDlg", 0)){
            case 1:
            break;
            default:
            var strTmp;
            do {
                strTmp = inputDlg("Script.iniのセクション名?(半角英数・セクション重複に注意)"
                                  + "\n(OK:決定、キャンセル:中断)", P.IniSection);
                if (strTmp == null){
                    throw (new Error());
                }
            } while (strTmp.match(/\W/) || !strTmp);
            P.IniSection = strTmp;
        }
    }
    catch(error){
        if (!error.number){
            throw (new Error(0, "作成を中止します。"));
        }
        else {
            throw (new Error(error.number, "showIniSectDlg -> " + error.description));
        }
    }
}

function showSectExistDlg(){
    var blnRet = true;
    try {
        switch (Slpnr.GetProfileInt("ALC_config", "showSectExistDlg", 0)){
            case 1:
            break;
            default:
            if (Slpnr.GetProfileString("AutoLogin_" + P.IniSection, "Account_0", "NoKey") != "NoKey"
                && !(Slpnr.GetProfileInt("ALC_config", "showIniSectDlg", 0))){
                var blnChk = showDlg(P.IniSection + " : 同名のセクションが存在しています。重複しますがよろしいですか?"
                                     + "\n(「はい」を選択した場合、このセクションに保存されているアカウントデータは削除/上書きされます)", 4 + 32);
                if (!blnChk){
                    blnRet = false;
                }
            }
        }
        return blnRet;
    }
    catch(error){
        throw (new Error(error.number, "showSectExistDlg -> " + error.description));
    }
}

function showSaveDatDlg(){
    try {
        switch (Slpnr.GetProfileInt("ALC_config", "showSaveDatDlg", 0)){
            case 1:
            P.SavePassword = false;
            break;
            case 2:
            P.SavePassword = true;
            break;
            default:
            P.SavePassword = showDlg("パスワードをScript.iniに保存しますか?", 4 + 32 + 256);
        }
    }
    catch(error){
        throw (new Error(error.number, "showSaveDatDlg -> " + error.description));
    }
}

function createScriptFile(){
    try {
        if (!FS.FolderExists(P.ScriptPath)){
            FS.CreateFolder(P.ScriptPath);
        }
        writeScript();
        for (i = 0; i < P.AcntNm.length; i++){
            Slpnr.WriteProfileStringCipher("AutoLogin_" + P.IniSection, "Account_" + i, P.AcntValue[i]);
        }
        if (P.SavePassword){
            for (i = 0; i < P.PassNm.length; i++){
                if (P.PassValue[i]){
                    Slpnr.WriteProfileStringCipher("AutoLogin_" + P.IniSection, "Password_" + i, P.PassValue[i]);
                }
            }
        }
    }
    catch(error){
        throw (new Error(error.number, "createScriptFile -> " + error.description));
    }
}

function writeScript(){
    try {
        var objFile = FS.CreateTextFile(P.ScriptFullName(), true);
        var SEQ;
        if (P.IsSH){
            WL('// ==UserScript==');
        }
        WL('// ' + (P.IsSH?'@name ':'') + '自動ログイン : ' + P.ScriptTitle);
        WL('// ' + (P.IsSH?'@author ':'generated by ') + '"' + MyTitle + MyVer + '"');
        if (P.IsSH){
            WL('// @include ' + P.PageURL);
            WL('// @type SleipnirScript');
            WL('// ==/UserScript==');
        }
        else if (Slpnr.Version < 200){
            WL('// このスクリプトを読込完了時スクリプトとして実行する場合、');
            WL('// ' + P.PageURL + '<script=' + P.ScriptFullName().substr(Slpnr.ScriptPath.length) + '>');
            WL('// 上記URLでお気に入りに登録してください。');
        }
        WL('');
        WL('// このスクリプトの改変は自由に行っていただいてかまいません。');
        WL('');
        WL('// 任意の値を設定してください。');
        if (!P.IsSH){
            WL('var timeout       = 20;        // タイムアウトまでの待ち時間(単位:秒)');
            WL('var waitforV2     = 2;         // Sleipnir2対策・セキュリティ切替実行までの待ち時間(単位:秒)');
        }
        WL('var savePassword  = ' + P.SavePassword + ';        // パスワードを Script.ini に保存する:true、保存しない:false');
        for (i = 0; i < P.AcntNm.length; i++){
            if (P.AcntNm.length > 1){
                SEQ = i + 1;
            }
            else {
                SEQ = "";
            }
            WL('var accountPromptName_' + i + '  = "ユーザID' + SEQ + '";        // アカウント入力ダイアログの項目名');
        }
        for (i = 0; i < P.PassNm.length; i++){
            if (P.PassNm.length > 1){
                SEQ = i + 1;
            }
            else {
                SEQ = "";
            }
            WL('var passwordPromptName_' + i + ' = "パスワード' + SEQ + '";        // パスワード入力ダイアログの項目名');
        }
        if (!P.IsSH){
            WL('// 以下、ページを開く際のセキュリティ設定。作成時に設定し忘れた場合変更して下さい。');
            WL('// trueがオン(ログイン時に必要)、falseがオフ(ログイン時特に必要なし)です。');
            WL('var blnScr        = ' + Slpnr.IsJavaScriptEnabled(id) + ';        // JavaScriptの実行');
            WL('var blnJav        = ' + Slpnr.IsJavaEnabled(id) + ';        // Javaの実行');
            WL('var blnAct        = ' + Slpnr.IsRunActiveXEnabled(id) + ';        // ActiveXの実行');
            WL('var blnAdl        = ' + Slpnr.IsDownloadActiveXEnabled(id) + ';        // ActiveXのダウンロード');
            WL('var blnPic        = ' + Slpnr.IsPictureEnabled(id) + ';        // 画像の再生');
            WL('var blnSou        = ' + Slpnr.IsSoundEnabled(id) + ';        // サウンドの再生');
            WL('var blnVid        = ' + Slpnr.IsVideoEnabled(id) + ';        // ビデオの再生');
        }
        else {
                WL('var blnChkTitle   = true;        // タイトルが一致したときのみ実行:true、無条件に実行:false');
                WL('var blnChkForm    = true;        // form.actionが一致したときのみ実行:true、無条件に実行:false');
        }
        WL('// 設定ここまで。');
        WL('');
        WL('var Slpnr = new ActiveXObject("Sleipnir.API");');
        if (P.IsSH){
            WL('var document = _document;');
            WL('var window;');
        }
        else {
            WL('var Arg = WScript.Arguments;');
            WL('var document;');
            WL('var window;');
            WL('var id;');
            WL('var resetIniData  = Slpnr.ShiftDown;');
        }
        WL('var t;');
        WL('');
        WL('var loginPage     = "' + P.IniSection + '";');
        if (!P.IsSH){
            WL('var pageURL       = "' + P.PageURL + '";');
            if (P.MainSyntax){
                WL('var LoginURL      = "' + P.LoginURL + '";');
            }
            if (P.MainSyntax != P.SubmitSyntax){
                WL('var SubmitURL     = "' + P.SubmitURL + '";');
            }
        }
        for (i = 0; i < P.AcntNm.length; i++){
            WL('var accountTag_' + i + '  = ' + P.AcntNm[i] + ';');
        }
        for (i = 0; i < P.PassNm.length; i++){
            WL('var passwordTag_' + i + ' = ' + P.PassNm[i] + ';');
        }
        for (i = 0; i < P.ChkTrue.length; i++){
            WL('var checkTag_' + i + '    = ' + P.ChkTrue[i] + ';');
        }
        for (i = 0; i < P.ChkFalse.length; i++){
            WL('var uncheckTag_' + i + '  = ' + P.ChkFalse[i] + ';');
        }
        for (i = 0; i < P.SelNm.length; i++){
            WL('var selTag_' + i + '      = ' + P.SelNm[i] + ';');
        }
        WL('var formNumber    = ' + P.FormNm + ';');
        WL('var submitTag     = "' + P.SubmitTag + '";');
        WL('var submitNumber  = ' + P.SubmitNm + ';');
        WL('');
        for (i = 0; i < P.AcntNm.length; i++){
            WL('var account_' + i + '     = "";');
        }
        for (i = 0; i < P.PassNm.length; i++){
            WL('var password_' + i + '    = "";');
        }
        for (i = 0; i < P.SelNm.length; i++){
            WL('var selindex_' + i + '    = ' + P.SelIndex[i] + ';');
        }
        WL('');
        if (!P.IsSH){
            WL('Main();');
        }
        else {
            WL('var pageTitle     = "' + P.PageTitle + '";');
            WL('var formAction    = "' + P.FormAct + '";');
            WL('');
            WL('if (((blnChkTitle && document.title == pageTitle) || !blnChkTitle) &&');
            WL('    ((blnChkForm && document.forms(formNumber).action == formAction) || !blnChkForm)){');
            WL('    Main();');
            WL('}');
        }
        WL('');
        WL('window = null;');
        WL('document = null;');
        if (!P.IsSH){
            WL('Arg = null;');
        }
        WL('Slpnr = null;');
        WL('');
        WL('function Main(){');
        if (!P.IsSH){
            WL('    var ArgChk = false;');
            WL('    if (Arg.length != 0){');
            WL('        try {');
            WL('            if (Slpnr.GetWindowObject(Arg(0)).location.href == pageURL){');
            WL('                ArgChk = true;');
            WL('            }');
            WL('        }');
            WL('        catch(error){');
            WL('        }');
            WL('    }');
            WL('    if (ArgChk){');
            WL('        id  = Arg(0);');
            WL('    }');
            WL('    else if (Slpnr.URL != pageURL){');
            WL('        id  = Slpnr.NewWindow(pageURL, true);');
            WL('    }');
            WL('    else {');
            WL('        id = Slpnr.GetDocumentID(Slpnr.ActiveIndex);');
            WL('    }');
            // Sleipnir2対策ココカラ
            WL('    // Sleipnir2対策ココカラ');
            WL('    if (Slpnr.Version >= 200){');
            WL('        t = 0;');
            WL('        do {');
            WL('            WScript.Sleep(500);');
            WL('            t += 500;');
            WL('        } while ((Slpnr.IsBusy(id)) && (t < (timeout * 1000)));');
            WL('        if (t >= (timeout * 1000)){');
            WL('            Quit();');
            WL('            return false;');
            WL('        }');
            WL('        else {');
            WL('            WScript.Sleep(waitforV2 * 1000);');
            WL('        }');
            WL('    }');
            WL('    // Sleipnir2対策ココマデ');
            // Sleipnir2対策ココマデ
            WL('    if ((blnScr && !Slpnr.IsJavaScriptEnabled(id)) || (blnJav && !Slpnr.IsJavaEnabled(id))');
            WL('     || (blnAct && !Slpnr.IsRunActiveXEnabled(id)) || (blnAdl && !Slpnr.IsDownloadActiveXEnabled(id))');
            WL('     || (blnPic && !Slpnr.IsPictureEnabled(id)) || (blnSou && !Slpnr.IsSoundEnabled(id))');
            WL('     || (blnVid && !Slpnr.IsVideoEnabled(id))){');
            WL('        Slpnr.SetSecurity(id, blnScr, blnJav, blnAct, blnAdl, blnPic, blnSou, blnVid);');
            WL('    }');
            WL('');
            WL('    // ドキュメント取得を待つ。');
            WL('    t = 0;');
            WL('    do {');
            WL('        WScript.Sleep(500);');
            WL('        t += 500;');
            WL('    } while ((document = Slpnr.GetDocumentObject(id)) == null && (t < (timeout * 1000)));');
            WL('    if (t >= (timeout * 1000)){');
            WL('        Quit();');
            WL('        return false;');
            WL('    }');
            if (P.MainSyntax){
                WL('    var WaitMainFrame = true;');
                WL('    do {');
                WL('        try {');
                WL('            if (document' + P.MainSyntax + ' != null){');
                WL('                WaitMainFrame = false;');
                WL('            }');
                WL('        }');
                WL('        catch(error){');
                WL('        }');
                WL('        finally {');
                WL('            WScript.Sleep(500);');
                WL('            t += 500;');
                WL('        }');
                WL('    } while (WaitMainFrame && t < (timeout * 1000));');
                WL('    if (t >= (timeout * 1000)){');
                WL('        Quit();');
                WL('        return false;');
                WL('    }');
                WL('    else if (document' + P.MainSyntax + '.URL != LoginURL){');
                WL('        document' + P.MainSyntax + '.parentWindow.location.href = LoginURL;');
                WL('        do {');
                WL('            WScript.Sleep(500);');
                WL('            t += 500;');
                WL('        } while (document' + P.MainSyntax + ' == null && t < (timeout * 1000));');
                WL('        if (t >= (timeout * 1000)){');
                WL('            Quit();');
                WL('            return false;');
                WL('        }');
                WL('    }');
            }
            if (P.MainSyntax != P.SubmitSyntax){
                WL('    var WaitSubmitFrame = true;');
                WL('    do {');
                WL('        try {');
                WL('            if (document' + P.SubmitSyntax + ' != null){');
                WL('                WaitSubmitFrame = false;');
                WL('            }');
                WL('        }');
                WL('        catch(error){');
                WL('        }');
                WL('        finally {');
                WL('            WScript.Sleep(500);');
                WL('            t += 500;');
                WL('        }');
                WL('    } while (WaitSubmitFrame && t < (timeout * 1000));');
                WL('    if (t >= (timeout * 1000)){');
                WL('        Quit();');
                WL('        return false;');
                WL('    }');
                WL('    else if (document' + P.SubmitSyntax + '.URL != SubmitURL){');
                WL('        document' + P.SubmitSyntax + '.parentWindow.location.href = SubmitURL;');
                WL('        do {');
                WL('            WScript.Sleep(500);');
                WL('            t += 500;');
                WL('        } while (document' + P.SubmitSyntax + ' == null && t < (timeout * 1000));');
                WL('        if (t >= (timeout * 1000)){');
                WL('            Quit();');
                WL('            return false;');
                WL('        }');
                WL('    }');
            }
            WL('');
        }
        WL('    window = document.parentWindow;');
        WL('');
        if (P.IsSH){
            for (i = 0; i < P.AcntNm.length; i++){
                WL('    account_' + i + '  = Slpnr.GetProfileStringCipher("AutoLogin_" + loginPage, "Account_' + i + '", "");');
            }
            for (i = 0; i < P.PassNm.length; i++){
                WL('    password_' + i + ' = Slpnr.GetProfileStringCipher("AutoLogin_" + loginPage, "Password_' + i + '", "");');
            }
        }
        else {
            WL('    if (!resetIniData){');
            WL('        // 設定を読み込む。');
            for (i = 0; i < P.AcntNm.length; i++){
                WL('        account_' + i + '  = Slpnr.GetProfileStringCipher("AutoLogin_" + loginPage, "Account_' + i + '", "");');
            }
            for (i = 0; i < P.PassNm.length; i++){
                WL('        password_' + i + ' = Slpnr.GetProfileStringCipher("AutoLogin_" + loginPage, "Password_' + i + '", "");');
            }
            WL('    }');
        }
        WL('');
        WL('    // ユーザーから入力を促す。');
        for (i = 0; i < P.AcntNm.length; i++){
            WL('    if (account_' + i + ' == "") {');
            WL('        account_' + i + ' = window.prompt(accountPromptName_' + i + ' + "を入力して下さい(値はScript.ini に保存されます)。", "");');
            WL('        if (account_' + i + ' == null){');
            WL('            account_' + i + ' = "";');
            WL('        }');
            WL('        else {');
            WL('            account_' + i + ' = String(account_' + i + '.match(/^[^\\x00]*/));');
            WL('        }');
            WL('        Slpnr.WriteProfileStringCipher("AutoLogin_" + loginPage, "Account_' + i + '", account_' + i + ');');
            WL('    }');
        }
        WL('    if (savePassword){');
        for (i = 0; i < P.PassNm.length; i++){
            WL('        if (password_' + i + ' == ""){');
            WL('            try {');
            WL('                password_' + i + ' = Slpnr.MaskedInputBox(passwordPromptName_' + i + ' + "を入力してください(値は Script.ini に保存されます)。", "");');
            WL('            }');
            WL('            catch(error){');
            WL('                password_' + i + ' = window.prompt(passwordPromptName_' + i + ' + "を入力してください(値は Script.ini に保存されます)。", "");');
            WL('            }');
            WL('            finally {');
            WL('                if (password_' + i + ' == null){');
            WL('                    password_' + i + ' = "";');
            WL('                }');
            WL('                else {');
            WL('                    password_' + i + ' = String(password_' + i + '.match(/^[^\\x00]*/));');
            WL('                }');
            WL('                Slpnr.WriteProfileStringCipher("AutoLogin_" + loginPage, "Password_' + i + '", password_' + i + ');');
            WL('            }');
            WL('        }');
        }
        WL('    }');
        WL('    else{');
        for (i = 0; i < P.PassNm.length; i++){
            WL('        if (password_' + i + ' != ""' + (P.IsSH?'':' || resetIniData') + '){');
            WL('            if (window.confirm("Script.ini にこのページのパスワードが保存されている場合、削除します。\\n" +');
            WL('                               "よろしいですか?(OK:削除する、キャンセル:削除しない)")){');
            WL('                try {');
            WL('                    Slpnr.DeleteProfileKey("AutoLogin_" + loginPage, "Password_' + i + '");');
            WL('                }');
            WL('                catch(error){');
            WL('                    Slpnr.WriteProfileString("AutoLogin_" + loginPage, "Password_' + i + '", "");');
            WL('                }');
            WL('            }');
            WL('        }');
            WL('        try {');
            WL('            password_' + i + ' = Slpnr.MaskedInputBox(passwordPromptName_' + i + ' + "を入力してください", "");');
            WL('        }');
            WL('        catch(error){');
            WL('            password_' + i + ' = window.prompt(passwordPromptName_' + i + ' + "を入力してください", "");');
            WL('        }');
            WL('        finally {');
            WL('            if (password_' + i + ' == null){');
            WL('                password_' + i + ' = "";');
            WL('            }');
            WL('            else {');
            WL('                password_' + i + ' = String(password_' + i + '.match(/^[^\\x00]*/));');
            WL('            }');
            WL('        }');
        }
        WL('    }');
        WL('');
        if (!P.IsSH){
            WL('    while (!DoLogin(document)){');
            WL('        if ((t > (timeout * 1000)) || Slpnr.GetDocumentObject(id) == null){');
            WL('            Slpnr.MessageBox("AutoLogin Error : ' + P.ScriptTitle + '.js\\nログインできませんでした。");');
            WL('            break;');
            WL('        }');
            WL('        WScript.Sleep(500);');
            WL('        t += 500;');
            WL('    }');
        }
        else {
            WL('    if (!DoLogin(document)){');
            WL('            sleipnir.Echo("AutoLogin Error : ' + P.ScriptTitle + '.user.js");');
            if (P.IsLogin){
                WL('            sleipnir.Echo("    ログインできませんでした。");');
            }
            else {
                WL('            sleipnir.Echo("    フォームにアクセスできませんでした。");');
            }
            WL('    }');
        }
        WL('}');
        WL('');
        WL('function DoLogin(objDoc){');
        WL('    var document = objDoc;');
        WL('    try {');
        if (P.MainSyntax){
            WL('        document = objDoc' + P.MainSyntax + ';');
        }
        for (i = 0; i < P.AcntNm.length; i++){
            WL('        document.forms(formNumber).elements(accountTag_' + i + ').value = account_' + i + ';');
        }
        for (i = 0; i < P.PassNm.length; i++){
            WL('        document.forms(formNumber).elements(passwordTag_' + i + ').value = password_' + i + ';');
        }
        for (i = 0; i < P.ChkTrue.length; i++){
            WL('        document.forms(formNumber).elements(checkTag_' + i + ').checked = true;');
        }
        for (i = 0; i < P.ChkFalse.length; i++){
            WL('        document.forms(formNumber).elements(uncheckTag_' + i + ').checked = false;');
        }
        for (i = 0; i < P.SelNm.length; i++){
            WL('        document.forms(formNumber).elements(selTag_' + i + ').selectedIndex = selindex_' + i + ';');
        }
        if (P.MainSyntax != P.SubmitSyntax){
            WL('        document = objDoc' + P.SubmitSyntax + ";");
        }
        if (P.IsSH){
            WL('        if (Slpnr.CtrlDown){');
            WL('            sleipnir.beep();');
            WL('        }');
            WL('        else {');
            WL('            document.all.tags(submitTag).item(submitNumber).' + (P.IsLogin?'click':'focus') + '();');
            WL('        }');
        }
        else {
            WL('        document.all.tags(submitTag).item(submitNumber).click();');
        }
        WL('        return true;');
        WL('    }');
        WL('    catch(error){');
        WL('        return false;');
        WL('    }');
        WL('}');
        if (!P.IsSH){
            WL('');
            WL('function Quit(){');
            WL('    Slpnr.MessageBox("AutoLogin Error : ' + P.ScriptTitle + '.js\\nタイムアウトしました。");');
            WL('}');
        }
        function WL(str){
            objFile.WriteLine(str);
        }
    }
    catch(error){
        throw (new Error(error.number, "writeScript -> " + error.description));
    }
    finally {
        if (objFile){
            objFile.Close();
            objFile = null;
        }
    }
}

function showEndDlg(){
    var strMsg = "スクリプト作成終了。" + (P.IsSH?"\\plugins\\seahorse\\に":"指定フォルダに");
    strMsg += P.ScriptTitle + (P.IsSH?'.user':'') + ".jsを作成しました。";
    try {
        if (Slpnr.Version < 200){
            try {
                    Slpnr.ExecCommand(33201);
                }
            catch(error){
                strMsg += "\n(スクリプトの再読み込みを実行してください。)";
            }
        }
        else {
            if (P.IsSH){
                strMsg += "\n(Sleipnir オプション > 拡張機能 > SeaHorse にて、再読み込みを実行してください。)";
            }
            else {
                try {
                    Slpnr.ExecuteAction("ReloadScript");
                }
                catch(error){
                    strMsg += "\n(スクリプトの再読み込みを実行してください。)";
                }
            }
        }
        showDlg(strMsg);
    }
    catch(error){
        throw (new Error(error.number, "showEndDlg -> " + error.description));
    }
}

function showDlg(){
    var strMsg = "";
    var lngPrm = 0;
    var lngRet = null;
    switch(arguments.length){
        case 1:
        strMsg = arguments[0];
        lngPrm = 0 + 64;
        break;
        case 2:
        strMsg = arguments[0];
        lngPrm = arguments[1];
        break;
    }
    try {
        lngRet = Slpnr.MsgBox(strMsg, MyTitle, lngPrm);
        return ((lngRet == 1) || (lngRet == 6));
    }
    catch (error){
        var window;
        if (arguments.length == 1){
            return (Slpnr.MessageBox(strMsg));
        }
        try {
            window = Slpnr.GetWindowObject(id);
            return (window.confirm(strMsg));
        }
        catch(error){
            throw (new Error(error.number, "showDlg -> " + error.description));
        }
        finally {
            window = null;
        }
    }
}

function inputDlg(strMsg, strDef){
    var strRet, window;
    try {
        window = Slpnr.GetWindowObject(id);
        if ((strRet = window.prompt(strMsg, strDef))){
            strRet = String(strRet.match(/^[^\x00]*/));
        }
        return strRet;
    }
    catch(error){
        try {
            strRet = Slpnr.InputBox(strMsg, strDef);
            if (!Slpnr.Result){
                strRet = null;
            }
            return strRet;
        }
        catch(error){
            throw (new Error(error.number, "inputDlg -> " + error.description));
        }
    }
    finally {
        window = null;
    }
}

function showErrDlg(lngErr, strErr){
    var strMsg = "Error:\n";
    var lngPrm = 48;
    if (!lngErr){
        strMsg = "";
    }
    else if (lngErr == 1){
        strMsg = "スクリプト作成失敗\n";
    }
    else {
        lngPrm = 16;
    }
    showDlg(strMsg + strErr, lngPrm);
}

function replaceSectionName(){
    if (!this){
        return "";
    }
    else {
        return (this.replace(/\W/g, ""));
    }
}

function replaceFileName(){
    var str = this;
    var blnMode = false;
    switch(arguments.length){
        case 1:
        blnMode = arguments[0];
        break;
    }
    if (!str){
        return "";
    }
    else {
        str = str.replace(/\\/g, "¥");
        str = str.replace(/\"/g, "”");
        str = str.replace(/:/g, ":");
        str = str.replace(/,/g, ",");
        str = str.replace(/;/g, ";");
        str = str.replace(/\./g, ".");
        str = str.replace(/\*/g, "*");
        str = str.replace(/\?/g, "?");
        str = str.replace(/</g, "<");
        str = str.replace(/>/g, ">");
        str = str.replace(/\|/g, "|");
        str = str.replace(/\//g, "/");
        str = str.replace(/[\s\f\n\r\t\v]/g, "_");
        if (blnMode && (this != str)){
            showDlg("ファイル名に使用できない文字は変換されました。");
        }
        return str;
    }
}

function Trim(){
    if (!this){
        return "";
    }
    else {
        return (this.replace(/^[\s\u3000]+/, "").replace(/[\s\u3000]+$/, ""));
    }
}

function AutoLoginParam(){
    this.IsSH = false;
    this.IsLogin = false;
    this.ScriptPath = "";
    this.ScriptTitle = "";
    this.SavePassword = false;
    this.PageTitle = "";
    this.PageURL = "";
    this.LoginURL = "";
    this.SubmitURL = "";
    this.IniSection = "";
    this.MainSyntax = "";
    this.SubmitSyntax = "";
    this.AcntNm = new Array();
    this.AcntValue = new Array();
    this.PassNm = new Array();
    this.PassValue = new Array();
    this.ChkTrue = new Array();
    this.ChkFalse = new Array();
    this.SelNm = new Array();
    this.SelIndex = new Array();
    this.FormNm = 0;
    this.FormAct = "";
    this.SubmitTag = "";
    this.SubmitNm = 0;
    AutoLoginParam.prototype.ScriptFullName = getFullName;

    function getFullName(){
        return (this.ScriptPath + "\\" + this.ScriptTitle + (P.IsSH?'.user':'') + ".js");
    }
}

/* ActiveDocumentClass */
function ActiveDocument(){
    this.self = null;
    this.elementSyntax = "";
    ActiveDocument.prototype.getDocument = GetDocument;

    function GetDocument(objDoc){
        var strSyntax = "";
        try {
            while (objDoc.activeElement.tagName.match(/FRAME$/i)){
                for (i = 0; i < objDoc.all.tags(objDoc.activeElement.tagName).length; i++){
                    if (objDoc.activeElement == objDoc.all.tags(objDoc.activeElement.tagName).item(i)){
                        strSyntax += (".frames.item(" + i + ").document");
                    }
                }
                objDoc = objDoc.activeElement.contentWindow.document;
            }
            return true;
        }
        catch(error) {
            return false;
        }
        finally {
            this.self = objDoc;
            this.elementSyntax = strSyntax;
        }
    }
}

/* Method GetParentActiveElement */
function GetParentActiveElement(strTag){
    var obj = this.self.activeElement;
    try {
        while (obj.tagName != strTag){
            obj = obj.parentElement;
        }
    }
    catch(error){
        obj = null;
    }
    finally {
        return obj;
    }
}

- 関連一覧ツリー (★ をクリックするとツリー全体を一括表示します)

- AutoLoginCreator.js 【1.xx互換スクリプト】 - sleepy(webmaster) 10/07-22:37 No.2


- Web Forum -   Modified by isso