跳转到内容

User:小躍/MathChallenge/MathChallenge.js

维基百科,自由的百科全书

这是本页的一个历史版本,由小躍留言 | 贡献2016年12月23日 (五) 13:52 (Fix)编辑。这可能和当前版本存在着巨大的差异。

注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google ChromeFirefoxMicrosoft EdgeSafari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
/*
版本:0.0.0 繁體中文版
開發者:小躍
*/
if (wgAction == 'view' && wgPageName =='User:小躍/MathChallenge'){
	document.getElementById('MathPlayingScreen').innerHTML = '您已成功載入腳本。'+'<input id="wpMathPlayingSureUser" value="確認身分" title="開始確認您的身分" type="button"/>';
	document.getElementById('MathPlayingScreen2').innerHTML ='咱們一起突破重重的關卡吧!';
	$('#wpMathPlayingSureUser').click(MathPlayingSureUser);
}
function MathPlayingSureUser(event) {
	event.preventDefault();
	var confirm_a=confirm('您的身分是'+wgUserName+'嗎?');
	switch(confirm_a){
		case true:{
			document.getElementById('MathPlayingScreen').innerHTML ='<img src="http:/upwiki/wikipedia/commons/4/42/Loading.gif" />'+wgUserName+
			'您好,歡迎進入挑戰數學的遊戲畫面。<br/><img src="http:/upwiki/wikipedia/commons/8/85/MathChallengePlayingStart.png" /><br/>';
			document.getElementById('MathPlayingScreen2').innerHTML =MathPlayingItems;
			if (wgAction == 'view' && wgPageName =='User:小躍/MathChallenge'){
				window.onbeforeunload = function(){ 
					window.event.returnValue ='';
				};
			}
			$('#wpMathPlayingDetermineL1').click(function(){
				Determine_q=0;
				Determine_score=0;
				Determine_ctime=0;
			}).click(MathPlayingDetermineL1).click(MathPlayingDetermineTimeout);
			$('#wpMathPlayingDetermineL2').click(function(){
				Determine_q=0;
				Determine_score=0;
				Determine_ctime=0;
			}).click(MathPlayingDetermineL2).click(MathPlayingDetermineTimeout);
			$('#wpMathPlayingDetermineL3').click(function(){
				Determine_q=0;
				Determine_score=0;
				Determine_ctime=0;
			}).click(MathPlayingDetermineL3).click(MathPlayingDetermineTimeout);
			break;	
		}
		case false:{
			document.getElementById('MathPlayingScreen').innerHTML ='<img src="https:/upwiki/wikipedia/commons/c/ca/Crystal_error.png" />您已取消確認身分的程序。';
			break;
		}
	}
}
var Determine_q;
var Determine_score;
var Determine_time;
var Determine_ctime;
var Determine_T;
var Determine1,Determine2,Determine3,Determine4;
var MathPlayingItems;
MathPlayingItems='選擇遊戲項目:<ul><li><input id="wpMathPlayingDetermineL1" value="第一階判斷" title="判斷大於、小於還是等於" type="button"/></li>'+
'<li><input id="wpMathPlayingDetermineL2" value="第二階判斷" title="判斷大於、小於還是等於" type="button"/></li>'+
'<li><input id="wpMathPlayingDetermineL3" value="第三階判斷" title="判斷大於、小於還是等於" type="button"/></li>'+
'</ul>';
function MathPlayingDetermineTimeout(){
	$(document).ready(function() {
		Determine_ctime=Determine_ctime+(0.01);	
	Determine_T=setTimeout("MathPlayingDetermineTimeout()",10);
	});
}
function MathPlayingDetermineL1(event){
	event.preventDefault();
	Determine_time=Math.floor(Determine_ctime *100)/100;
	document.getElementById('MathPlayingScreenShow').innerHTML ='使用時間:'+Determine_time+'秒,累計答對題數:'+Determine_score;
switch(Determine_q){
case 10:{
	clearTimeout(Determine_T);
	document.getElementById('MathPlayingScreen2').innerHTML ='<center><font size="45">題數已用完。</font><br/><input id="wpMathPlayingBack" value="返回" type="button"/></center>';
	$('#wpMathPlayingBack').click(MathPlayingItem);
	break;
}
default:{
	++Determine_q;
	Determine1=Math.floor(Math.random() *10);
	Determine2=Math.floor(Math.random() *10);
	document.getElementById('MathPlayingScreen2').innerHTML ='<center>第'+Determine_q+'題<br/><font size="45">'+Determine1.toString()+'<img src="http:/upwiki/wikipedia/commons/c/cd/Chess_l45.svg" />'+Determine2.toString()+'</font><br/>'+
	'<input id="wpMathPlayingDetermineBigger" value="大於" type="button"/><input id="wpMathPlayingDetermineSmaller" value="小於" type="button"/><input id="wpMathPlayingDetermineEqual" value="等於" type="button"/><br/><img src="http://3.bp.blogspot.com/_BxnVmGrZndM/THuqMI4dRaI/AAAAAAAABj0/iqjuTE10eE8/s1600/%C3%A5%E2%80%B9%E2%80%A2%C3%A7%E2%80%A2%C2%AB.gif"  width="300"/></center>';
	$('#wpMathPlayingDetermineBigger').click(function(){
		(Determine1>Determine2)?Determine_score=Determine_score+1:Determine_score=Determine_score+0;
	}).click(MathPlayingDetermineL1);
	$('#wpMathPlayingDetermineSmaller').click(function(){
		(Determine1<Determine2)?Determine_score=Determine_score+1:Determine_score=Determine_score+0;
	}).click(MathPlayingDetermineL1);
	$('#wpMathPlayingDetermineEqual').click(function(){
		(Determine1==Determine2)?Determine_score=Determine_score+1:Determine_score=Determine_score+0;
	}).click(MathPlayingDetermineL1);
	break;
}
}//switch end

}
function MathPlayingDetermineL2(event){
	event.preventDefault();
	Determine_time=Math.floor(Determine_ctime *100)/100;
	document.getElementById('MathPlayingScreenShow').innerHTML ='使用時間:'+Determine_time+'秒,累計答對題數:'+Determine_score;
switch(Determine_q){
case 10:{
	clearTimeout(Determine_T);
	document.getElementById('MathPlayingScreen2').innerHTML ='<center><font size="45">題數已用完。</font><br/><input id="wpMathPlayingBack2" value="返回" type="button"/></center>';
	$('#wpMathPlayingBack2').click(MathPlayingItem);
	break;
}
default:{
	++Determine_q;
	Determine1=1+Math.floor(Math.random() *9);
	Determine2=1+Math.floor(Math.random() *9);
	Determine3=1+Math.floor(Math.random() *9);
	Determine4=1+Math.floor(Math.random() *9);
	document.getElementById('MathPlayingScreen2').innerHTML ='<center>第'+Determine_q+'題<br/><font size="45">'+Determine1.toString()+'+'+Determine2.toString()+'<img src="http:/upwiki/wikipedia/commons/c/cd/Chess_l45.svg" />'+Determine3.toString()+'+'+Determine4.toString()+'</font><br/>'+
	'<input id="wpMathPlayingDetermineBigger2" value="大於" type="button"/><input id="wpMathPlayingDetermineSmaller2" value="小於" type="button"/><input id="wpMathPlayingDetermineEqual2" value="等於" type="button"/><br/><img src="http://3.bp.blogspot.com/_BxnVmGrZndM/THuqMI4dRaI/AAAAAAAABj0/iqjuTE10eE8/s1600/%C3%A5%E2%80%B9%E2%80%A2%C3%A7%E2%80%A2%C2%AB.gif"  width="300"/></center>';
	$('#wpMathPlayingDetermineBigger2').click(function(){
		(Determine1+Determine2>Determine3+Determine4)?Determine_score=Determine_score+1:Determine_score=Determine_score+0;
	}).click(MathPlayingDetermineL2);
	$('#wpMathPlayingDetermineSmaller2').click(function(){
		(Determine1+Determine2<Determine3+Determine4)?Determine_score=Determine_score+1:Determine_score=Determine_score+0;
	}).click(MathPlayingDetermineL2);
	$('#wpMathPlayingDetermineEqual2').click(function(){
		(Determine1+Determine2==Determine3+Determine4)?Determine_score=Determine_score+1:Determine_score=Determine_score+0;
	}).click(MathPlayingDetermineL2);
	break;
}
}//switch end

}
function MathPlayingDetermineL3(event){
	event.preventDefault();
	Determine_time=Math.floor(Determine_ctime *100)/100;
	document.getElementById('MathPlayingScreenShow').innerHTML ='使用時間:'+Determine_time+'秒,累計答對題數:'+Determine_score;
switch(Determine_q){
case 10:{
	clearTimeout(Determine_T);
	document.getElementById('MathPlayingScreen2').innerHTML ='<center><font size="45">題數已用完。</font><br/><input id="wpMathPlayingBack3" value="返回" type="button"/></center>';
	MathPlaySaveET('User:小躍/MathChallenge/Leaderboard','User:小躍/MathChallenge/Leaderboard',1,'{{User:小躍/MathChallenge/LeaderboardTemplate|username='+wpUaerName+'|score='+Determine_score+'|time='+Determine_time+'}}','自動儲存記錄');
	$('#wpMathPlayingBack3').click(MathPlayingItem);
	break;
}
default:{
	++Determine_q;
	Determine1=1+Math.floor(Math.random() *9);
	Determine2=1+Math.floor(Math.random() *9);
	Determine3=1+Math.floor(Math.random() *9);
	Determine4=1+Math.floor(Math.random() *9);
	document.getElementById('MathPlayingScreen2').innerHTML ='<center>第'+Determine_q+'題<br/><font size="45">'+Determine1.toString()+'×'+Determine2.toString()+'<img src="http:/upwiki/wikipedia/commons/c/cd/Chess_l45.svg" />'+Determine3.toString()+'×'+Determine4.toString()+'</font><br/>'+
	'<input id="wpMathPlayingDetermineBigger3" value="大於" type="button"/><input id="wpMathPlayingDetermineSmaller3" value="小於" type="button"/><input id="wpMathPlayingDetermineEqual3" value="等於" type="button"/><br/><img src="http://3.bp.blogspot.com/_BxnVmGrZndM/THuqMI4dRaI/AAAAAAAABj0/iqjuTE10eE8/s1600/%C3%A5%E2%80%B9%E2%80%A2%C3%A7%E2%80%A2%C2%AB.gif"  width="300"/></center>';
	$('#wpMathPlayingDetermineBigger3').click(function(){
		(Determine1*Determine2>Determine3*Determine4)?Determine_score=Determine_score+1:Determine_score=Determine_score+0;
	}).click(MathPlayingDetermineL3);
	$('#wpMathPlayingDetermineSmaller3').click(function(){
		(Determine1*Determine2<Determine3*Determine4)?Determine_score=Determine_score+1:Determine_score=Determine_score+0;
	}).click(MathPlayingDetermineL3);
	$('#wpMathPlayingDetermineEqual3').click(function(){
		(Determine1*Determine2==Determine3*Determine4)?Determine_score=Determine_score+1:Determine_score=Determine_score+0;
	}).click(MathPlayingDetermineL3);
	break;
}
}//switch end

}
function MathPlayingItem(event){
	event.preventDefault();
	document.getElementById('MathPlayingScreen2').innerHTML =MathPlayingItems;
	$('#wpMathPlayingDetermineL1').click(function(){
		Determine_q=0;
		Determine_score=0;
		Determine_ctime=0;
	}).click(MathPlayingDetermineL1).click(MathPlayingDetermineTimeout);
	$('#wpMathPlayingDetermineL2').click(function(){
		Determine_q=0;
		Determine_score=0;
		Determine_ctime=0;
	}).click(MathPlayingDetermineL2).click(MathPlayingDetermineTimeout);
	$('#wpMathPlayingDetermineL3').click(function(){
		Determine_q=0;
		Determine_score=0;
		Determine_ctime=0;
	}).click(MathPlayingDetermineL3).click(MathPlayingDetermineTimeout);
}
function MathPlaySaveET( tracePage,destinationPage,editSection,edittext,editsummary ) {
	var api = new mw.Api();
	api.get( {
		'action' : 'query',
		'titles' : tracePage,
		'prop'   : 'revisions|info',
		'intoken' : 'edit',
		'rvprop' : 'content',
		'rvsection':editSection,
		'indexpageids' : 1
	} ).done( function (result) {
		result = result.query;
		var page = result.pages[result.pageids[0]];
		var pagecontent= page.revisions[0]["*"].toString();
		var pagecontentL=pagecontent.length;
		var pagetext=pagecontent.substring(0,pagecontentL-3);
			pagetext+=edittext+'|}';
		api.post( {
			'action' : 'edit',
			'title' : destinationPage,
			'section':editSection,
			'text' :pagetext,
			'minor':1,
			'summary' :editsummary,
			'token' : page.edittoken
		} ).done( function () {
		} );
	} );
}