User:Vanished user 1929210/test.js
Appearance
(Redirected from User:逆襲的天邪鬼/test.js)
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Vanished user 1929210/test. |
/**
* AceEditor 維基百科條目版
* Author: [[User:Vjudge1]]
*
* 已知bug:
* 1. 工具欄按鈕全部失效
* 2. 壓根就沒寫完
*
* 未與其他編輯器(wikEd等等)進行測試因此不知道是否兼容。
*/
(function() {
'use strict';
var $editorElem, editor;
var $textBox;
var aceMode = true;
function init() {
$textBox = $('#wpTextbox1');
// 建立一個與文本框同樣大小的div,並將文字放進去
$editorElem = $('<div id="wpEditor"></div>');
$editorElem.text($textBox.val());
$editorElem.height($textBox.height());
// 替換文本框
$textBox.before($editorElem);
editor = ace.edit('wpEditor');
editor.getSession().setUseWrapMode(true);
$editorElem = $('#wpEditor');
$editorElem.css('font', $('#wpTextbox1').css('font'));
function setAceVisible(value) {
if (value) {
$('#wikiEditor-ui-toolbar').hide();
$('#editpage-specialchars').hide();
$textBox.hide();
$editorElem.show();
editor.setValue($textBox.val());
editor.focus();
} else {
$('#wikiEditor-ui-toolbar').show();
$('#editpage-specialchars').show();
$textBox.show();
$editorElem.hide();
$textBox.focus();
}
}
setAceVisible(true);
// 添加切換按鈕
$('#mw-editpage-watch').after('<input name="wpAceEditor" type="checkbox" value="1" checked="checked" id="wpAceEditor"> <label for="wpAceEditor" id="mw-ace-editor">AceEditor</label>');
$('#wpAceEditor').click(function () {
setAceVisible(document.editform.wpAceEditor.checked);
});
// *** DEBUG ***
window.editor = editor;
aceMode = true;
// 保持同步
editor.getSession().on('change', function(e) {
$textBox.val(editor.getValue());
});
}
var wgAction = mw.config.get("wgAction");
var layoutEngine = $.client.profile().layout;
if ((wgAction == "edit" || wgAction == "submit") &&
mw.config.get("wgPageContentModel") == "wikitext" &&
layoutEngine != "trident" && layoutEngine != "edge") {
// 加載Ace
mw.loader.using('ext.codeEditor.ace', function () {
init();
config();
});
}
})();