「テキストブラウザ」の版間の差分

提供: MeryWiki
ナビゲーションに移動 検索に移動
MSY-07 (トーク | 投稿記録)
省略された波括弧の追加
MSY-07 (トーク | 投稿記録)
スペースからタブに変更
16行目: 16行目:


function getTypeName(arg1) {
function getTypeName(arg1) {
    return sc.Run("GetTypeName", arg1);
return sc.Run("GetTypeName", arg1);
}
}


var s1 = document.selection.Text;
var s1 = document.selection.Text;
if (s1 == "") {
if (s1 == "") {
    var x = document.selection.GetActivePointX(mePosView);
var x = document.selection.GetActivePointX(mePosView);
    var y = document.selection.GetActivePointY(mePosView);
var y = document.selection.GetActivePointY(mePosView);
    document.selection.SelectWord();
document.selection.SelectWord();
    s1 = document.selection.Text;
s1 = document.selection.Text;
    document.selection.SetActivePoint(mePosView, x, y);
document.selection.SetActivePoint(mePosView, x, y);
}
}
if (s1.substr(0, 7) == "http://" || s1.substr(0, 8) == "https://") {
if (s1.substr(0, 7) == "http://" || s1.substr(0, 8) == "https://") {
    var o = new ActiveXObject("InternetExplorer.Application");
var o = new ActiveXObject("InternetExplorer.Application");
    if (o) {
if (o) {
        o.visible = false;
o.visible = false;
        o.navigate(s1);
o.navigate(s1);
        do {
do {
            Sleep(100);
Sleep(100);
        } while(o.Busy);
} while(o.Busy);
        var s2 = s1 + "\n";
var s2 = s1 + "\n";
        s2 = s2 + o.document.title + "\n";
s2 = s2 + o.document.title + "\n";
        s2 = s2 + "--------------------------------------------------------------------------------" + "\n";
s2 = s2 + "--------------------------------------------------------------------------------" + "\n";
        s2 = s2 + getHtml(o.document.body.childNodes, "");
s2 = s2 + getHtml(o.document.body.childNodes, "");
        document.selection.SelectAll();
document.selection.SelectAll();
        document.selection.Text = s2;
document.selection.Text = s2;
        document.selection.StartOfDocument();
document.selection.StartOfDocument();
    }
}
}
}


function getHtml(arg1, arg2) {
function getHtml(arg1, arg2) {
    var s = "";
var s = "";
    for (var i = 0; i < arg1.length; i++) {
for (var i = 0; i < arg1.length; i++) {
        var v = arg1[i];
var v = arg1[i];
        switch (getTypeName(v)) {
switch (getTypeName(v)) {
            case "HTMLBRElement":
case "HTMLBRElement":
                s = s + "\n" + arg2;
s = s + "\n" + arg2;
                break;
break;
            case "DispHTMLDOMTextNode":
case "DispHTMLDOMTextNode":
                var node;
var node;
                var prev_node;
var prev_node;
                node = v.data.replace(/^[ ]+|[ ]+$/g, '');
node = v.data.replace(/^[ ]+|[ ]+$/g, '');
                do {
do {
                    prev_node = node;
prev_node = node;
                    node = node.replace("  ", " ");
node = node.replace("  ", " ");
                } while(node != prev_node);
} while(node != prev_node);
                if (node != "") {
if (node != "") {
                    s = s + node;
s = s + node;
                }
}
                break;
break;
            case "HTMLAnchorElement":
case "HTMLAnchorElement":
                s = s + getHtml(v.childNodes, arg2);
s = s + getHtml(v.childNodes, arg2);
                s = s + "<\"" + v.href + "\">";
s = s + "<\"" + v.href + "\">";
                break;
break;
            default:
default:
                var temp = "";
var temp = "";
                switch (v.tagName) {
switch (v.tagName) {
                    case "P":
case "P":
                    case "DIV":
case "DIV":
                    case "TABLE":
case "TABLE":
                    case "TR":
case "TR":
                    case "H1":
case "H1":
                    case "H2":
case "H2":
                    case "H3":
case "H3":
                    case "H4":
case "H4":
                    case "H5":
case "H5":
                    case "H6":
case "H6":
                    case "H7":
case "H7":
                    case "UL":
case "UL":
                    case "OL":
case "OL":
                    case "SELECT":
case "SELECT":
                    case "TEXTAREA":
case "TEXTAREA":
                        temp = indent;
temp = indent;
                        s = s + "\n" + arg2 + temp;
s = s + "\n" + arg2 + temp;
                        break;
break;
                    case "TD":
case "TD":
                    case "LI":
case "LI":
                    case "OPTION":
case "OPTION":
                        s = s + "\n" + arg2;
s = s + "\n" + arg2;
                        break;
break;
                    default:
default:
                        break;
break;
                }
}
                s = s + getHtml(v.childNodes, arg2 + temp);
s = s + getHtml(v.childNodes, arg2 + temp);
                if (temp != "") {
if (temp != "") {
                    s = s + "\n" + arg2;
s = s + "\n" + arg2;
                }
}
                break;
break;
        }
}
    }
}
    return s;
return s;
}
}
</syntaxhighlight>
</syntaxhighlight>

