let main={theme:'lite',version:'0.804',timePrev:performance.now(),searchScript:'no',searchStatus:'no',searchData:''} let menuVis=false let searchVis=false function pathAbsolute(base,relative){let stack=base.split('index.html'),parts=relative.split('index.html') stack.pop() for(let i=0;i中文' newDiv.innerHTML=str}} if(!transQ){let path=location.pathname path=path.split('mathsisfun/index.html').join('index.html') let dir=path.substring(0,path.lastIndexOf('index.html')) let file=path.substring(path.lastIndexOf('index.html')+1) let fbQ=false if(fbQ){path='https://www.facebook.com/Mathisfun-249324325634773/' let newDiv=document.createElement('div') let tgtDiv=document.getElementById('content') document.body.insertBefore(newDiv,tgtDiv) let str='
' newDiv.innerHTML=str}}} function fixSpells(elem,tp){if(!(elem instanceof Node)||elem.nodeType!==Node.ELEMENT_NODE)return let children=elem.childNodes for(let i=0;children[i];++i){let node=children[i] switch(node.nodeType){case Node.ELEMENT_NODE:fixSpells(node,tp) break case Node.TEXT_NODE:if(tp=='s')fixSpell(node) if(tp=='d')fixDec(node) break}}} function fixSpell(node){let s=node.nodeValue if(s.length<4)return if(!s.match(/(?=.*[a-zA-Z])/))return let sStt=s for(let j=0;j255){s+='+'}else{s+='%' s+=HEX.charAt((charCode>>4)&0xf) s+=HEX.charAt(charCode&0xf)}}} return s} function copyToClipboard(txtArea){txtArea.focus() txtArea.select() let copiedTxt=document.selection.createRange() copiedTxt.execCommand('Copy')} function toHex(s){let hex='' for(let i=0;inow} function adOffSet(){let object={value:false,when:new Date()} localStorage.setItem('adoff',JSON.stringify(object))} function adOffReset(){let object={value:false,when:0} localStorage.setItem('adoff',JSON.stringify(object))} let adIDs=[{id:'adTop',withAdsQ:true},{id:'adend',withAdsQ:true},{id:'adsHide1',withAdsQ:true},{id:'adsShow1',withAdsQ:false},] function adsSet(onQ){for(let i=0;i0)qs+='_' qs+=arguments[i]} let s='' for(let i=0;iQuestion '+(i+1)+' '} document.write(s)} function urlSttGet(){let url=location.href url=url.replace('localhost/index.html','') let slashN=url.split('index.html').length-4 let urlStt='' for(let i=0;i' for(i=0;i'+links[i][1]+'' s+='\n'}} s+=''} if(typ==1){s+=''} if(typ==2){s+=' ' s+='' s+='Menu' s+=''} return s} function themeChgHTML(){let s='' s+='' return s} function menuShow(){console.log('menuShow',menuVis) let div=document.getElementById('menuSlim') if(menuVis){div.style.display='none'}else{div.style.display='block' if(searchVis)searchShow()} menuVis=!menuVis} function searchShow(){console.log('searchShow',searchVis) let div=document.getElementById('search') if(searchVis){div.style.display='none' div.style.position='relative'}else{div.style.display='block' div.style.position='absolute' if(menuVis)menuShow()} searchVis=!searchVis} function translateHTML(){let s='' s+='
' s+='' s+=' '}else{console.log('async translate2') s+='let googleTranslateScript = document.createElement("script");' s+='googleTranslateScript.type = "text/javascript";' s+='googleTranslateScript.async = true;' s+='googleTranslateScript.src = "../translate.google.com/translate_a/elementa0d8.js?cb=googleTranslateElementInit";' s+='( document.getElementsByTagName("head")[0] || document.getElementsByTagName("body")[0] ).appendChild(googleTranslateScript);' s+=''} return s} function cookMsg(){let s='' let imgHome=(document.domain=='localhost'?'/mathsisfun':'')+'/' s+='We may use Cookies  ' s+='
OK
' return s} function cookOK(){console.log('cookOK') document.getElementById('cookOK').style.display='none' localStorage.setItem('cookie','ok')} function adsenseDo(){console.log('adsenseDo') let script=document.createElement('script') script.type='text/javascript' script.setAttribute('async','async') script.src='../pagead2.googlesyndication.com/pagead/js/f.txt' document.getElementsByTagName('body')[0].appendChild(script) let ins=document.createElement('ins') ins.setAttribute('class','adsbygoogle') ins.setAttribute('style','display:block;') ins.setAttribute('data-ad-client','ca-pub-1389989178296449') ins.setAttribute('data-ad-slot','2009442555') ins.setAttribute('data-ad-format','auto') ins.setAttribute('data-full-width-responsive','true') let dest=document.getElementById('adend') dest.appendChild(ins) var inlineScript=document.createElement('script') inlineScript.type='text/javascript' inlineScript.text='(adsbygoogle = window.adsbygoogle || []).push({});' dest.appendChild(inlineScript) console.log('adsenseDo done')} function adTopHTML(){let path=location.pathname path=path.split('mathsisfun/index.html').join('index.html') let dir=path.substring(0,path.lastIndexOf('index.html')) let file=path.substring(path.lastIndexOf('index.html')+1) let s='' let src='' s+=adCodeGet(src) return s} function adEndHTML(){let path=location.pathname path=path.split('mathsisfun/index.html').join('index.html') let src='' src=document.domain=='localhost'?'dummy':'adsense' let s=adCodeGet(src) return s} function adCodeGet(src){let s='' switch(src){case '300x250':s+='dummy' break case 'dummy':s+='nice image' break case 'adsense':s+=` ` break default:} return s} function linksHTML(){let url=location.href let urlenc=encodeURIComponent(location.href) let title=encodeURIComponent(document.title) let linkstt='' s+=linkstt+'https://www.facebook.com/sharer/sharer.php?u='+url+'&t='+title+'" title="Share on Facebook" id="linkfb"> ' s+=linkstt+'https://twitter.com/intent/tweet?source='+url+'&text='+title+':%20'+url+'" title="Tweet it" id="linktw"> ' s+=linkstt+'http://pinterest.com/pin/create/button/?url='+url+'&description='+title+'" title="Pin it" id="linkpi">' s+='' return s} function footerHTML(){let s='' let urlStt=urlSttGet() let sep=' ○ ' s+='
' s+='Search'+sep s+='Index'+sep s+='About'+sep s+='Contact'+sep s+='Cite This Page'+sep s+='Privacy' s+='
' return s} function footer2HTML(){let urlStt=urlSttGet() let links=[['
logo
','',1],['index.htm','Home',0],['links/index.html','Index',0],['aboutmathsisfun.html','About Us',0],['contact.php','Contact Us',0],['Privacy.htm','Privacy',0],['
Subjects
','',1],['algebra/index.html','Algebra',0],['algebra/index-2.html','Algebra 2',0],['calculus/index.html','Calculus',0],['data/index.html','Data',0],['geometry/plane-geometry.html','Plane Geometry',0],['geometry/solid-geometry.html','Solid Geometry',0],['measure/index.html','Measure',0],['money/index.html','Money',0],['numbers/index.html','Numbers',0],['physics/index.html','Physics',0],['
Other
','',1],['activity/index.html','Activities',0],['definitions/index.html','Dictionary',0],['games/index.html','Games',0],['puzzles/index.html','Puzzles',0],['worksheets/index.php','Worksheets',0],] let s='' s+='
' for(let i=0;i0)s+='
' s+='
' s+=link[0]}else{s+='
' s+=''+link[1]+'' s+='
\n'}} s+='
Cite This Page' s+='
' console.log('foot',s) return s} function themeChg(){let was=themeGet() let theme=was=='lite'?'dark':'lite' themeSet(theme) document.getElementById('themeSlider').checked=theme=='dark'} function themeGet(){let theme=localStorage.getItem('theme') if(theme==null){let prefersDarkScheme=window.matchMedia('(prefers-color-scheme: dark)').matches theme=prefersDarkScheme?'dark':'lite' localStorage.setItem('theme',theme)} if(theme!='lite'&&theme!='dark'){theme='lite' localStorage.setItem('theme',theme)} return theme} function themeSet(theme){localStorage.setItem('theme',theme) console.log('themeSet',theme,document.documentElement.hasAttribute('theme')) document.documentElement.setAttribute('theme',theme)} function adsHideHTML(){let s='' s+='' s+='
Hide Ads | ' let imgHome=(document.domain=='localhost'?'/mathsisfun':'')+'/' s+='About Ads
' return s} function adsHideSet(){if(adOffQ()){adsSet(false)}} function gTagHTML(){let s='' s+='' s+='' return s} function logVisit(){let pg=location.pathname if(pg=='index.html')return let pgHex=toHex(pg) addVisit(pgHex,'visit',window.location.hostname)} if(Math.random()<0.1)logVisit() function addVisit(pg,viewtype,hostname){console.log('addVisit',viewtype,hostname) let req req=new XMLHttpRequest() let params='type='+viewtype params+='&site=mif' params+='&pg='+encodeURIComponent(pg) params+='&lang='+encodeURIComponent(window.navigator.language) params+='&ref='+encodeURIComponent(toHex(document.referrer)) req.open('POST.html','https://mi2f.com/update.php',true) req.setRequestHeader('Content-type','application/x-www-form-urlencoded') req.send(params)} function onScroll(){let scrollTop=document.documentElement?document.documentElement.scrollTop:document.body.scrollTop let menu=document.getElementById('menu') if(scrollTop>100){menu.style.top='0px' menu.style.width='1000px' menu.style.border='1px solid #ffffff' menu.style.boxShadow='0px 12px 12px -12px #77cc77' menu.style.backgroundColor='white' menu.style.textAlign='center' menu.style.position='fixed' menu.style.zIndex='5000'}else{menu.style.boxShadow='none' menu.style.position='static'}} function relatedLinks(){if(window.innerWidth<860){return} let rels=document.getElementsByClassName('related') if(rels.length==0){return} let rel=rels[0] let links=rel.getElementsByTagName('a') let count=links.length let right=null let left=null if(count==1)right=links[0] if(count>1){left=links[0] right=links[1]} let s='' let top=220 if(left!=null){s+='
' s+=fmtMenuBox(left.href,left.text,0) s+='
'} if(right!=null){s+='
' s+=fmtMenuBox(right.href,right.text,1) s+='
'} document.getElementById('stt').innerHTML+=s} function fmtMenuBox(url,txt,dirn){let s='' let boxID=dirn==0?'menuLt':'menuRt' s+='' s+='
' s+=txt s+='
' s+='
' return s} function vidDo(id,spanid){let s='' let visIndex=videoVis.indexOf(spanid) let visQ=visIndex>-1?true:false if(visQ){let frame=document.getElementById(spanid+'v1') frame.parentNode.removeChild(frame) videoVis.splice(visIndex,1) visQ=false}else{s+='
' s+='' s+='
' videoVis.push(spanid) visQ=true} let vid=document.getElementById(spanid) vid.innerHTML=s vid.style.border='5px solid blue;' console.log('vidDo',vid) if(visQ)resizeVideo(spanid)} function resizeVideo(spanid){let v1=document.getElementById(spanid+'v1') let wd=window.innerWidth-40 if(wd>640)wd=640 v1.style.width=wd+'px' v1.style.height=wd*(340/640)+80+'px'} let videoVis=[] function mainDo(){if(document.getElementById('menuWide')==null)return document.getElementById('menuWide').innerHTML=menuHTML(0) document.getElementById('menuSlim').innerHTML=menuHTML(1) document.getElementById('menuTiny').innerHTML=menuHTML(2) document.getElementById('adHide').innerHTML=adsHideHTML() if(localStorage.getItem('cookie')=='ok'){}else{document.getElementById('cookOK').innerHTML=cookMsg()} document.getElementById('search').innerHTML=searchHTML() document.getElementById('linkto').innerHTML=linksHTML() document.getElementById('logo').innerHTML+=themeChgHTML() document.getElementById('themeSlider').checked=themeGet()=='dark' document.getElementById('footer').innerHTML=footerHTML() let qDivs=document.querySelectorAll('.questions') for(let i=0;i' s+='' s+='' s+='' s+='' return s} function searchKey(ev){let val=ev.target.value console.log('searchKey',val) if(main.searchScript=='no'){main.searchScript='loading' let script=document.createElement('script') script.onload=function(){console.log('Script loaded and ready') searchDo(ev) main.searchScript='yes'} let imgHome=(document.domain=='localhost'?'/mathsisfun':'')+'/search/images/' script.src=imgHome+'search-lib.js' document.getElementsByTagName('head')[0].appendChild(script)} if(main.searchScript=='yes')searchDo(ev) return} function qsExpand(node){let str=node.innerHTML if(str.includes('getQ('))return console.log('qsExpand',str) let newStr=qsHTML(str) node.innerHTML=newStr} function qsHTML(qStr){let qs=qStr.trim().split(/[^0-9]+/) let joinedStr=qs.join('_') let s='' for(let i=0;iQuestion '+(i+1)+' '} return s} function vidExpand(div,n){let str=div.innerHTML if(str.trim().length<=1)return let newStr=vidHTML(str,'title','video'+n) div.innerHTML=newStr} function vidHTML(id,titleid='title',spanid='video',style='span'){id=id.replace(/−/g,'-') let s='' switch(style){case 'span':s+='' s+='Video' s+='' s+='' break case 'h1':let title=document.getElementById(titleid).innerHTML s+='
' s+='
' s+=' ' s+=' Video' s+=' ' s+='
' s+='
 
' s+='
' s+='

'+title+'

' s+='
' s+='
' break case 'h2':title=document.getElementById(titleid).innerHTML s+='
' s+=' ' s+=' Video' s+=' ' s+='
' s+='

'+title+'

' break} return s} function initVideo(id,titleid,spanid,style){titleid=typeof titleid!=='undefined'?titleid:'title' spanid=typeof spanid!=='undefined'?spanid:'video' style=typeof style!=='undefined'?style:'h1' document.getElementById(titleid).innerHTML=vidHTML(id,titleid,spanid,style)} function scriptExpand(node){let str=node.innerHTML if(str.trim().length<=1)return iframeDo(node,str)} function putFlash6(w,h,swf,querystring,clr,noflash){} function putFlash7(w,h,swf,querystring,clr,noflash){console.log('putFlash7: '+swf) let s='
' document.write(s) window.RufflePlayer=window.RufflePlayer||{} window.addEventListener('load',(event)=>{const ruffle=window.RufflePlayer.newest() const player=ruffle.createPlayer() const container=document.getElementById('container') container.appendChild(player) player.load(swf)})} function putFlash8(w,h,swf,querystring,clr,noflash){console.log('putFlash8: '+swf) window.RufflePlayer=window.RufflePlayer||{} window.addEventListener('load',(event)=>{const ruffle=window.RufflePlayer.newest() const player=ruffle.createPlayer() const container=document.getElementById('container') console.log('container',container) container.appendChild(player) player.load(swf)})} function iframeDo(node,fileStr){let fileNames=fileStr.split(',') let filename=fileNames[fileNames.length-1].trim() let imgHome=document.domain=='localhost'?'/mathsisfun/':'/' let sttWd=parseInt(node.getBoundingClientRect().width) let sttHt=parseInt(node.getBoundingClientRect().height) let aspect=parseFloat(node.style.gap) let maxQ=!isNaN(aspect) console.log('iframe',node,node.style.gap,aspect,maxQ) let htQ=node.style.height.length>0 let iframe=document.createElement('iframe') if(htQ){iframe.width=sttWd iframe.height=sttHt}else{iframe.height='200'} iframe.style=`display:block; margin:auto; border:none; background-color:transparent; overflow:hidden; transition:all 0.6s ease-in-out;` iframe.scrolling='no' iframe.setAttribute('title','JavaScript Animation') console.log('iframe',filename,sttWd,sttHt,htQ,maxQ) let html='' html+='' for(let i=0;i'} html+='' html+='' html+='' html+='' html+='' html+=`` html+='' html+='' node.parentElement.insertBefore(iframe,node) node.style.display='none' iframe.contentWindow.document.open() iframe.contentWindow.document.write(html) iframe.contentWindow.document.close() iframe.addEventListener('load',function(){let btnQ=false let aQ=false iframe.style.maxWidth='100%' let bestWd=0,bestHt=0 if(htQ){bestWd=sttWd bestHt=sttHt}else{bestWd=0 iframe.width=bestWd+'px' bestHt=iframe.contentDocument.body.scrollHeight+1 iframe.height=bestHt+'px'} setInterval(function(){if(maxQ){let wd=window.innerWidth let ht=window.innerHeight-60 let newAspect=wd/ht if(newAspect>aspect){wd=ht*aspect}else{ht=wd/aspect} iframe.width=wd+'px' iframe.height=ht+'px' return} let wd,ht if(false){let div=iframe.contentDocument.body.children[0].children[0] let rect=div.getBoundingClientRect() wd=rect.width ht=rect.height}else{wd=iframe.contentDocument.body.scrollWidth+1 ht=iframe.contentDocument.body.scrollHeight+1} if(wd!=bestWd){console.log('chg wd',bestWd,'to',wd) bestWd=wd if(!aQ){iframe.width='100%'}else{iframe.width=bestWd+'px' aQ=true}} if(ht>bestHt||ht▭' div.innerHTML=btnStr} btnQ=true}},650)})} function rpLog(id){let now=performance.now() if(main.timeStt==undefined){main.timeStt=performance.now() main.timePrev=performance.now()} console.log(''+id+': '+parseInt(now-main.timeStt)+'ms => '+parseInt(now-main.timePrev)+'ms') main.timePrev=now} themeSet(themeGet()) window.onload=mainDo