사용자:백괴투/common.js
< 사용자:백괴투
참고: 설정을 저장한 후에 바뀐 점을 확인하기 위해서는 브라우저의 캐시를 새로 고쳐야 합니다.
- 파이어폭스 / 사파리: Shift 키를 누르면서 새로 고침을 클릭하거나, Ctrl-F5 또는 Ctrl-R을 입력 (Mac에서는 ⌘-R)
- 구글 크롬: Ctrl-Shift-R키를 입력 (Mac에서는 ⌘-Shift-R)
- 인터넷 익스플로러 / 엣지: Ctrl 키를 누르면서 새로 고침을 클릭하거나, Ctrl-F5를 입력.
- 오페라: Ctrl-F5를 입력.
/** 플러그인 uncytick***************************
* 게임 실행용 플러그인
* 버전 => 1.0.0
* 작성자 : [[사용자:BANIP|BANIP]]
* JSON => uncytick = {"name":"uncytick","descript":"게임 실행용 플러그인","version":"1.0.0","local":true,"creat":"BANIP","state":"사용자:BANIP/틱택토 live/플러그인","executable":true};
*/
function plugin_uncytick(){
if($("[data-name='uncytick']").length >= 1){
// 이부분에 코드 입력 //
jQuery.getScript("https://socket-io-chat.now.sh/socket.io/socket.io.js")
.done(function(){
var Socket = /** @class */ (function () {
function Socket(url, username) {
if (username === void 0) { username = Math.random().toString(); }
this.username = username;
this.socket = io(url);
this.defineJoin();
this.bindSocketListener();
}
Socket.prototype.defineJoin = function () {
this.socket.emit("join", { username: this.username });
};
Socket.prototype.bindSocketListener = function () {
var _this = this;
var socket = this.socket;
socket.on("newuser", function (_a) {
var username = _a.username;
Chat.server(username + "\uB2D8\uC774 \uB4E4\uC5B4\uC654\uC5B4\uC694.");
});
socket.on("passuser", function (_a) {
var username = _a.username;
Chat.server(username + "\uB2D8\uC774 \uB098\uAC14\uC5B4\uC694.");
});
socket.on("getuserlist", function (data) {
var buttonClickListener = function ($li, username, id) {
socket.emit("requestjoin", { targetId: id });
$(".activePull").removeClass();
$li.addClass("activePull");
Chat.server(username + "에게 게임신청을 했어요.");
};
var $lis = data
.map(function (userData) {
if (userData == null)
return;
var username = userData.username, id = userData.id;
var $li = $("<li />")
.text(username)
.data("id", id);
if (username != _this.username) {
var $button = $("<button>").text("게임 신청").addClass("btn-request");
$button.click(function () { return buttonClickListener($li, username, id); });
$li.append($button);
}
return $li;
});
$("#userlist").html($lis);
});
socket.on("servermessage", function (data) {
Chat.server(data.message);
});
socket.on("receivemessage", function (data) {
Chat.client(data.username, data.message);
});
socket.on("gamestart", function (_a) {
var enemyUsername = _a.enemyUsername;
var canStartGame = _this.game == undefined || _this.game.isGameEnd == true;
if (canStartGame) {
_this.game = new Game(socket, _this.username, enemyUsername);
}
else {
Chat.server(_this.game.enemyUsername + "\uACFC\uC758 \uAC8C\uC784\uC774 \uC544\uC9C1 \uB05D\uB098\uC9C0 \uC54A\uC558\uC5B4\uC694.");
}
});
};
return Socket;
}());
var Chat = /** @class */ (function () {
function Chat() {
}
Chat.server = function (message) {
var $li = $("<li></li>").text(message);
$("#messages").append($li);
Chat.moveBottom();
};
Chat.client = function (username, message) {
var $li = $("\n <li>\n <span class='username' /> : <span class='message'>\n </li>");
$li.find(".username").text(username);
$li.find(".message").text(message);
$("#messages").append($li);
Chat.moveBottom();
};
Chat.moveBottom = function () {
$("#messages").scrollTop($("#messages")[0].scrollHeight);
};
return Chat;
}());
var Game = /** @class */ (function () {
function Game(socket, username, ememyusername) {
this.socket = socket;
this.isGameEnd = false;
this.enemyUsername = ememyusername;
Chat.server(ememyusername + "과의 게임이 시작되었어요!");
$(".btn-request").fadeOut();
var bindClick = function ($target, axis) {
var x = axis[0], y = axis[1];
$target.text("H").click(function () {
console.log([x, y]);
socket.emit("draw", {
axis: [x, y]
});
});
};
$("#gamepan").slideDown().find("> div")
.each(function (x) {
$(this).find("> a").each(function (y) { bindClick($(this), [x, y]); });
});
this.bindSocketListener();
}
Game.prototype.bindSocketListener = function () {
var socket = this.socket;
var self = this;
socket.on("renewgamepan", function (_a) {
var gamepan = _a.gamepan;
gamepan.forEach(function (hori, x) {
return hori.forEach(function (cell, y) {
var textType = {
"1": "O",
"0": "H",
"-1": "X",
};
var text = textType[cell];
$("#gamepan").find("div").eq(x).find("a").eq(y)
.data("x", x).data("y", y)
.text(text);
console.log(x, y);
});
});
});
socket.on("gameend", function (_a) {
var state = _a.state;
var hideGamePan = function () { return $("#gamepan").slideUp(); };
var messageType = {
"win": "게임 승리!! 축하드려요!",
"lose": "윽... 져버렸네요...",
"draw": "비겼어요!",
};
var endMessage = messageType[state];
Chat.server(endMessage);
$(".btn-request").fadeIn();
setTimeout(hideGamePan, 3000);
self.isGameEnd = true;
self.removesocketListener();
});
};
Game.prototype.removesocketListener = function () {
$("#gamepan").find("a").off("click");
this.socket.off("gameend").off("renewgamepan");
};
return Game;
}());
var gamehtml = '<div id="gamepan"><div><a></a><a></a><a></a></div><div><a></a><a></a><a></a></div><div><a></a><a></a><a></a></div></div><div class="wrap"><ul id="userlist" class="scrollbox"></ul><ul id="messages" class="scrollbox"></ul><input id="chat" placeholder="메세지를 입력하세요..."/></div>';
$("#gamewindow").html(gamehtml);
var thisSocket = new Socket("https://banip.tk" + "/uncytt",mw.config.values.wgUserName);
$("#chat").keypress(function (e) {
if (e.key === "Enter" && $(this).val() != "") {
thisSocket.socket.emit("sendmessage", { message: $(this).val() });
$(this).val("");
}
});
});
// 여기까지 코드 입력 //
}
}
$( plugin_uncytick );
/* uncytick 끝 */
/** 플러그인 numbase***************************
* 숫자야구 remake
* 버전 => 1.41
* 작성자 : [[사용자:Riemann|Riemann]]
* JSON => numbase = {"name":"numbase","descript":"숫자야구 remake","version":"1.41","local":true,"creat":"Riemann","state":"사용자:Riemann/numbase","executable":true};
*/
function plugin_numbase(){
if($("[data-name='numbase']").length >= 1){
var title = mw.config.get('wgPageName');
if (title.slice( -1 ) == "4") {
var no = 4
}
else {
var no = 3
}
var trial = 0;
var d = new Date();
$("#sBtn").click(function(){
$("#description").css("display", "none");
$("#sBtn").css("display", "none");
$("#res").css("display", "table");
cpuNum = initNumbase();
document.getElementById('count').innerHTML = "시도 횟수: " + trial;
var bDate = d.getTime();
numGuess(bDate);
});
function initNumbase() {
var choice = "";
var initArray = [0,1,2,3,4,5,6,7,8,9];
var i, j;
for (i = 0; i < no; i++) {
j = Math.floor(Math.random() * initArray.length);
choice += initArray[j];
initArray.splice(j,1);
}
return choice;
}
function numGuess(bDate) {
document.getElementById('disp').style.display = 'table';
document.getElementById('numList').style.display = 'block';
var numb = document.getElementById('numList');
var numBlocks = "";
var disp = "";
document.getElementById('disp').innerHTML = disp;
for (i = 0; i < 10; i++) {
numBlocks += "<div id=\"numBlock" + i + "\" class=\"numBlock\">" + i + "</div>";
}
numBlocks += "<div id=\"numBlockC\" class=\"numBlockC\">C</div>";
numBlocks += "<div id=\"numBlockX\" class=\"numBlockC\">입력</div>";
numb.innerHTML = numBlocks;
function restrictLen(l,n) {
if (l.length < no) {
l += n;
} else {
alert(no + " 자리로 입력하세요.");
}
return l;
}
$("#numBlock0").click(function(){
disp = restrictLen(disp,0);
document.getElementById('disp').innerHTML = disp;
$("#numBlock0").css("display", "none");
});
$("#numBlock1").click(function(){
disp = restrictLen(disp,1);
document.getElementById('disp').innerHTML = disp;
$("#numBlock1").css("display", "none");
});
$("#numBlock2").click(function(){
disp = restrictLen(disp,2);
document.getElementById('disp').innerHTML = disp;
$("#numBlock2").css("display", "none");
});
$("#numBlock3").click(function(){
disp = restrictLen(disp,3);
document.getElementById('disp').innerHTML = disp;
$("#numBlock3").css("display", "none");
});
$("#numBlock4").click(function(){
disp = restrictLen(disp,4);
document.getElementById('disp').innerHTML = disp;
$("#numBlock4").css("display", "none");
});
$("#numBlock5").click(function(){
disp = restrictLen(disp,5);
document.getElementById('disp').innerHTML = disp;
$("#numBlock5").css("display", "none");
});
$("#numBlock6").click(function(){
disp = restrictLen(disp,6);
document.getElementById('disp').innerHTML = disp;
$("#numBlock6").css("display", "none");
});
$("#numBlock7").click(function(){
disp = restrictLen(disp,7);
document.getElementById('disp').innerHTML = disp;
$("#numBlock7").css("display", "none");
});
$("#numBlock8").click(function(){
disp = restrictLen(disp,8);
document.getElementById('disp').innerHTML = disp;
$("#numBlock8").css("display", "none");
});
$("#numBlock9").click(function(){
disp = restrictLen(disp,9);
document.getElementById('disp').innerHTML = disp;
$("#numBlock9").css("display", "none");
});
$("#numBlockC").click(function(){
disp = "";
document.getElementById('disp').innerHTML = disp;
$(".numBlock").css("display", "inline-flex");
});
$("#numBlockX").click(function(){
if (disp.length < no) {
alert(no + " 자리로 입력하세요.")
} else {
trial += 1
document.getElementById('count').innerHTML = "시도 횟수: " + trial;
v = valid(disp,cpuNum);
$("#res").append("<tr><td>" + trial + "</td><td>" + disp + "</td><td>" + v + "</td></tr>");
disp = "";
document.getElementById('disp').innerHTML = disp;
$(".numBlock").css("display", "inline-flex");
if ((v == "0B 3S" && no == 3) || (v == "0B 4S" && no == 4)) {
var dd = new Date();
var duration = Math.floor((dd.getTime() - bDate) / 1000);
document.getElementById('end').innerHTML = "축하합니다. 정수를 맞히셨습니다. " + trial + "회, " + duration + "초가 소비되었습니다. 이용해주셔서 감사합니다.";
$("#disp").css("display", "none");
$("#numList").css("display", "none");
$("#end").css("display", "inline");
return 0;
}
}
});
}
function valid(u,c) {
var b = 0;
var s = 0;
var bs;
for (i = 0; i < no; i++) {
for (j = 0; j < no; j++) {
if (u[i] == c[j]) {
if (i == j) {
s += 1;
}
else {
b += 1;
}
}
}
}
bs = "" + b + "B " + s + "S"
return bs;
}
}
}
$( plugin_numbase );
/* numbase 끝 */
/** 플러그인 msgame***************************
* 스톱워치 게임
* 버전 => 0.942
* 작성자 : [[사용자:Riemann|Riemann]]
* JSON => msgame = {"name":"msgame","descript":"스톱워치 게임","version":"0.942","local":true,"creat":"Riemann","state":"사용자:Riemann/msgame","executable":true};
*/
function plugin_msgame(){
if($("[data-name='msgame']").length >= 1){
// 이부분에 코드 입력 //
sc = 0
cb = 0
bl = false;
$(document.body).keydown(function() {
if (bl == false) {
bl = true
startF();
} else {
bl = false
stopF();
}
});
$("#msgame-start").click(function() {
bl = true
startF();
});
$("#msgame-stop").click(function() {
bl = false
stopF();
});
function startF() {
obj = Math.floor(Math.random() * 10) + 5;
$("#msgame-start").css("display", "none");
$("#msgame-stop").css("display", "block");
it = new Date();
si = setInterval(clockUpdate, 20)
$("#msgame-console").text(obj + " 초를 세세요.");
}
function stopF() {
$("#msgame-clockText").css("display", "inline");
$("#msgame-stop").css("display", "none");
$("#msgame-start").css("display", "block");
clearInterval(si);
ie = new Date();
ifin = ie - it;
$("#msgame-clockText").text(toMilliSec(ifin));
finished(obj, ifin);
}
function clockUpdate() {
ic = new Date();
id = ic - it;
ii = toMilliSec(id);
$("#msgame-clockText").text(ii);
if (obj * 1000 - id < 500 * cb && cb > 4 ) {
$("#msgame-clockText").fadeOut();
}
}
function toMilliSec(d) {
return (Math.floor(d / 1000) + "\"" + ("" + d % 1000).padStart(3, "0")).padStart(6, "0");
}
function finished(a, b) {
ath = a * 1000
if (ath == b) {
cbm = Math.floor(Math.pow(800, (1 + cb / 10)))
$("#msgame-console").text("정확하시군요. " + cbm + " 점 드리겠습니다.");
sc += cbm
cb += 1
} else if (Math.abs(ath - b) < 100) {
cbm = Math.floor(Math.pow((500 / Math.abs(ath - b)), (1 + cb / 10)))
$("#msgame-console").text("정확하시군요. " + cbm + " 점 드리겠습니다.");
sc += cbm
cb += 1
} else {
$("#msgame-console").text("안타깝습니다. 조금 더 노력해 보세요!");
cb = 0
}
$("#msgame-score").text(sc);
$("#msgame-combo").text(cb);
}
// 여기까지 코드 입력 //
}
}
$( plugin_msgame );
/* msgame 끝 */
/** 플러그인 inputform***************************
* (베타 테스트) 완전한 입력기를 구현합니다.
* 버전 => 1.6
* 작성자 : [[사용자:Gustmd7410|Gustmd7410]]
* JSON => inputform = {"name":"inputform","descript":"(베타 테스트) 완전한 입력기를 구현합니다.","version":"1.6","local":false,"creat":"Gustmd7410","state":"틀:입력 상자/플러그인","executable":true};
*/
function plugin_inputform(){
// 이부분에 코드 입력 //
mw.loader.using('oojs-ui-core').done(function () {
function toBool(value) {
switch (value) {
case undefined: return false;
case '': return true;
}
}
function toArray(value) {
if (value)
return value.split(' ');
else
return undefined;
}
function InpTable(table) {
this["case"] = {};
this["default"] = Object.assign({
prefix: '',
value: undefined,
suffix: '',
replace: [],
sub: [0]
}, table["default"]);
if (table["case"]) {
for (var value in table["case"]) {
this["case"][value] = Object.assign({}, this["default"], { value: this["default"].value || value }, table["case"][value]);
}
}
}
$('.input-form').each(function () {
var container = this;
$(this).html(new $('<form />', {
"class": $(this).data('class'),
id: $(this).data('id'),
style: $(this).data('style'),
'accept-charset': 'UTF-8',
autocomplete: toBool($(this).data('autocomplete')),
novalidate: toBool($(this).data('novalidate')),
html: $(this).html()
}));
$(this).children('form').submit(function (event) {
event.preventDefault();
var action = new URL('/w/index.php', location);
if (toBool($(container).data('pass')))
action.search = location.search;
if ($(container).data('get'))
new URLSearchParams($(container).data('get')).forEach(function (value, key) {
action.searchParams.set(key, value);
});
action.searchParams.set('title', $(container).data('title'));
$(this).children('.input-field').each(function () {
if (typeof ($(this).data('table')) == 'object') {
var name = $(this).data('name');
var rawval = $(this).find('input').val();
var table = new InpTable($(this).data('table'));
var cvttbl = table["case"][rawval] || table["default"];
var cvtval = (cvttbl.value || rawval).slice(cvttbl.sub[0], cvttbl.sub[1]);
cvttbl.replace.forEach(function (reparr) {
var regex = reparr[0].substr(1).split('/');
regex.pop();
regex = regex.join('/');
var flag = reparr[0].substr(1).split('/').reverse()[0];
cvtval = cvtval.replace(new RegExp(regex, flag), reparr[1]);
});
action.searchParams.set(name, cvttbl.prefix + cvtval + cvttbl.suffix);
}
else
action.searchParams.set($(this).data('name'), $(this).find('input').val());
});
location.href = action.href;
});
});
$('.input-field').each(function () {
$(this).html(new OO.ui.TextInputWidget({
accessKey: $(this).data('accessKey'),
autocomplete: toBool($(this).data('autocomplete')),
autofocus: toBool($(this).data('autofocus')),
classes: toArray($(this).data('classes')),
disabled: toBool($(this).data('disabled')),
flags: toArray($(this).data('flags')),
icon: $(this).data('icon'),
iconTitle: $(this).data('iconTitle'),
id: $(this).data('id'),
indicator: $(this).data('indicator'),
indicatorTitle: $(this).data('indicatorTitle'),
inputId: $(this).data('inputId'),
maxLength: Number($(this).data('maxLength')),
name: $(this).data('name'),
placeholder: $(this).data('placeholder'),
readOnly: toBool($(this).data('readOnly')),
required: toBool($(this).data('required')),
spellcheck: toBool($(this).data('spellcheck')),
tabIndex: Number($(this).data('tabIndex')),
text: $(this).data('text'),
title: $(this).data('title'),
type: $(this).data('type'),
validate: (function(container) {
if ($(container).data('validatetype') == 'RegExp') {
var value = $(container).data('validate').substr(1).split('/');
return RegExp(value[0], value[1]);
}
else
return $(container).data('validate');
})(this),
value: $(this).data('value')
}).$element);
if(toBool($(this).data('inline'))) $(this).find('*').css({
display: 'inline',
width: 'auto'
});
});
$('.input-button').each(function () {
$(this).html(new OO.ui.ButtonInputWidget({
accessKey: $(this).data('accessKey'),
classes: toArray($(this).data('classes')),
disabled: toBool($(this).data('disabled')),
flags: toArray($(this).data('flags')),
framed: toBool($(this).data('framed')),
icon: $(this).data('icon'),
iconTitle: $(this).data('iconTitle'),
id: $(this).data('id'),
indicator: $(this).data('indicator'),
indicatorTitle: $(this).data('indicatorTitle'),
inputId: $(this).data('inputId'),
label: $(this).data('label'),
name: $(this).data('name'),
tabIndex: Number($(this).data('tabIndex')),
text: $(this).data('text'),
title: $(this).data('title'),
type: $(this).data('type'),
value: $(this).data('value')
}).$element);
});
noPlugin('input');
});
// 여기까지 코드 입력 //
}
$( plugin_inputform );
/* inputform 끝 */