미디어위키:Common.js: 두 판 사이의 차이
둘러보기로 이동
검색으로 이동
백괴게임>Riemann 잔글편집 요약 없음 |
백괴게임>산천대국 시장 (반입님의 요청으로) |
||
427번째 줄: | 427번째 줄: | ||
/*</nowiki></source>*/ | /*</nowiki></source>*/ | ||
/** mediawiki api를 통해 간단하게 문서들을 수집, 변경하는 함수. | |||
* 플러그인 코어에서 사용하기 위해 만들었습니다. | |||
* 작성자: [[사용자:BANIP|BANIP]] | |||
*/ | |||
var token; | |||
var getToken = (function(){ | |||
$.ajax({ | |||
url:"/w/api.php?action=query&meta=tokens", | |||
success:function(v,i){ | |||
var datas = JSON.parse($(v).find("pre").text()); | |||
token = datas["query"]["tokens"]["csrftoken"]; | |||
}, | |||
async: false | |||
}) | |||
})(); | |||
function entityDecode(doc){ | |||
return $('<p></p>').html(doc).text(); | |||
} | |||
function changeDocument( title, summary, content, editToken ) { | |||
$.ajax({ | |||
url: mw.util.wikiScript("api"), | |||
data: { | |||
format: 'json', | |||
action: 'edit', | |||
title: title, | |||
summary: summary, | |||
text: content, | |||
token: editToken | |||
}, | |||
dataType: 'json', | |||
type: 'POST', | |||
success: function( data ) { | |||
if ( data && data.edit && data.edit.result == 'Success' ) { | |||
window.location.reload(); // reload page if edit was successful | |||
} else if ( data && data.error ) { | |||
alert( 'Error: API returned error code "' + data.error.code + '": ' + data.error.info ); | |||
} else { | |||
alert( 'Error: Unknown result from API.' ); | |||
} | |||
}, | |||
error: function( xhr ) { | |||
alert( 'Error: Request failed.' ); | |||
} | |||
}); | |||
} | |||
function addDocument( title, summary, content, editToken ){ | |||
originContent = getDocument(title) | |||
changeDocument( title, summary, originContent + content, editToken ); | |||
} | |||
function getDocument(title){ | |||
var originContent; | |||
$.ajax({ | |||
url:"/w/index.php?title=" + title + "&action=edit", | |||
success:function ajaxSucess(data){ | |||
originContent = $(data).find("textarea").html(); | |||
}, | |||
async: false | |||
}) | |||
return entityDecode(originContent); | |||
} | |||
function readDocument(title){ | |||
var doc; | |||
$.ajax({ | |||
url:"/wiki/" + title, | |||
success:function ajaxSucess(data){ | |||
doc = $(data).find("#mw-content-text"); | |||
}, | |||
async: false | |||
}) | |||
return doc; | |||
} | |||
/** 플러그인 틀을 사용할 수 있게 하는 함수. | |||
* 작성자: [[사용자:BANIP|BANIP]] | |||
*/ | |||
var commonjs = "사용자:" + mw.config.get("wgRelevantUserName") + "/common.js"; | |||
var plugins = {}, docPlugins = {}, uninstalledPlugins = {}, unupdatedPlugins = {}; | |||
var preloadedplugins = [], needPlugins = []; | |||
var jsdoc | |||
function removePluginByDoc(title,doc){ | |||
var reg = new RegExp("\\/\\*\\* 플러그인 "+title+"([\\s\\S]*)\\/\\* "+title+" 끝 \\*\\/","g"); | |||
doc = doc.replace(reg,""); | |||
return doc | |||
} | |||
var checkDocPlugin = (function(){ | |||
var plusSubTitle = "" | |||
$(".use-script").each(function(){ | |||
var plugin = { | |||
name : $(this).attr("data-name"), | |||
descript : $(this).attr("data-descript"), | |||
version : $(this).attr("data-version"), | |||
local : ($(this).attr("data-local") == "true") ? true : false, | |||
creat : $(this).attr("data-creat"), | |||
state : $(this).attr("data-state"), | |||
link : $(this).attr("data-link"), | |||
}; | |||
docPlugins[plugin.name] = plugin; | |||
plusSubTitle += ", " + $(this).attr("data-name"); | |||
}) | |||
if(plusSubTitle != ""){ | |||
plusSubTitle += " 플러그인 가동중"; | |||
$("#siteSub").text(function(i,v){return v + plusSubTitle}); | |||
} | |||
})(); | |||
var checkHavePlugin = (function(){ | |||
if(Object.keys(docPlugins).length >= 1){ | |||
jsdoc = getDocument(commonjs); | |||
var pluginreg = /plugins\.([a-zA-Z0-9_$]*)\s?\=\s?(\{.*\})\;/g; | |||
var nameMatch = pluginreg.exec(jsdoc); | |||
while(nameMatch){ | |||
preloadedplugins.push(JSON.parse( nameMatch[2] )); | |||
nameMatch = pluginreg.exec(jsdoc); | |||
} | |||
for(var keyD in docPlugins){ | |||
var docplugin = docPlugins[keyD]; | |||
var isHavePlugin = false; | |||
for(var keyM in preloadedplugins){ | |||
var myplugin = preloadedplugins[keyM] | |||
if(docplugin.name == myplugin.name){ | |||
if(docplugin.version != myplugin.version){ | |||
unupdatedPlugins[docplugin.name] = docplugin; | |||
} | |||
isHavePlugin = true; | |||
break; | |||
} | |||
} | |||
if(isHavePlugin == false){ | |||
uninstalledPlugins[docplugin.name] = docplugin; | |||
} | |||
} | |||
for(var key in uninstalledPlugins){ | |||
needPlugins.push( docPlugins[key].name ); | |||
} | |||
for(var key in unupdatedPlugins){ | |||
needPlugins.push( docPlugins[key].name ); | |||
} | |||
} | |||
})(); | |||
var checkinstalledPlugin = function(){ | |||
if( Object.keys(docPlugins).length >= 1 && (Object.keys(unupdatedPlugins).length >= 1 || Object.keys(uninstalledPlugins).length >= 1) ){ | |||
function appendBox(plugin,status){ | |||
var box = $(".cloneable.p-box").clone().removeClass("cloneable"); | |||
var code = readDocument( plugin.state ).find("pre.script").html(); | |||
docPlugins[plugin.name].code = code; | |||
box.find(".p-status").html(status); | |||
box.find(".p-code").html( code.replace(/\s{1,}$/,"") ); | |||
box.find(".p-name").text( plugin["name"] ); | |||
box.find(".p-descript").text( plugin["descript"] ); | |||
if(status == "버전업"){ | |||
var thisVersion; | |||
for(var key in preloadedplugins){ | |||
if (preloadedplugins[key].name == plugin["name"]){ | |||
thisVersion = preloadedplugins[key].version; | |||
} | |||
} | |||
box.find(".p-version").text( thisVersion + " => " + plugin["version"] ); | |||
} else { | |||
box.find(".p-version").text( plugin["version"] ); | |||
} | |||
box.find(".p-local").text( plugin["local"] == true ? "일부 문서만" : "문서 전체" ); | |||
box.find(".p-creat").text( plugin["creat"] ); | |||
$.ajax({ | |||
url:"/w/api.php?action=query&prop=revisions&rvdir=older&titles=" + plugin.state, | |||
success:function(v,i){ | |||
var datas = JSON.parse($(v).find("pre").text()); | |||
var titleKey = Object.keys(datas["query"]["pages"])[0]; | |||
var lastModified = datas["query"]["pages"][titleKey]["revisions"][0]["user"] +"(" + datas["query"]["pages"][titleKey]["revisions"][0]["timestamp"] + ")"; | |||
box.find(".p-last").text(lastModified); | |||
}, | |||
async: false | |||
}) | |||
$(".box-article").append(box); | |||
} | |||
var doc = $("#mw-content-text"); | |||
var setupMeta = readDocument("틀:플러그인/setup"); | |||
doc.html(setupMeta); | |||
for(var key in uninstalledPlugins){ | |||
appendBox(uninstalledPlugins[key],"설치"); | |||
} | |||
for(var key in unupdatedPlugins){ | |||
appendBox(unupdatedPlugins[key],"버전업"); | |||
} | |||
function installButtonClick(){ | |||
$(".install-button").text("설치중.."); | |||
$(".install-button").off("click"); | |||
function translateInstallPlugin(plugin){ | |||
var toJSONPlugin = Object.assign({}, plugin); | |||
toJSONPlugin.code = undefined; | |||
toJSONPlugin.link = undefined; | |||
var docHead = "", docFoot = ""; | |||
docHead += "/** 플러그인 " + plugin["name"] + "***************************\n"; | |||
docHead += "* " + plugin["descript"] + "\n"; | |||
docHead += "* 버전 => " + plugin["version"] + "\n"; | |||
docHead += "* 작성자 : [[사용자:" + plugin["creat"] + "|" + plugin["creat"] + "]] \n"; | |||
docHead += "*/ \n"; | |||
docHead += "plugins." + plugin["name"] + " = " + JSON.stringify(toJSONPlugin) + "; \n"; | |||
docHead += "var plugin_" + plugin["name"] + " = function(){\n"; | |||
docFoot += "\n}\n"; | |||
if(plugin.local){ | |||
docFoot += "if($(\"[data-name='" + plugin["name"] + "']\").length >= 1){\n"; | |||
docFoot += "plugin_" + plugin["name"] + "();\n"; | |||
docFoot += "}\n"; | |||
} else { | |||
docFoot += "plugin_" + plugin["name"] + "();\n"; | |||
} | |||
docFoot += "/* " + plugin["name"] + " 끝 */\n"; | |||
return entityDecode(docHead + plugin["code"] + docFoot); | |||
} | |||
var doc = ""; | |||
for(var key in needPlugins){ | |||
var pluginName = needPlugins[key]; | |||
var plugin = docPlugins[pluginName]; | |||
jsdoc = removePluginByDoc(pluginName,jsdoc); | |||
doc += translateInstallPlugin( plugin ); | |||
} | |||
changeDocument(commonjs,"플러그인 "+ needPlugins +"설치", jsdoc + doc, token); | |||
} | |||
$(".install-button").on("click",installButtonClick); | |||
} | |||
} | |||
if(Object.keys(docPlugins).length >= 1 && (Object.keys(unupdatedPlugins).length >= 1 || Object.keys(uninstalledPlugins).length >= 1)){ | |||
if($(".plugin-install").length >= 1){ | |||
$(".plugin-install").eq(0).closest("table").show(); | |||
$(".plugin-name").eq(0).text(needPlugins); | |||
$(".plugin-install").on("click",checkinstalledPlugin); | |||
} else { | |||
checkinstalledPlugin(); | |||
} | |||
} |
2017년 5월 20일 (토) 07:01 판
/* 이 자바스크립트 설정은 모든 문서, 모든 사용자에게 적용됩니다. */
/*<source lang="javascript"><nowiki>*/
/** [[틀:USERNAME]]에서 사용하는 바꿔치기 함수
* 작성자: [[사용자:Peremen|Peremen]]
*/
function UserNameReplace() {
if (typeof(disableUsernameReplace) != 'undefined' && disableUsernameReplace) return;
if (!document.getElementById('pt-userpage')) return;
$("span.insertusername").each(function(i) {
$(this).text(wgUserName)
})
};
$(UserNameReplace);
/** [[틀:제목]]에서 사용하는 제목 바꿔치기 함수
* 작성자: [[사용자:Peremen|Peremen]]
*/
function rewriteTitle() {
if (typeof(disableTitleRewrite) != 'undefined' && disableTitleRewrite) return;
if (!document.getElementById('title-meta')) return;
$('h1.firstHeading').each( function(i){
$(this).html( $("#title-meta").html()).css('text-align', $("#title-align").text())
})
}
$(rewriteTitle);
/* from en: */
var hasClass = (function () {
var reCache = {};
return function (element, className) {
return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
};
}
)();
/*
[[:en:Wikipedia:WikiProject User scripts/Scripts/Add edit section 0]]
[[위키백과:사랑방/2007년 1월#중국어판을 보니 section 0 편집 방법이 있더군요]]
*/
/* 영어 위키백과 버전 */
function addEditZero() {
var x;
if (!(x = document.getElementById('ca-edit') )) return;
var url;
if (!(url = x.getElementsByTagName('a')[0] )) return;
if (!(url = url.href )) return;
var y = addPortletLink('p-cactions', url+"§ion=0", '0', 'ca-edit-0',
'문서의 첫 부분만을 편집합니다.', '0', x.nextSibling);
y.className = x.className; // steal classes from the the edit tab...
x.className = 'istalk'; // ...and make the edit tab have no right margin
// exception: don't steal the "selected" class unless actually editing section 0:
if (/(^| )selected( |$)/.test(y.className)) {
if (!document.editform || !document.editform.wpSection
|| document.editform.wpSection.value != "0") {
y.className = y.className.replace(/(^| )selected( |$)/g, "$1");
x.className += ' selected';
}
}
}
$(addEditZero);
/* ([[위키백과:관리자 요청/2007년 5월#스크립트 추가 요청]]) */
/** Collapsible tables *********************************************************
*
* Description: Allows tables to be collapsed, showing only the header. See
* Wikipedia:NavFrame.
* Maintainers: User:R. Koot
*/
//var autoCollapse = 2;
//var collapseCaption = "hide";
//var expandCaption = "show";
function collapseTable( tableIndex ) {
var Button = document.getElementById( "collapseButton" + tableIndex );
var Table = document.getElementById( "collapsibleTable" + tableIndex );
if ( !Table || !Button ) {
return false;
}
var Rows = Table.getElementsByTagName( "tr" );
if ( Button.firstChild.data == collapseCaption ) {
for ( var i = 1; i < Rows.length; i++ ) {
Rows[i].style.display = "none";
}
Button.firstChild.data = expandCaption;
} else {
for ( var i = 1; i < Rows.length; i++ ) {
Rows[i].style.display = Rows[0].style.display;
}
Button.firstChild.data = collapseCaption;
}
}
function createCollapseButtons() {
var tableIndex = 0;
var NavigationBoxes = new Object();
var Tables = document.getElementsByTagName( "table" );
for ( var i = 0; i < Tables.length; i++ ) {
if ( hasClass( Tables[i], "collapsible" ) ) {
NavigationBoxes[ tableIndex ] = Tables[i];
Tables[i].setAttribute( "id", "collapsibleTable" + tableIndex );
var Button = document.createElement( "span" );
var ButtonLink = document.createElement( "a" );
var ButtonText = document.createTextNode( collapseCaption );
Button.style.styleFloat = "right";
Button.style.cssFloat = "right";
Button.style.fontWeight = "normal";
Button.style.textAlign = "right";
Button.style.width = "6em";
ButtonLink.setAttribute( "id", "collapseButton" + tableIndex );
ButtonLink.setAttribute( "href", "javascript:collapseTable(" + tableIndex + ");" );
ButtonLink.appendChild( ButtonText );
Button.appendChild( document.createTextNode( "[" ) );
Button.appendChild( ButtonLink );
Button.appendChild( document.createTextNode( "]" ) );
var Header = Tables[i].getElementsByTagName( "tr" )[0].getElementsByTagName( "th" )[0];
/* only add button and increment count if there is a header row to work with */
if (Header) {
Header.insertBefore( Button, Header.childNodes[0] );
tableIndex++;
}
}
}
for ( var i = 0; i < tableIndex; i++ ) {
if ( hasClass( NavigationBoxes[i], "collapsed" ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], "autocollapse" ) ) ) {
collapseTable( i );
}
}
}
$( createCollapseButtons );
/* ([[위키백과:관리자 요청/2007년 5월#스크립트 추가 요청]]) */
/** Dynamic Navigation Bars (experimental) *************************************
*
* Description: See [[:en:Wikipedia:NavFrame]].
* Maintainers: UNMAINTAINED
*/
// set up the words in your language
var autoCollapse = 2;
var collapseCaption = "숨기기";
var expandCaption = "보이기";
var NavigationBarHide = '[' + collapseCaption + ']';
var NavigationBarShow = '[' + expandCaption + ']';
// set up max count of Navigation Bars on page,
// if there are more, all will be hidden
// NavigationBarShowDefault = 0; // all bars will be hidden
// NavigationBarShowDefault = 1; // on pages with more than 1 bar all bars will be hidden
var NavigationBarShowDefault = autoCollapse;
// shows and hides content and picture (if available) of navigation bars
// Parameters:
// indexNavigationBar: the index of navigation bar to be toggled
function toggleNavigationBar(indexNavigationBar) {
var NavToggle = document.getElementById("NavToggle" + indexNavigationBar);
var NavFrame = document.getElementById("NavFrame" + indexNavigationBar);
if (!NavFrame || !NavToggle) {
return false;
}
// if shown now
if (NavToggle.firstChild.data == NavigationBarHide) {
for (
var NavChild = NavFrame.firstChild;
NavChild != null;
NavChild = NavChild.nextSibling
) {
if ( hasClass( NavChild, 'NavPic' ) ) {
NavChild.style.display = 'none';
}
if ( hasClass( NavChild, 'NavContent') ) {
NavChild.style.display = 'none';
}
}
NavToggle.firstChild.data = NavigationBarShow;
// if hidden now
} else if (NavToggle.firstChild.data == NavigationBarShow) {
for (
var NavChild = NavFrame.firstChild;
NavChild != null;
NavChild = NavChild.nextSibling
) {
if (hasClass(NavChild, 'NavPic')) {
NavChild.style.display = 'block';
}
if (hasClass(NavChild, 'NavContent')) {
NavChild.style.display = 'block';
}
}
NavToggle.firstChild.data = NavigationBarHide;
}
}
// adds show/hide-button to navigation bars
function createNavigationBarToggleButton() {
var indexNavigationBar = 0;
// iterate over all < div >-elements
var divs = document.getElementsByTagName("div");
for (var i=0;NavFrame = divs[i];i++) {
// if found a navigation bar
if (hasClass(NavFrame, "NavFrame")) {
indexNavigationBar++;
var NavToggle = document.createElement("a");
NavToggle.className = 'NavToggle';
NavToggle.setAttribute('id', 'NavToggle' + indexNavigationBar);
NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');');
var NavToggleText = document.createTextNode(NavigationBarHide);
NavToggle.appendChild(NavToggleText);
// Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked)
for (
var j=0;
j < NavFrame.childNodes.length;
j++
) {
if (hasClass(NavFrame.childNodes[j], "NavHead")) {
NavFrame.childNodes[j].appendChild(NavToggle);
}
}
NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar);
}
}
// if more Navigation Bars found than Default: hide all
if (NavigationBarShowDefault < indexNavigationBar) {
for (
var i=1;
i<=indexNavigationBar;
i++
) {
toggleNavigationBar(i);
}
}
}
$( createNavigationBarToggleButton );
/** 특집 게임에 별표를 붙이는 함수.
* 작성자: [[사용자:Peremen|Peremen]]
*/
function LinkFA() {
// iterate over all <span>-elements
$("span.FA").each(function(i, e) {
var a = e.id;
$("#p-lang li").each( function(j, k) {
if (k.className == "interwiki-"+a) {
k.className += " FA";
k.title = "이 게임은 특집 게임입니다.";
}
});
});
}
$(LinkFA);
/** 대문의 탭을 "프로젝트"->"대문"으로 바꾸는 함수.
* 작성자: [[사용자:Peremen|Peremen]]
*/
function MainPageRenameNamespaceTab() {
var title = mw.config.get( 'wgPageName' );
var hasMainPageTab = (title == '백괴게임:대문' || title == '백괴게임토론:대문');
if ( hasMainPageTab ){
$( '#ca-nstab-project a' ).text( "대문" );
}
var hasGameListTab = (title == '백괴게임:게임_목록' || title == '백괴게임토론:게임_목록');
if ( hasGameListTab ){
$( '#ca-nstab-project a' ).text( "게임 목록" );
}
$( '#ca-nstab-main a' ).text( "게임" );
}
$(MainPageRenameNamespaceTab);
/*
* @author [[User:Devunt]]
*/
addOnloadHook(function()
{
if (wgPageName!="백괴게임:낙서장")
return;
if (document.URL.lastIndexOf("action=edit") != -1)
{
if (document.URL.lastIndexOf("fakeaction=clean") == -1)
return;
var dbindex = document.editform.wpTextbox1;
dbindex.value = "{{이 줄은 지우지 마세요 (낙서장 안내문)}}";
document.editform.wpSummary.value = "낙서장 비움";
document.editform.wpSave.click();
return;
}
});
/** 임베드 플래시 무비 **************************************************
* 문서에 플래시 파일을 넣을 수 있게 합니다. 오직 현재 사용자 공간에서 활성화됩니다.
* [[틀:플래시]]를 참고하십시오.
* 작성자: [[:en:User:Olipro|Olipro]]
*/
var flashOk;
function embedFlashMovie( flashOk ) {
mainbody = document.getElementById( 'bodyContent' );
mainbody.innerHTML = contentTempHolder;
spancheck = document.getElementsByTagName( 'span' );
for( i = 0; i < spancheck.length; i++ ) {
if( spancheck[i].getAttribute( 'id' ) != 'embedFlashDoc' ) {
continue;
}
obj = spancheck[i].innerHTML.split( '@' );
flwidth = obj[0];
flheight = obj[1];
flfile = obj[2].replace( 'fullurl://', 'http://' );
showFlash = ' ';
if( flashOk ) {
showFlash = '<object width="' + flwidth + '" height="' + flheight + '"';
showFlash += 'classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"';
showFlash += 'codebase="http://fpdownload.macromedia.com/pub/';
showFlash += 'shockwave/cabs/flash/swflash.cab#version=8,0,0,0">';
showFlash += '<param name="movie" value="' + flfile + '" />';
showFlash += '<embed src="' + flfile + '" width="' + flwidth + '" height=';
showFlash += '"' + flheight + '" type="application/x-shockwave-flash" ';
showFlash += 'pluginspage="http://www.macromedia.com/go/getflashplayer" />';
showFlash += '</object>';
} else {
showFlash = '<a class="plainlinks" href="javascript:embedFlashMovie(true)" onClick="embedFlashMovie(true)">' + flfile + '</a> (신뢰하는 경우 보려면 클릭하십시오.)';
}
spancheck[i].innerHTML = showFlash;
spancheck[i].style.display = 'inline';
}
}
var contentTempHolder;
function embedFlashCheck() {
if( !document.getElementById( 'embedFlashDoc' ) ) {
return;
}
mainbody = document.getElementById( 'bodyContent' );
contentTempHolder = mainbody.innerHTML;
if( typeof displayFlashOverride != 'undefined' ) {
embedFlashMovie( displayFlashOverride );
return;
}
askmessage = '<div align="center" id="askflash">이 게임에는 ';
askmessage += '<a href="/wiki/백괴:플래시" class="plainlinks">플래시</a>가 들어있습니다.<br />';
askmessage += '컴퓨터에 해를 끼칠 수 있으므로 신뢰하는 경우에만 여십시오.<br />';
askmessage += '플래시가 포함된 게임을 보시겠습니까?<br /><b><a href="javascript:embedFlashMovie(true)" ';
askmessage += 'onClick="embedFlashMovie(true)">예</a> | <a ';
askmessage += 'href="javascript:embedFlashMovie(false)" ';
askmessage += 'onClick="embedFlashMovie(false)">아니오</a> | <a ';
askmessage += 'href="/index.php?title=User:' + wgUserName + '/' + skin + '.js&';
askmessage += 'action=edit§ion=new&preload=틀:플래시/비활성">';
askmessage += '이 메시지를 다시 표시하지 않음</a></b></div>';
mainbody.innerHTML = askmessage;
}
addOnloadHook( embedFlashCheck );
/** 좌측 사이드바의 리얼센스가 늘 보이게
* 작성자: [[사용자:devunt]]
*/
function showRealSense() {
$('#p-realsense')
.addClass('persistent')
.removeClass('collapsed')
.find('.body')
.hide()
.show();
}
$(showRealSense);
/* userAgent */
/** source: http://www.gregoryvarghese.com/how-to-get-browser-name-and-version-via-javascript/ **/
function get_browser_info(){
var ua=navigator.userAgent,tem,M=ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
if(/trident/i.test(M[1])){
tem=/\brv[ :]+(\d+)/g.exec(ua) || [];
return {name:'IE ',version:(tem[1]||'')};
}
if(M[1]==='Chrome'){
tem=ua.match(/\bOPR\/(\d+)/)
if(tem!=null) {return {name:'Opera', version:tem[1]};}
}
M=M[2]? [M[1], M[2]]: [navigator.appName, navigator.appVersion, '-?'];
if((tem=ua.match(/version\/(\d+)/i))!=null) {M.splice(1,1,tem[1]);}
return {
name: M[0],
version: M[1]
};
}
/** 白괴낚시는 파이어폭스 41.0 이상을 권장합니다. **/
if(document.getElementById("shiro").innerHTML !== false){
var browser=get_browser_info();
if((browser.name !== 'Firefox' || browser.version < 41) && browser.name !== 'Chrome' )
{
alert("사용하고 계시는 브라우저에서는 게임이 바르게 보이지 않을 수 있습니다.");
}
}
/*</nowiki></source>*/
/** mediawiki api를 통해 간단하게 문서들을 수집, 변경하는 함수.
* 플러그인 코어에서 사용하기 위해 만들었습니다.
* 작성자: [[사용자:BANIP|BANIP]]
*/
var token;
var getToken = (function(){
$.ajax({
url:"/w/api.php?action=query&meta=tokens",
success:function(v,i){
var datas = JSON.parse($(v).find("pre").text());
token = datas["query"]["tokens"]["csrftoken"];
},
async: false
})
})();
function entityDecode(doc){
return $('<p></p>').html(doc).text();
}
function changeDocument( title, summary, content, editToken ) {
$.ajax({
url: mw.util.wikiScript("api"),
data: {
format: 'json',
action: 'edit',
title: title,
summary: summary,
text: content,
token: editToken
},
dataType: 'json',
type: 'POST',
success: function( data ) {
if ( data && data.edit && data.edit.result == 'Success' ) {
window.location.reload(); // reload page if edit was successful
} else if ( data && data.error ) {
alert( 'Error: API returned error code "' + data.error.code + '": ' + data.error.info );
} else {
alert( 'Error: Unknown result from API.' );
}
},
error: function( xhr ) {
alert( 'Error: Request failed.' );
}
});
}
function addDocument( title, summary, content, editToken ){
originContent = getDocument(title)
changeDocument( title, summary, originContent + content, editToken );
}
function getDocument(title){
var originContent;
$.ajax({
url:"/w/index.php?title=" + title + "&action=edit",
success:function ajaxSucess(data){
originContent = $(data).find("textarea").html();
},
async: false
})
return entityDecode(originContent);
}
function readDocument(title){
var doc;
$.ajax({
url:"/wiki/" + title,
success:function ajaxSucess(data){
doc = $(data).find("#mw-content-text");
},
async: false
})
return doc;
}
/** 플러그인 틀을 사용할 수 있게 하는 함수.
* 작성자: [[사용자:BANIP|BANIP]]
*/
var commonjs = "사용자:" + mw.config.get("wgRelevantUserName") + "/common.js";
var plugins = {}, docPlugins = {}, uninstalledPlugins = {}, unupdatedPlugins = {};
var preloadedplugins = [], needPlugins = [];
var jsdoc
function removePluginByDoc(title,doc){
var reg = new RegExp("\\/\\*\\* 플러그인 "+title+"([\\s\\S]*)\\/\\* "+title+" 끝 \\*\\/","g");
doc = doc.replace(reg,"");
return doc
}
var checkDocPlugin = (function(){
var plusSubTitle = ""
$(".use-script").each(function(){
var plugin = {
name : $(this).attr("data-name"),
descript : $(this).attr("data-descript"),
version : $(this).attr("data-version"),
local : ($(this).attr("data-local") == "true") ? true : false,
creat : $(this).attr("data-creat"),
state : $(this).attr("data-state"),
link : $(this).attr("data-link"),
};
docPlugins[plugin.name] = plugin;
plusSubTitle += ", " + $(this).attr("data-name");
})
if(plusSubTitle != ""){
plusSubTitle += " 플러그인 가동중";
$("#siteSub").text(function(i,v){return v + plusSubTitle});
}
})();
var checkHavePlugin = (function(){
if(Object.keys(docPlugins).length >= 1){
jsdoc = getDocument(commonjs);
var pluginreg = /plugins\.([a-zA-Z0-9_$]*)\s?\=\s?(\{.*\})\;/g;
var nameMatch = pluginreg.exec(jsdoc);
while(nameMatch){
preloadedplugins.push(JSON.parse( nameMatch[2] ));
nameMatch = pluginreg.exec(jsdoc);
}
for(var keyD in docPlugins){
var docplugin = docPlugins[keyD];
var isHavePlugin = false;
for(var keyM in preloadedplugins){
var myplugin = preloadedplugins[keyM]
if(docplugin.name == myplugin.name){
if(docplugin.version != myplugin.version){
unupdatedPlugins[docplugin.name] = docplugin;
}
isHavePlugin = true;
break;
}
}
if(isHavePlugin == false){
uninstalledPlugins[docplugin.name] = docplugin;
}
}
for(var key in uninstalledPlugins){
needPlugins.push( docPlugins[key].name );
}
for(var key in unupdatedPlugins){
needPlugins.push( docPlugins[key].name );
}
}
})();
var checkinstalledPlugin = function(){
if( Object.keys(docPlugins).length >= 1 && (Object.keys(unupdatedPlugins).length >= 1 || Object.keys(uninstalledPlugins).length >= 1) ){
function appendBox(plugin,status){
var box = $(".cloneable.p-box").clone().removeClass("cloneable");
var code = readDocument( plugin.state ).find("pre.script").html();
docPlugins[plugin.name].code = code;
box.find(".p-status").html(status);
box.find(".p-code").html( code.replace(/\s{1,}$/,"") );
box.find(".p-name").text( plugin["name"] );
box.find(".p-descript").text( plugin["descript"] );
if(status == "버전업"){
var thisVersion;
for(var key in preloadedplugins){
if (preloadedplugins[key].name == plugin["name"]){
thisVersion = preloadedplugins[key].version;
}
}
box.find(".p-version").text( thisVersion + " => " + plugin["version"] );
} else {
box.find(".p-version").text( plugin["version"] );
}
box.find(".p-local").text( plugin["local"] == true ? "일부 문서만" : "문서 전체" );
box.find(".p-creat").text( plugin["creat"] );
$.ajax({
url:"/w/api.php?action=query&prop=revisions&rvdir=older&titles=" + plugin.state,
success:function(v,i){
var datas = JSON.parse($(v).find("pre").text());
var titleKey = Object.keys(datas["query"]["pages"])[0];
var lastModified = datas["query"]["pages"][titleKey]["revisions"][0]["user"] +"(" + datas["query"]["pages"][titleKey]["revisions"][0]["timestamp"] + ")";
box.find(".p-last").text(lastModified);
},
async: false
})
$(".box-article").append(box);
}
var doc = $("#mw-content-text");
var setupMeta = readDocument("틀:플러그인/setup");
doc.html(setupMeta);
for(var key in uninstalledPlugins){
appendBox(uninstalledPlugins[key],"설치");
}
for(var key in unupdatedPlugins){
appendBox(unupdatedPlugins[key],"버전업");
}
function installButtonClick(){
$(".install-button").text("설치중..");
$(".install-button").off("click");
function translateInstallPlugin(plugin){
var toJSONPlugin = Object.assign({}, plugin);
toJSONPlugin.code = undefined;
toJSONPlugin.link = undefined;
var docHead = "", docFoot = "";
docHead += "/** 플러그인 " + plugin["name"] + "***************************\n";
docHead += "* " + plugin["descript"] + "\n";
docHead += "* 버전 => " + plugin["version"] + "\n";
docHead += "* 작성자 : [[사용자:" + plugin["creat"] + "|" + plugin["creat"] + "]] \n";
docHead += "*/ \n";
docHead += "plugins." + plugin["name"] + " = " + JSON.stringify(toJSONPlugin) + "; \n";
docHead += "var plugin_" + plugin["name"] + " = function(){\n";
docFoot += "\n}\n";
if(plugin.local){
docFoot += "if($(\"[data-name='" + plugin["name"] + "']\").length >= 1){\n";
docFoot += "plugin_" + plugin["name"] + "();\n";
docFoot += "}\n";
} else {
docFoot += "plugin_" + plugin["name"] + "();\n";
}
docFoot += "/* " + plugin["name"] + " 끝 */\n";
return entityDecode(docHead + plugin["code"] + docFoot);
}
var doc = "";
for(var key in needPlugins){
var pluginName = needPlugins[key];
var plugin = docPlugins[pluginName];
jsdoc = removePluginByDoc(pluginName,jsdoc);
doc += translateInstallPlugin( plugin );
}
changeDocument(commonjs,"플러그인 "+ needPlugins +"설치", jsdoc + doc, token);
}
$(".install-button").on("click",installButtonClick);
}
}
if(Object.keys(docPlugins).length >= 1 && (Object.keys(unupdatedPlugins).length >= 1 || Object.keys(uninstalledPlugins).length >= 1)){
if($(".plugin-install").length >= 1){
$(".plugin-install").eq(0).closest("table").show();
$(".plugin-name").eq(0).text(needPlugins);
$(".plugin-install").on("click",checkinstalledPlugin);
} else {
checkinstalledPlugin();
}
}