사용자:Jinhoftyu/common.js
보이기
참고: 설정을 저장한 후에 바뀐 점을 확인하기 위해서는 브라우저의 캐시를 새로 고쳐야 합니다.
- 파이어폭스 / 사파리: Shift 키를 누르면서 새로 고침을 클릭하거나, Ctrl-F5 또는 Ctrl-R을 입력 (Mac에서는 ⌘-R)
- 구글 크롬: Ctrl-Shift-R키를 입력 (Mac에서는 ⌘-Shift-R)
- 엣지: Ctrl 키를 누르면서 새로 고침을 클릭하거나, Ctrl-F5를 입력.
/** 플러그인 p21***************************
* 블랙잭
* 버전 => 0.840a4
* 작성자 : [[사용자:Riemann|Riemann]]
* JSON => p21 = {"name":"p21","descript":"블랙잭","version":"0.840a4","local":true,"creat":"Riemann","state":"사용자:Riemann/p21","executable":true};
*/
function plugin_p21(){
if($("[data-name='p21']").length >= 1){
var title = mw.config.get('wgPageName');
if (title.slice( 1, 2 ) == "라") {
var blind = true;
var defa = 20;
} else {
var blind = false;
var defa = 10;
}
var mult = defa;
$("#multiplier").text(mult);
var coins = 100;
var wincount = 0;
var losecount = 0;
//$("#console").text("스코어: " + coins + "점");
$("#console").text("스코어: " + wincount + "승 " + losecount + "패");
$("#console").append("\n블랙잭에 오신 것을 환영합니다.");
const pcLst = [
0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAD,0xAE,
0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBD,0xBE,
0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCD,0xCE,
0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDD,0xDE];
const pointData = {a1:1,a2:2,a3:3,a4:4,a5:5,a6:6,a7:7,a8:8,a9:9,aa:10,ab:10,ad:10,ae:10,b1:1,b2:2,b3:3,b4:4,b5:5,b6:6,b7:7,b8:8,b9:9,ba:10,bb:10,bd:10,be:10,c1:1,c2:2,c3:3,c4:4,c5:5,c6:6,c7:7,c8:8,c9:9,ca:10,cb:10,cd:10,ce:10,d1:1,d2:2,d3:3,d4:4,d5:5,d6:6,d7:7,d8:8,d9:9,da:10,db:10,dd:10,de:10};
var pcSet = [];
function hexToChar(x) {
return String.fromCharCode(0xD83C) +String.fromCharCode(x + 0xDC00);
}
function hexToStr(x) {
return x.toString(16);
}
var dealerD, guestD;
$("#deal").click(function(){
//$("#console").text("스코어: " + coins + "점");
$("#console").text("스코어: " + wincount + "승 " + losecount + "패");
$("#console").append("\n새 판을 엽니다.");
$("#deal").css("display", "none");
$("#dealerDeck").text("");
$("#guestDeck").text("");
pcSet = Object.create(pcLst);
deal();
return 0;
});
$("#hit").click(function(){
hit();
return 0;
});
$("#stand").click(function(){
stand();
return 0;
});
$("#surrender").click(function(){
surrender();
return 0;
});
$("#plus").click(function(){
inc();
return 0;
});
$("#minus").click(function(){
dec();
return 0;
});
$("#reset").click(function(){
reset();
return 0;
});
function reset() {
mult = defa;
$("#multiplier").text(mult);
}
/*
function inc() {
if (mult < 100) {
mult += 2;
} else {
alert("최대 100 코인까지만 걸 수 있습니다.");
}
$("#multiplier").text(mult);
}
function dec() {
if (mult > 2) {
mult -= 2;
} else {
alert("설마 빚을 판돈으로 거시려고요?");
}
$("#multiplier").text(mult);
}
*/
function deal() {
dealerD = [];
guestD = [];
dealerD.push(cardPop());
guestD.push(cardPop());
dealerD.push(cardPop());
guestD.push(cardPop());
if (blind == true) {
$("#dealerDeck").text("\u{1F0A0}\u{1F0A0}");
} else {
$("#dealerDeck").text(hexToChar(dealerD[0]) + "\u{1F0A0}");
}
$("#dealerS").text("?");
if (blind == true) {
$("#guestDeck").text("\u{1F0A0}\u{1F0A0}");
} else {
$("#guestDeck").text(hexToChar(guestD[0]) + hexToChar(guestD[1]));
}
var guestScore = [];
var score = pointData[hexToStr(guestD[0])] + pointData[hexToStr(guestD[1])];
$("#guestS").text(score);
if ((pointData[hexToStr(guestD[0])] == 1 && pointData[hexToStr(guestD[1])] == 10) || (pointData[hexToStr(guestD[0])] == 10 && pointData[hexToStr(guestD[1])] == 1)) {
$("#guestS").text(21);
jack();
} else {
$("#hit").css("display", "inline-flex");
$("#stand").css("display", "inline-flex");
$("#surrender").css("display", "inline-flex");
}
};
function hit() {
$("#hit").css("display", "none");
$("#stand").css("display", "none");
$("#surrender").css("display", "none");
guestD.push(cardPop());
var guestDeq = "";
for (i = 0; i < guestD.length; i++) {
guestDeq += hexToChar(guestD[i]);
}
if (blind == true) {
$("#guestDeck").text("\u{1F0A0}".repeat(guestDeq.length / 2));
} else {
$("#guestDeck").text(guestDeq);
}
var guestScore = [];
var score = 0;
for (i = 0; i < guestD.length; i++) {
guestScore.push(pointData[hexToStr(guestD[i])]);
score += guestScore[i];
}
$("#guestS").text(score);
if (score == 21 || (score == 11 && guestScore.includes(1))) {
$("#console").append("\n21점이므로 자동으로 스탠드를 외쳤습니다.")
stand(dealerD,guestD);
} else if (score > 21) {
bust();
} else {
$("#hit").css("display", "inline-flex");
$("#stand").css("display", "inline-flex");
}
return 0;
}
function stand() {
$("#hit").css("display", "none");
$("#stand").css("display", "none");
$("#surrender").css("display", "none");
var dScore = 0;
var dealerScore = []
for (i = 0; i < dealerD.length; i++) {
dealerScore.push(pointData[hexToStr(dealerD[i])]);
dScore += dealerScore[i];
}
while (dScore < 17) {
dealerD.push(cardPop());
$("#console").append("\n딜러가 카드를 뽑았습니다.")
dealerScore = [];
dScore = 0;
for (i = 0; i < dealerD.length; i++) {
dealerScore.push(pointData[hexToStr(dealerD[i])]);
dScore += dealerScore[i];
dealerDeq += hexToChar(dealerD[i]);
}
}
var dealerDeq = "";
for (i = 0; i < dealerD.length; i++) {
dealerDeq += hexToChar(dealerD[i]);
}
$("#dealerS").text(dScore);
$("#dealerDeck").text(dealerDeq);
guestScore = [];
score = 0;
for (i = 0; i < guestD.length; i++) {
guestScore.push(pointData[hexToStr(guestD[i])]);
score += guestScore[i];
}
$("#guestS").text(score);
if (score > 21) {
bust()
} else if (dScore > 21) {
$("#console").append("\n딜러의 버스트.")
win()
} else {
$("#console").append("\n딜러의 스탠드.")
compare(dealerD,guestD);
}
return 0;
}
function compare() {
var dealerScore = [];
var dScore = 0;
for (i = 0; i < dealerD.length; i++) {
dealerScore.push(pointData[hexToStr(dealerD[i])]);
dScore += dealerScore[i];
}
var guestScore = [];
var score = 0;
for (i = 0; i < guestD.length; i++) {
guestScore.push(pointData[hexToStr(guestD[i])]);
score += guestScore[i];
}
if (dScore < 12 && dealerScore.includes(1)) {
dScore += 10
}
if (score < 12 && guestScore.includes(1)) {
score += 10
}
$("#dealerS").text(dScore);
$("#guestS").text(score);
if (dScore > score) {
lose()
} else if (dScore == score) {
push()
} else {
win()
}
return 0;
}
function win() {
$("#console").append("\n축하합니다! 이겼습니다.")
//$("#console").append("\n" + mult + "점을 얻었습니다.")
//coins += mult;
wincount += 1;
$("#deal").css("display", "inline-flex");
return 0;
}
function lose() {
$("#console").append("\n졌습니다...")
//$("#console").append("\n" + mult + "점을 잃었습니다.")
//coins -= mult;
losecount += 1;
$("#deal").css("display", "inline-flex");
publicAd();
return 0;
}
function push() {
$("#console").append("\n비겼습니다.")
$("#deal").css("display", "inline-flex");
return 0;
}
function surrender() {
$("#hit").css("display", "none");
$("#stand").css("display", "none");
$("#surrender").css("display", "none");
$("#console").append("\n이번 판을 포기하셨습니다 (패배로 처리됩니다).")
//$("#console").append("\n" + (0.5 * mult) + "점을 잃었습니다.")
//coins -= 0.5 * mult;
losecount += 1;
$("#deal").css("display", "inline-flex");
publicAd();
return 0;
}
function bust() {
$("#console").append("\n버스트! 유감입니다. 졌습니다...")
//$("#console").append("\n" + mult + "점을 잃었습니다.")
//coins -= mult;
losecount += 1;
$("#hit").css("display", "none");
$("#stand").css("display", "none");
$("#deal").css("display", "inline-flex");
publicAd();
return 0;
}
function jack() {
$("#console").append("\n블랙잭 달성! 축하합니다. 이겼습니다!")
//$("#console").append("\n" + (1.5 * mult) + "점을 획득했습니다.")
//coins += 1.5 * mult;
wincount += 1;
$("#deal").css("display", "inline-flex");
return 0;
}
function publicAd() {
if (coins < 0) {
$("#notice").text("땀 흘려 번 돈이 아름답습니다.");
}
return 0;
}
function cardPop() {
var j, ret;
j = Math.floor(Math.random() * pcSet.length);
ret = pcSet[j];
pcSet.splice(j,1);
return ret;
}
}
}
$( plugin_p21 );
/* p21 끝 */
/** 플러그인 uncydungeon***************************
* uncydungeon 실행
* 버전 => 0.1
* 작성자 : [[사용자:Jinhoftyu|Jinhoftyu]]
* JSON => uncydungeon = {"name":"uncydungeon","descript":"uncydungeon 실행","version":"0.1","local":true,"creat":"Jinhoftyu","state":"사용자:Jinhoftyu/Undungeon/플러그인","executable":true};
*/
function plugin_uncydungeon(){
if($("[data-name='uncydungeon']").length >= 1){
// 이부분에 코드 입력 //
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
class Item {
constructor(type, name, value) {
this.type = type;
this.name = name;
this.value = value;
}
}
class Entity {
constructor(type, name, x, y, health) {
this.type = type;
this.name = name;
this.x = x;
this.y = y;
this.health = health;
}
getAttack() {
return getAttack(this.name);
}
}
const rand = new (function() {
const seed = new Date().getTime();
this.nextInt = (n) => Math.floor(Math.random() * n);
this.seed = (s) => {};
})();
let game = false;
let mapY = 20;
let mapX = 80;
const base = new Array(mapY).fill(null).map(() => new Array(mapX).fill(null));
const entity = new Array(mapY).fill(null).map(() => new Array(mapX).fill(null));
const entities = [];
const item = [];
let dl = 0;
let xl = 0;
let hp = 0;
let maxhp = 0;
let pw = 0;
let maxpw = 0;
let time = 0;
let role;
let name = null;
let pl;
const inv = [];
const log = [];
function refLog() {
while (log.length > 3) {
log.shift();
}
}
async function main() {
for (let i = 0; i < mapY; i++) {
const row = [];
for (let j = 0; j < mapX; j++) {
row.push([]);
}
item.push(row);
}
while (name === null) {
name = await askQuestion('Your name?');
}
while (!game) {
const roleInput = await askQuestion(`
Your role?
a) Monk
b) Ranger
c) Valkryie
d) Wizard`);
preset(roleInput);
}
mapGen();
while (game) {
if (showInv) {
inventory();
await askQuestion();
} else {
display();
const cmd = (await askQuestion()).split(' ');
switch (cmd[0]) {
case '.':
turn();
break;
case 'h':
move(pl, -1, 0);
break;
case 'l':
move(pl, 1, 0);
break;
case 'j':
move(pl, 0, -1);
break;
case 'k':
move(pl, 0, 1);
break;
case 'y':
move(pl, -1, -1);
break;
case 'u':
move(pl, 1, -1);
break;
case 'b':
move(pl, -1, 1);
break;
case 'n':
move(pl, 1, 1);
break;
case '<':
ascend();
break;
case ',':
pickup();
break;
case 'i':
showInv = true;
break;
case 'Q':
process.exit(0);
break;
}
}
}
}
function updateStack(x, y, items) {
item[y][x] = items;
}
async function pickup() {
const plx = pl.x;
const ply = pl.y;
const items = item[ply][plx];
if (items.length > 0) {
const i = items[0];
inv.push(i);
items.shift();
updateStack(plx, ply, items);
log.push(`You picked up ${itemName(i)}.`);
turn();
} else {
log.push('There is nothing here.');
}
}
function ascend() {
const plx = pl.x;
const ply = pl.y;
if (base[ply][plx] === '<') {
console.log('You escaped from the dungeon.');
process.exit(0);
} else {
log.push("You can't go up here.");
}
}
function itemName(i) {
return `${i.value} ${i.name}${i.value > 1 ? 's' : }`;
}
async function move(en, dx, dy) {
const x = en.x;
const y = en.y;
if (base[y + dy][x + dx] !== '#' && entity[y + dy][x + dx] === null) {
entity[y][x] = null;
en.x += dx;
en.y += dy;
const floor = base[en.y][en.x];
entity[en.y][en.x] = en;
const items = item[en.y][en.x];
// log output
if (en === pl) {
turn();
if (floor !== '.' && floor !== '\0') {
log.push(`You are standing in ${floorDes(floor)}.`);
}
if (items.length > 1) {
log.push('You see here several items.');
} else if (items.length > 0) {
const i = items[0];
log.push(`You see here ${itemName(i)}.`);
}
}
}
}
async function turn() {
for (const e of entities) {
if (e !== pl) {
if (adjacent(e, pl)) {
attack(e, pl);
} else {
switch (rand.nextInt(8)) {
case 0:
move(e, -1, 0);
break;
case 1:
move(e, 1, 0);
break;
case 2:
move(e, 0, -1);
break;
case 3:
move(e, 0, 1);
break;
case 4:
move(e, -1, -1);
break;
case 5:
move(e, 1, -1);
break;
case 6:
move(e, -1, 1);
break;
case 7:
move(e, 1, 1);
break;
}
}
}
}
time++;
}
function mapGen() {
for (let y = 0; y < mapY; y++) {
for (let x = 0; x < mapX; x++) {
// old mapgen
const xborder = (y === 1
}
}
$( plugin_uncydungeon );
/* uncydungeon 끝 */
/** 플러그인 uncyslide***************************
* 백괴슬라이드 실행
* 버전 => 1.1.02
* 작성자 : [[사용자:BANIP|BANIP]]
* JSON => uncyslide = {"name":"uncyslide","descript":"백괴슬라이드 실행","version":"1.1.02","local":true,"creat":"BANIP","state":"백괴슬라이드/플러그인","executable":true};
*/
function plugin_uncyslide(){
if($("[data-name='uncyslide']").length >= 1){
// 이부부분에 코드 입력 //
var slideable = plugin_Slideable();
var create = slideable.create;
var execute = slideable.execute;
var dispose = slideable.dispose;
var rankingSystem = plugin_RankingSystem()("백괴슬라이드/랭킹", function(prev,next){ return Number(prev.time) - Number(next.time)});
var outputKeys = {time:"소요시간"};
var startMap = localStorage.getItem("uncySlide/startmap") || 0;
var game = {
0: {
center: "아래로 밀어주세요.",
bottom: 1
},
1: {
center: "오른쪽으로 밀어보세요.",
right: 2
},
2: {
center: "어디로 밀어보실래요?",
top: 3,
bottom: 3,
},
3: {
center: "반갑습니다. <br>백괴슬라이드입니다.",
bottom: 4,
},
4: {
center: "어디로 당기고 미느냐에 따라, 게임의 결과가 달라집니다.",
bottom: 5,
},
5: {
center: "는 개뿔 이겜 시스템만든다고 그런 장황한거 만들 정신머리는 없었습니다",
bottom: 5.1,
},
5.1: {
center: "진심 힘들었습니다.",
bottom: 5.2,
},
5.2: {
center: "잘했죠?",
bottom: 5.3,
},
5.3: {
center: "위로 밀어서 칭찬하거나 아래로 밀어서 욕해주세요.",
top: 5.4,
bottom: 5.5,
},
5.4: {
center: "감사합니다. 헤헤",
bottom: 6,
},
5.5: {
center: "흑흑.. 힘들었는데..",
bottom: 6,
},
6: {
center: "그래도 미디어위키의 틀에서 벗어난 겜인만큼 최대한 나은 경험을 선사하고자 노력했습니다. 잘부탁드립니다.",
bottom: function(){
localStorage.setItem("uncySlide/startmap","main");
execute("main");
},
},
main: {
center: "<ul><li>아래: 게임시작</li><li>토론: 위</li><li>설명: 오른쪽</li></ul>",
bottom: function(){ execute("start",{count:100,time:Date.now()}) },
top: "debate",
right: "i0",
},
i0: {
center:"가장자리에 화살표 보이죠?",
bottom:"i1"
},
i1: {
center:"화면을 넘겨서 드래그해서 진행하는 게임이에요.",
bottom:"i2"
},
i2: {
center:"원래라면 좀 큰 스케일의 게임으로 만들고 싶었는데..",
bottom:"i3"
},
i3: {
center:"제 역량이 겜 크기에서 다 드러나네요...",
bottom:"i4"
},
i4: {
center:"아무쪼록 힘들게 만들었으니 재밌게 즐겨주세요.",
right:"main"
},
debate: function(){
location.href = "https://libertyga.me/wiki/%ED%86%A0%EB%A1%A0:%EB%B0%B1%EA%B4%B4%EC%8A%AC%EB%9D%BC%EC%9D%B4%EB%93%9C";
},
start: function(arg){
function getRandomDirection(){
switch( Math.ceil(Math.random() * 4) ){
case 1: return "top"; break;
case 2: return "bottom"; break;
case 3: return "left"; break;
case 4: return "right"; break;
}
}
function getColorCode(count,maxcount){
var code = "hsl(" + count / maxcount * 360 +",100%,70%)";
return code
}
var count = arg.count;
var maxcount = arg.maxcount || count;
var time = arg.time;
var $this = $(this);
var timerInterval;
var slideableItem = {
center: function(){
var $this = $(this);
$this.css({
"background": getColorCode(count,maxcount)
});
timerInterval = setInterval(function(){
var overtime = (Date.now() - time) * 0.001;
var printableTime = overtime.toFixed(2);
$this.find(".counter").html(printableTime + "초");
},5)
return "<div class='counter' style='font-size:5vw;'></div><div style='font-size:20vw;'>" + count + "</div>";
}
};
slideableItem[getRandomDirection()] = function(){
clearInterval(timerInterval);
if(count === 1) return execute("result",{count:count - 1,time:time,maxcount:maxcount});
execute("start",{count:count - 1,time:time,maxcount:maxcount})
};
create(slideableItem);
},
result: function(arg){
var maxcount = arg.maxcount || count;
var time = ( (Date.now() - arg.time) / 1000 ).toFixed(2);
var updateParam = {
time: time,
name: mw.config.get("wgUserName")
};
rankingSystem.update(updateParam,function(rankingScore,thisScore){ return rankingScore.time > thisScore.time},outputKeys);
create({
center: "갯수: " + maxcount + " <br/>시간: " + time + "<ul><li>왼쪽: 메인으로</li><li>오른쪽: 토론으로</li></ul>",
left:"main",
right:"debate",
});
}
}
dispose(game, startMap, {});
}
}
$( plugin_uncyslide );
/* uncyslide 끝 */
/** 플러그인 Slideable***************************
* 슬라이드 플러그인 라이브러리
* 버전 => 1.0.21
* 작성자 : [[사용자:BANIP|BANIP]]
* JSON => Slideable = {"name":"Slideable","descript":"슬라이드 플러그인 라이브러리","version":"1.0.21","local":true,"creat":"BANIP","state":"사용자:BANIP/플러그인/슬라이드","executable":false};
*/
function plugin_Slideable(){
if($("[data-name='Slideable']").length >= 1){
// 이부부분에 코드 입력 //
//모든 키 순회
function forEach(object, callback) {
for (var key in object) {
var variable = object[key];
callback(variable, key);
}
}
function create(directionData) {
function initClassName($target, data) {
forEach(data, function(value, direction) {
$target.find("." + direction).addClass("on");
})
}
function initDOM($target, data) {
$target[0].data = data;
$target.find(".center").html(data.center);
$target.find(".top.on").css("background","url('https://upload.wikimedia.org/wikipedia/commons/8/85/Arrow_top_svg.svg') no-repeat center");
$target.find(".bottom.on").css("background","url('https://upload.wikimedia.org/wikipedia/commons/f/f2/Arrow_bottom_svg.svg') no-repeat center");
$target.find(".left.on").css("background","url('https://upload.wikimedia.org/wikipedia/commons/4/40/Arrowleft_svg.svg') no-repeat center");
$target.find(".right.on").css("background","url('https://upload.wikimedia.org/wikipedia/commons/e/ec/Arrow2right.svg') no-repeat center");
}
var slideUtil = {
moveObject: function($this, axis) {
var x = axis[0], y = axis[1];
var data = $this[0].data;
if (!data.right && x > 0) x = 0;
if (!data.left && x < 0) x = 0;
if (!data.top && y < 0) y = 0;
if (!data.bottom && y > 0) y = 0;
$this.css("transform", "translate(" + x + "px," + y + "px)");
},
isHideable: function($this, axis, limit) {
var x = axis[0], y = axis[1];
var data = $this[0].data;
if (data.right && x > limit) return "right";
if (data.left && x < limit * -1) return "left";
if (data.bottom && y > limit) return "bottom";
if (data.top && y < limit * -1) return "top";
},
hide: function(direction, $this) {
function getCss(direction) {
var css = {
opacity: 0.01
};
var interval = 50;
switch (direction) {
case "left":
css.left = -1 * interval + "vw";
break;
case "right":
css.left = interval + "vw";
break;
case "bottom":
css.top = interval + "vh";
break;
case "top":
css.top = -1 * interval + "vh";
break;
}
return css;
}
var self = $this[0];
var data = self.data;
if (self.isHide === true) {
return;
}
self.isHide = true;
$this.animate(getCss(direction), {
duration: 300,
easing: "swing",
start: data[direction],
complete: function() {
$this.remove();
}
});
}
}
function setEvent($target, data) {
var util = slideUtil;
var moveLimit = 50;
$(".slideable").mousedown(function(e) {
this.isMouseDown = true;
this.startAxis = [e.clientX, e.clientY];
})
$(".slideable").mousemove(function(e) {
if (this.isMouseDown) {
event.preventDefault()
var axis = [e.clientX, e.clientY];
var startAxis = this.startAxis;
var moveInterval = [axis[0] - startAxis[0], axis[1] - startAxis[1]]
util.moveObject($(this), moveInterval);
var hideDirection = util.isHideable($(this), moveInterval, moveLimit);
if (hideDirection) util.hide(hideDirection, $(this));
}
})
$(".slideable").mouseup(function(e) {
this.isMouseDown = false;
})
function getTouchEvent(e) {
return e.originalEvent.touches[0]
}
$(".slideable").on("touchstart", function(e) {
var touch = getTouchEvent(e);
this.isMouseDown = true;
this.startAxis = [touch.clientX, touch.clientY];
})
$(".slideable").on("touchmove", function(e) {
event.preventDefault()
if (this.isMouseDown) {
event.preventDefault()
var touch = getTouchEvent(e);
var axis = [touch.clientX, touch.clientY];
var startAxis = this.startAxis;
var moveInterval = [axis[0] - startAxis[0], axis[1] - startAxis[1]]
util.moveObject($(this), moveInterval);
var hideDirection = util.isHideable($(this), moveInterval, moveLimit);
if (hideDirection) util.hide(hideDirection, $(this));
}
})
$(".slideable").on("touchend", function(e) {
this.isMouseDown = false;
})
}
//슬라이드아이템의 방향키로 숫자 혹은 문자로 지정된 경우
//함수로 변환
function setExecutable(target, item){
forEach(item,function(value,direction){
new Promise(function(resolve, reject){
if(direction === "center"){
switch( typeof value ){
case "function":
resolve( value.bind(target)() );
break;
}
} else {
switch( typeof value ){
case "string": case "number":
resolve(function(){ execute(value); }.bind(target));
break;
}
}
}).then(function(result){
item[direction] = result;
})
})
}
var $target = $(".slideable.cloneable").clone().removeClass("cloneable");
$("body").prepend($target);
setExecutable($target[0], directionData);
initClassName($target, directionData);
initDOM($target, directionData);
setEvent($target, directionData);
}
// create는 다른 함수들에 의존하지 않음 //
var game;
function execute(number, argument) {
dispose(game, number, argument);
}
function dispose(slideableArray, start, argument) {
game = slideableArray;
var slideableItem = slideableArray[start];
switch (typeof slideableItem) {
case "function":
slideableItem(argument);
break;
case "object":
create(slideableItem);
break;
}
}
//모바일 전체화면으로 수정
var setFullScreen = (function(){
//window.scrollTo(0,1);
})();
return {
create: create,
execute: execute,
dispose: dispose
}
}
}
/* Slideable 끝 */
/** 플러그인 RankingSystem***************************
* 랭킹시스템 라이브러리
* 버전 => 1.1.0
* 작성자 : [[사용자:BANIP|BANIP]]
* JSON => RankingSystem = {"name":"RankingSystem","descript":"랭킹시스템 라이브러리","version":"1.1.0","local":true,"creat":"BANIP","state":"사용자:BANIP/플러그인/랭킹시스템","executable":false};
*/
function plugin_RankingSystem(){
if($("[data-name='RankingSystem']").length >= 1){
// 이부부분에 코드 입력 //
/**
* @param
{string} documentTitle 랭킹정보가 있는 문서의 제목.
{function} sortCallback 랭킹을 정렬할때 기준으로 사용하는 함수
{any} prev 랭킹 정렬 기준으로 사용할 왼쪽의 값
{any} next 랭킹 정렬 기준으로 사용할 오른쪽의 값
{object} api MediaWikiapi의 인스턴스, 없어도 됨.
@return {Object}
{function} get 랭킹정보를 object형태로 획득
{function} update 랭킹정보 업데이트
{object} updateInfo 업데이트할 사용자 정보
{function} updateCriteria 사용자정보의 업데이트 기준
@param {any} rankingScore 랭킹에서 사용중인 스코어
{any} thisScore 사용자 스코어
@return{bool} true가 반환되면 업데이트
{object} alternateKeys 랭킹에서 보여지는 대체 키
*/
return function(documentTitle, sortCallback, api) {
function forEach(object, callback) {
for (var key in object) {
var variable = object[key];
callback(variable, key);
}
}
function getRankingJSON(rankingDoc) {
if (!rankingDoc) return {};
var includeOnlyString = "includeonly"
var regexp = new RegExp("\<" + includeOnlyString + "\>(.*)\<\/" + includeOnlyString + "\>");
var stringRanking = regexp.exec(rankingDoc)[1];
return JSON.parse(stringRanking);
}
function updateDoc(rankingJSON, api, alternateKeys) {
//alternateKeys가 반영된 개개인의 랭킹정보 획득
function getOutputJSON(json) {
var result = {};
forEach(json, function(value, key) {
key = alternateKeys[key] || key;
result[key] = value;
})
return result;
}
//보여지는 형태의 랭킹정보 획득
function getOutputString(json) {
var name = json.name;
var result = "* '''" + name + "''' : ";
forEach(json, function(value, key) {
if (key === "name") return;
key = alternateKeys[key] || key;
result += key + ": " + value + ", ";
})
result += "\n"
return result
}
var stringRanking = JSON.stringify(rankingJSON);
var result = "<includ" + "eonly>" + stringRanking + "</inclu" + "deonly>\n";
result += "<onlyin" + "clude>\n";
var rankingList = Object.entries(rankingJSON).sort(function(prev,next){
return sortCallback(prev[1],next[1])
}).map(function(value){
return value[0]
});
rankingList.forEach(function(key) {
var json = rankingJSON[key];
var outputJSON = getOutputJSON(json);
result += getOutputString(outputJSON)
});
result += "</only" + "include>";
var reply = documentTitle.replace(new RegExp("\/.*"),"") + " 점수 갱신";
api.changeDocument(documentTitle, reply, result, true);
return result;
}
function updateUserScore(rankingJSON, thisScore, updateCriteria) {
updateCriteria = updateCriteria || function(rankingScore, thisScore) {
return rankingScore.score < thisScore.score;
}
var userName = thisScore.name;
var rankingScore = rankingJSON[userName];
if (!rankingScore || updateCriteria(rankingScore, thisScore)) {
rankingJSON[userName] = thisScore;
}
}
api = api || MediaWikiAPI();
var userName = mw.config.get("wgUserName");
var rankingDoc = api.getDocument(documentTitle);
var rankingJSON = getRankingJSON(rankingDoc);
var actions = {
get: function() {
return rankingJSON;
},
update: function(updateInfo, updateCriteria, alternateKeys) {
rankingJSON = actions.get();
updateUserScore(rankingJSON, updateInfo, updateCriteria);
updateDoc(rankingJSON, api, alternateKeys);
}
}
return actions;
}
}
}
/* RankingSystem 끝 */