<?xml version="1.0" encoding="Shift_JIS"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta name="generator" content="Hidemaru for Windows" />
<title>ExpContext</title>

<!-- スクリプト -->
<script type="text/jscript">
var ext;
if (window.opener)
        ext = window.opener.external.menuArguments;
else {
        window.alert("このファイルはIEのコンテキストメニュー拡張用のプログラムファイルです。\n直接開くことはできません。");
        document.write("<style type='text/css'>*{display:none;}<\/style>");
        window.opener = true;
        setTimeout("window.close()", 500);
}

function Coerce() {        //coerce
        if (!catchComplete())
                return;

        var s = "";
        var html, i;

        s +=
                "<link rel='stylesheet' type='text/css' href='coerce.css'>\n"+
                "<base href='" + ext.location.href + "'>\n"+
                "<body>\n";

        //フレーム有オプション
        var frm = ext.top.frames;
        var frmDoc = ext.top.document;
        if (frm.length) {
                //対象ページがShiftJISでなかった時の文字化け対策
                var msg = {
                        "このページにはフレームが使われています。":
                                "%u3053%u306E%u30DA%u30FC%u30B8%u306B%u306F%u30D5%u30EC%u30FC%u30E0%u304C%u4F7F%u308F%u308C%u3066%u3044%u307E%u3059%u3002",
                        "(<iframe>が含まれています)":
                                "%uFF08%26lt%3Biframe%26gt%3B%u304C%u542B%u307E%u308C%u3066%u3044%u307E%u3059%uFF09",
                        "(フレーム名:":
                                "%28%u30D5%u30EC%u30FC%u30E0%u540D%uFF1A",
                        "なし":
                                "%u306A%u3057",
                        "<noframes>の内容":
                                "%26lt%3Bnoframes%26gt%3B%u306E%u5185%u5BB9"
                }
                for (i in msg)
                        msg[i] = unescape(msg[i]);

                s += "<div>";
                s += "<strong style='color:red'>" + msg["このページにはフレームが使われています。"];

                if (frmDoc.getElementsByTagName("iframe").length)
                        s += msg["(<iframe>が含まれています)"];

                s += "<\/strong><br>\n";

                for (i = 0; i < frm.length; i++)
                        s += "<a href='" + frm[i].location.href + "'>" + frm[i].location.href + msg["(フレーム名:"] + (frm[i].name ? frm[i].name : msg["なし"]) + ")<\/a><br>\n";

                html = frmDoc.body.innerHTML;
                if (frmDoc.getElementsByTagName("noframes").length) {
                        s += "<p><strong style='color:red'>" + msg["<noframes>の内容"] + "<\/strong><\/p>\n";
                        s += html.replace(/<noframes/gi, "<Xnoframes");
                }
                s += "<hr style='margin-bottom:5em;'>\n";
                s += "<\/div>\n";
        }

        //ソース置換
        var regObj, rep = new Array(
                " style=",
                " bgcolor=",
                " background=",
                " onmouseout=",
                " onmouseover=",
                " onmousedown=",
                " onmouseup=",
                " onclick=",
                " onkeypress=",
                " onchange=",
                " onselect=",
                " onload=",
                " onunload=",
                " onabort=",
                " onerror=",
                " onfocus=",
                " onblur=",
                " onsubmit=",
                " onreset=",
                "<font",
                "<nobr"
        );
        html = ext.document.body.innerHTML;
        for (i = 0; i < rep.length; i++) {
                regObj = new RegExp(rep[i], "gi");
                html = html.replace(regObj, rep[i].charAt(0) + "X" + rep[i].substring(1, rep[i].length));
        }

        html = html.replace(/<script/gi, "<\!--<Xscript");
        html = html.replace(/\/\/.?--\>/gi, "//");
        html = html.replace(/<\/script>/gi, "<\/script>-->");
        html = html.replace(/<noscript/gi, "<span class='noscriptDecoration'><Xnoscript");
        html = html.replace(/<\/noscript>/gi, "<\/noscript><\/span>");

        s += html;

        s += "<\/body>";

        try { //IEが調子悪い時に起きる例外エラーへの対処
                var win = ext.open();
                with (win.document) {
                        open(); write(s); close(); title = ext.top.document.title;
                }
                win.focus();
                closeSelect();
        } catch(e) {
                errorMsg(e);
        }
}


var someWinObj;