2024年12月30日 (月) 00:31時点における版

URL の上にカーソルを置いて実行するとその内容をエディタ内に表示します。

// -----------------------------------------------------------------------------
// テキストブラウザ
//
// Copyright (c) Kuro. All Rights Reserved.
// www:    https://www.haijin-boys.com/
// -----------------------------------------------------------------------------

var indent = "\t";

var sc = new ActiveXObject("ScriptControl");
sc.Language = "VBScript";
sc.AddCode("Function GetTypeName(arg1) : GetTypeName = TypeName(arg1) : End Function");

function getTypeName(arg1) {
	return sc.Run("GetTypeName", arg1);
}

var s1 = document.selection.Text;
if (s1 == "") {
	var x = document.selection.GetActivePointX(mePosView);
	var y = document.selection.GetActivePointY(mePosView);
	document.selection.SelectWord();
	s1 = document.selection.Text;
	document.selection.SetActivePoint(mePosView, x, y);
}
if (s1.substr(0, 7) == "http://" || s1.substr(0, 8) == "https://") {
	var o = new ActiveXObject("InternetExplorer.Application");
	if (o) {
		o.visible = false;
		o.navigate(s1);
		do {
			Sleep(100);
		} while(o.Busy);
		var s2 = s1 + "\n";
		s2 = s2 + o.document.title + "\n";
		s2 = s2 + "--------------------------------------------------------------------------------" + "\n";
		s2 = s2 + getHtml(o.document.body.childNodes, "");
		document.selection.SelectAll();
		document.selection.Text = s2;
		document.selection.StartOfDocument();
	}
}

function getHtml(arg1, arg2) {
	var s = "";
	for (var i = 0; i < arg1.length; i++) {
		var v = arg1[i];
		switch (getTypeName(v)) {
			case "HTMLBRElement":
				s = s + "\n" + arg2;
				break;
			case "DispHTMLDOMTextNode":
				var node;
				var prev_node;
				node = v.data.replace(/^[ ]+|[ ]+$/g, '');
				do {
					prev_node = node;
					node = node.replace("  ", " ");
				} while(node != prev_node);
				if (node != "") {
					s = s + node;
				}
				break;
			case "HTMLAnchorElement":
				s = s + getHtml(v.childNodes, arg2);
				s = s + "<\"" + v.href + "\">";
				break;
			default:
				var temp = "";
				switch (v.tagName) {
					case "P":
					case "DIV":
					case "TABLE":
					case "TR":
					case "H1":
					case "H2":
					case "H3":
					case "H4":
					case "H5":
					case "H6":
					case "H7":
					case "UL":
					case "OL":
					case "SELECT":
					case "TEXTAREA":
						temp = indent;
						s = s + "\n" + arg2 + temp;
						break;
					case "TD":
					case "LI":
					case "OPTION":
						s = s + "\n" + arg2;
						break;
					default:
						break;
				}
				s = s + getHtml(v.childNodes, arg2 + temp);
				if (temp != "") {
					s = s + "\n" + arg2;
				}
				break;
		}
	}
	return s;
}
スポンサーリンク