利用者:Ninomy/vector.js

出典: フリー教科書『ウィキブックス(Wikibooks)』

注意: 保存した後、ブラウザのキャッシュをクリアする必要があります。Mozilla / Firefox / Safari: [Shift] を押しながら [再読み込み] をクリック、または [Shift]-[Ctrl]-[R] (Macでは [Cmd]-[Shift]-[R]); IE: [Ctrl] を押しながら [更新] をクリック、または [Ctrl]-[F5]; Konqueror: [再読み込み] をクリック、または [F5]; Opera: 「ツール」→「設定」からキャッシュをクリア。

// This javascript prevents carelessly submission (hitting Enter at summary field).
// To enable, copy and paste this script to a subpage of your user page.
// 2004-07-30: New feature: Replace Fullwidth comma (U+FF0C) to Ideographic comma (U+3001)
//                          and Fullwidth full stop (U+FF0E) to Ideographic full stop (U+3002)
//             If you don't need this feature, use the past version.

// This script is under public domain, and comes with ABSOLUTELY NO WARRANTY.
// You can use/modify/redistribute without any permission.

var submitchecker_buttonclicked = false;
var confirm_prompt = "Textarea contains “\uFF0C”(U+FF0C) and/or “\uFF0E”(U+FF0E).\nReplace them?";
var confirm_result = null;

function install_submitchecker() {
  var f = document.getElementById("editform");
  if(f) {
    var inputs = f.getElementsByTagName("input");
    for(var i = 0; i < inputs.length; ++i)
      if(inputs[i].type == "submit")
        inputs[i].onclick = submitchecker_nocheck;
    f.onsubmit = submitchecker;
  }
}
function submitchecker() {
  var edit = document.getElementById("editform").getElementsByTagName("textarea")[0];
  if(edit && /[\uFF0C\uFF0E]/.test(edit.value)) {
    var r;
    if(window.execScript) {
      window.execScript(
        "confirm_result = MsgBox(confirm_prompt,vbYesNoCancel)",
        "VBScript");
      if(confirm_result == 2) return false;
      r = (confirm_result == 6);
    } else {
      r = prompt(confirm_prompt, "yes");
      if(!r) return false;
      r = /^[yY]/.test(r);
    }
    if(r) {
      edit.value = edit.value.replace(/\uFF0C/g, '\u3001').replace(/\uFF0E/g, '\u3002');
    }
  }
  if(submitchecker_buttonclicked) return true;
  return confirm("Are you sure you want to submit your changes?");
}
function submitchecker_nocheck(e) {
  if(e && e.target) {
    var name = e.target.name;
    if(name != "wpSave" && name != "wpPreview") return true;
  }
  submitchecker_buttonclicked = true;
  return true;
}
if(window.attachEvent) window.attachEvent("onload", install_submitchecker);
else if(window.addEventListener) window.addEventListener("load", install_submitchecker, false);

//log
function addlogtab()
{
  // get title from URL
  var u = location.href;
  if(/[\?&]title=([^&]+)/.test(u)) u = RegExp.$1;
  else if(/\/wiki\/([^\?]+)/.test(u)) u = RegExp.$1;
  else return;
  
  // insertion point of toolbox
  var lit = document.getElementById('t-recentchangeslinked');
  if(!lit) lit = document.getElementById('t-whatlinkshere');
  // if not found, we're in special page
  if(!lit) return;
  
  // insertion point of actions tab
  var act = document.getElementById('p-cactions');
  act = act.getElementsByTagName('ul')[0];
  
  // get namespace number
  var ns = document.body.className.split(' ');
  for(var i = 0; i < ns.length; ++i) {
    var r = /^ns-([0-9]+)$/.exec(ns[i]);
    if(r) { ns = parseInt(r[1]); break; }
  }
  if(typeof ns != 'number') return;
  
  // purge cache
  a = document.createElement('a');
  a.appendChild(document.createTextNode('Purge cache'));
  a.setAttribute('href', '/wiki/' + u + '?action=purge');
  a.setAttribute('title', decodeURI(u));
  li = document.createElement('li');
  li.appendChild(a);
  lit.parentNode.insertBefore(li, lit.nextSibling);
  
  // User: or User_talk:
  if(ns == 2 || ns == 3) {
    // strip subpage
    var user = decodeURI(u).replace(/^[^:]+:/, '').replace(/\/.*/, '');
    // User's log
    a = document.createElement('a');
    a.appendChild(document.createTextNode('User log'));
    a.setAttribute('href', '/wiki/Special:Log?user=' + encodeURI(user));
    a.setAttribute('title', 'User:' + user + "'s log");
    li = document.createElement('li');
    li.appendChild(a);
    lit.parentNode.insertBefore(li, lit.nextSibling);
    // IP address
    var m = /^\d+\.\d+\.\d+\.\d+$/.exec(user);
    if(m) {
      a = document.createElement('a');
      a.appendChild(document.createTextNode('whois'));
      a.setAttribute('href', 'http://linky.wikipedia.jp/whois?key=' + encodeURI(user));
      a.setAttribute('title', 'whois query for ' + user);
      li = document.createElement('li');
      li.appendChild(a);
      act.appendChild(li);
    }
  }
  
  // Page log
  a = document.createElement('a');
  a.appendChild(document.createTextNode('Page log'));
  a.setAttribute('href', '/wiki/Special:Log?page=' + u);
  a.setAttribute('title', decodeURI(u));
  li = document.createElement('li');
  li.appendChild(a);
  lit.parentNode.insertBefore(li, lit.nextSibling);
  
  // Image: or Image_talk:
  if((ns == 6 || ns == 7) && location.host != 'commons.wikimedia.org') {
    var img = u.replace(/^[^:]+:/, (ns == 6 ? 'Image:' : 'Image_talk:'));
    // link to commons
    a = document.createElement('a');
    a.appendChild(document.createTextNode('commons'));
    a.setAttribute('href', 'http://commons.wikimedia.org/wiki/' + img);
    a.setAttribute('title', 'commons:' + decodeURI(img));
    li = document.createElement('li');
    li.appendChild(a);
    act.appendChild(li);
  }
}
$(addlogtab);