function SomeWin() {        //ウィンドウ複製
        //未使用
        if (someWinObj) {
                //フレーム有オプション
                if (ext.top.frames.length) {
                        var frm = someWinObj.top.document.getElementsByTagName("frame");
                        for (i = 0; i < frm.length; i++) {
                                frm[i].src = ext.top.frames[i].location.href;
                        }
                }
                someWinObj.focus();
                window.close();

        } else if (catchComplete()) {
                try {
                        someWinObj = window.open(ext.top.location.href);
                        closeSelect();
                        //setTimeout("SomeWin()", 500); //windowオブジェクトが生成されるまでの時間稼ぎ
                } catch(e) {
                        errMsg(e);
                }
        }
}



function change(selThis) {        //サーバーチェンジ
        var svr = selThis.value;
        selThis.selectedIndex = 0;
        var l = ext.top.location, lh = l.host, p = l.href;

        if (p.match(/file:\/\/(|localhost)\//))
                p = unescape(p.replace(/file:\/\/(|localhost)\//, ""));

        if ((l.protocol == "file:" && p.substr(0,2) == svr) || lh == svr)
                return;
        else if (l.protocol == "file:")
                p = p.replace(p.substr(0,2), "http://" + svr);
        else
                p = p.replace("http://" + lh, svr);

        if (!p.match(/\.([sx]?html?|cgi)/)) {
                var a = new String(p.match(/[?#].+/)); //アンカー等を一時退避
                p = new String(p.match(/^[^?#]+/));
                try {
                        p += ext.document.getElementsByName("filename")[0].content;
                } catch (e) {
                        p += "index.html";
                }
                if (a)
                        p += a;
        }

        l.href = p;
        closeSelect();
}


function Explorer() {        //エクスプローラの起動
        var appObj = new ActiveXObject("Shell.Application");
        appObj.ShellExecute("explorer","F:\\");
        closeSelect();
}


function folderOpen() {        //このページのフォルダを開く
        var path = ext.location.href;
        if (ext.location.host.match(/(127\.0\.0\.1|cts\.velvet\.jp)/))
                path = path.replace(/http:\/\/(127\.0\.0\.1|cts\.velvet\.jp)/, "F:");
        else if (ext.location.protocol == "file:")
                path = path.replace("file:///", "");
        else
                return;

        path = path.replace(/\//g, "\\").replace(/[?#].+/, "");
        path = path.substring(0, path.lastIndexOf("\\"));

        (new ActiveXObject("Shell.Application")).ShellExecute("explorer", path);
        closeSelect();
}


function catchComplete() {        //オブジェクトの受け渡し
        return ext;
}


function closeSelect() {        //ウィンドウを閉じる
        if (document.all("close").checked)
                window.close();
}

function errorMsg(e) {        //エラーメッセージ
        alert("予期せぬ、あるいは不可抗力のエラーが発生しました。\n安全のためスクリプトの実行を中断します。\n\nError Name: " + e.name + "\nError Message: " + e.message + "\nError Number: " + e.number);
        window.close();
}
</script>

<!-- CSS -->
<style type="text/css">
BODY {
 margin:0px;
 background-color:#cec6b5;
 overflow:hidden;
}
P { margin:0.5em 0px;}
FIELDSET {
 margin:1em 0.5em;
 padding:1em;
 border-color:#ccb;
 text-align:center;
}
LEGEND {
 padding:3px 0.5em;
 border:1px solid #543;
 background-color:543; color:#cec6b5;
 font-size:24pt; font-family:"Century-Gothic", Verdana, Arial;
}
LABEL {
 font-size:9pt;
 cursor:hand;
}
INPUT.btn {
 width:100%;
 border-color:#ccb #543 #543 #ccb;
 background-color:#ccb; color:#513c27;
 font-size:10pt; font-family:sans-serif;
 cursor:hand;
}
SELECT {
 width:100%;
 background-color:#ccb; color:#513c27;
 font-size:10pt; font-family:sans-serif;
}
</style>
</head>



<body>



<!-- ボタン -->
<div>
        <fieldset>
                <legend>ExpContext</legend>
                <p><label for="close"><input id="close" type="checkbox" checked="checked" />選択したら閉じる</label></p>
                <p><input type="button" class="btn" onclick="Coerce()" value="Coerce" /></p>
                <p><input type="button" class="btn" onclick="SomeWin()" value="ウィンドウを複製" /></p>
                <p><input type="button" class="btn" onclick="Explorer()" value="エクスプローラ" /></p>
                <p><input type="button" class="btn" onclick="folderOpen()" value="このページのフォルダ" /></p>
                <p><select onchange="change(this)">
                        <option>サーバーチェンジ</option>
                        <option value="127.0.0.1">to http://127.0.0.1/</option>
                        <option value="cts.velvet.jp">to http://cts.velvet.jp/</option>
                        <option value="F:">to local</option>
                </select></p>
        </fieldset>
</div>



</body>
</html>