MediaWiki:Common.js
注意: 保存後、変更を確認するにはブラウザーのキャッシュを消去する必要がある場合があります。
- Firefox / Safari: Shift を押しながら 再読み込み をクリックするか、Ctrl-F5 または Ctrl-R を押してください (Mac では ⌘-R)
- Google Chrome: Ctrl-Shift-R を押してください (Mac では ⌘-Shift-R)
- Internet Explorer / Microsoft Edge: Ctrl を押しながら 最新の情報に更新 をクリックするか、Ctrl-F5 を押してください
- Opera: Ctrl-F5を押してください
/* ここにあるすべてのJavaScriptは、すべてのページ読み込みですべての利用者に対して読み込まれます */
function my_switch(){
var uri = new URL(window.location.href);
var is_switched = uri.searchParams.get("nebula_switch") != null;
if (is_switched){
console.log("nebula_switch: 入れ替え後のページです");
var view_tab = document.getElementById("ca-view");
if (view_tab)
var is_view_mode = view_tab.classList.contains("selected");
else
var is_view_mode = false;
var is_not_ve_edit_mode = uri.searchParams.get("veaction") == null;
if (is_view_mode && is_not_ve_edit_mode){
console.log("nebula_switch: 閲覧モードです");
var switch_tag = document.getElementById("nebula_switch");
if (switch_tag){
var parser = new Parser(switch_tag); // 未定義
parser.parse();
if (parser.is_failed)
write_error("入れ替えタグが異常です。" + parser.failure_message);
// 未定義
}
else
console.log(
"nebula_switch: 入れ替えタグが見つかりませんでした"
);
}else
console.log(
"nebula_switch: 閲覧モードでないため、入れ替えは行いません"
);
}
}
// ECMAScript 5 の構文で書かなければならないため、
// class キーワードが使えない...
function Parser(switch_tag){
if (this === undefined)
throw new TypeError();
this.switch_tag = switch_tag;
}
Parser.prototype = {
constructor: Parser,
parse: function(){
var dom_parsed = (new DOMParser()).parseFromString(
"<root>" + this.switch_tag.innerText + "</root>",
"application/xml"
);
/*Array.from(dom_parsed.children[0].children).forEach(node=>{
[node.nodeName
});*/
this.is_failed = false;
}
};
my_switch();