// *** CUSTOMIZE SECTION
var logoutconfirm_message = "!!ATTENTION!!\nAre you sure you want to log out?";
// ***

function install_logoutconfirm() {
  var e = document.getElementById('pt-logout');
  e = e.getElementsByTagName('a')[0];
  if(e.addEventListener) e.addEventListener("click", logoutconfirm, false);
  else if(e.attachEvent) e.attachEvent("onclick", logoutconfirm);
}
function logoutconfirm(e) {
  if(confirm(logoutconfirm_message)) return true;
  if(e.preventDefault) e.preventDefault();
  else if(window.event) event.returnValue = false;
  return false;
}
$(install_logoutconfirm);

// *** CUSTOMIZE SECTION
var useralert_message = 'ATTENTION: This page is user page. Are you sure you want to edit?';
// ***

$(function() {
  if(wgCanonicalNamespace != 'User') return;
  if(!document.getElementById('editform')) return;
  if(wgUserName == wgTitle.split('/')[0]) return;
  
  var div = document.createElement('div');
  div.setAttribute('class', 'usermessage');
  div.setAttribute('style', 'display:block');
  div.innerHTML = useralert_message;
  var s = document.getElementById('contentSub');
  s.parentNode.insertBefore(div, s.nextSibling);
});

//Welcome
$(function() {
  if(wgCanonicalNamespace != 'User_talk') return;
  if(!document.getElementById('editform')) return;
  
  var b = document.createElement('button');
  b.innerHTML = 'Welcome';
  b.setAttribute('type', 'button');
  b.onclick = function() {
    var e = document.getElementById('editform');
    if(e.wpTextbox1.value) e.wpTextbox1.value += "\n";
    e.wpTextbox1.value += "\u007B\u007Bsubst:ようこそ}}";
    e.wpSummary.value = 'ウィキブックスへようこそ';
    e.wpSave.focus();
  }
  var p = document.createElement('p');
  p.appendChild(b);
  var s = document.getElementById('contentSub');
  s.parentNode.insertBefore(p, s.nextSibling);
});

//Preview
$(function() {
  if(wgCanonicalNamespace != 'User_talk') return;
  if(!document.getElementById('editform')) return;
  
  var b = document.createElement('button');
  b.innerHTML = 'Preview';
  b.setAttribute('type', 'button');
  b.onclick = function() {
    var e = document.getElementById('editform');
    if(e.wpTextbox1.value) e.wpTextbox1.value += "\n";
    e.wpTextbox1.value += "\u007B\u007Bsubst:Preview}}";
    e.wpSummary.value = 'プレビュー機能のお知らせ';
    e.wpSave.focus();
  }
  var p = document.createElement('p');
  p.appendChild(b);
  var s = document.getElementById('contentSub');
  s.parentNode.insertBefore(p, s.nextSibling);
})

//一括
$(function() {
  if(wgCanonicalNamespace != 'User_talk') return;
  if(!document.getElementById('editform')) return;
  
  var b = document.createElement('button');
  b.innerHTML = '一括';
  b.setAttribute('type', 'button');
  b.onclick = function() {
    var e = document.getElementById('editform');
    if(e.wpTextbox1.value) e.wpTextbox1.value += "\n";
    e.wpTextbox1.value += "\u007B\u007Bsubst:一括}}";
    e.wpSummary.value = '一括投稿のお願い';
    e.wpSave.focus();
  }
  var p = document.createElement('p');
  p.appendChild(b);
  var s = document.getElementById('contentSub');
  s.parentNode.insertBefore(p, s.nextSibling);
})

// TeX入力支援 (originally made by Kanjy)
importScript("利用者:Ninomy/TeX.js");