User:A930913/vada/plugin/store.js

if(typeof window!="undefined"){ //inside Vada DOM (function{		var store={};		store.about={			name:"App Store",			description:"Easy installer of Vada plugins",			namespace:"store",			userscript:"User:A930913/vada/plugin/store.js",		}		store.load=function(params){			var apps=params.apps;			var s=$(" ");			s.attr("id","apps");			var c=$(" ");			c.text("Installed apps:");			apps.forEach(function(itm){ var o=$(" ").val(itm.name); s.append(o); if(params.myapps.indexOf(itm.userscript)!=-1){ c.append(" /g,"")+"' title='"+itm.description.replace(/<.+?>/g,"")+"' value='"+itm.userscript+"'>"+itm.name+" "); }			});			var b=$(" ");			b.text("Uninstall selected apps");			b.click(store.uninstall);			c.append(b);			var d=$(" ");			d.html(['',s,' ',c]);			$("#diffcontainer").append(d);			$("#appinp").on("input",function(e){ var app; for(var i=0;i<apps.length;i++){ if(apps[i].name==e.target.value){ app=apps[i]; break; }				}				if(app){ store.show(app); }			});		}		store.show=function(app){			var b=$(" ");			b.text("Purchase free app");			b.click(function{ window.vada.call("plugins.store.install",{app:app.userscript}); });			$("#appdisplay").html([" "+app.name+" "+app.description+" Free app is free ",b]);		}		store.uninstall=function{			var rm=[];			$("[name=unapp]:checked").each(function{ rm.push(this.value); });			window.vada.call("plugins.store.uninstall",{rm:rm});		}		store.uninstalled=function{			alert("Page needs to be reloaded to finish uninstalling.");		}		store.run=function(params){			importScript(params.app);			alert("App successfully installed");		}		window.vada.loadPlugin(store);		var blob = new Blob(['\ #appinp{\ border-radius:10px;\ position:fixed;\ }\		#appdisplay{\ font-family:sans-serif;\ display:table-cell;\ width:50%;\ padding-top:30px;\ }\		.appname{\ font-weight:bold;\ }\		.appdesc{\ \		}\		.appprice{\ \		}\		.appname:before{\ content:\'Name: \';\ opacity:0.3;\ }\		.appdesc:before{\ content:\'Description: \';\ opacity:0.3;\ }\		.appprice:before{\ content:\'Price: \';\ opacity:0.3;\ }\		#installed{\ font-family:sans-serif;\ display:table-cell;\ }\		#appcontainer{\ display:table;\ width:100%;\ padding:10px;\ box-sizing:border-box;\ background:#eee;\ }\		#appcontainer button{\ display:block;\ border-radius:10px;\ }\		#appcontainer button:hover{\ background-color:#ccc;\ }\		'], {type: 'text/css'});		var css=document.createElement("link");		css.setAttribute("rel","stylesheet");		css.setAttribute("href",window.URL.createObjectURL(blob));		document.head.appendChild(css);	}); } else { //inside Vada process vada.plugins.store={ start:function{ vada.events.trigger("plugins.stop",{}); vada.events.addListener("plugins.stop",vada.plugins.store.stop); var myapps=vada.plugins.store.getMyApps; vada.dom.call("plugins.store.load",{apps:JSON.parse(new vada.Page("User:A930913/vada/plugin/store.js/plugins.js").text),myapps:myapps}); },		stop:function{ vada.events.removeListener("plugins.stop",vada.plugins.store.stop); },		getMyApps:function{ var vjs=(function{try{return vada.plugins.store.mypage.text;}catch(e){return "";}}); return(function(vjs){				var r=/^importScript\("(.*?)"\);( \/\/\[\[.*?\]\])?$/gm;				var apps=[];				while(m=r.exec(vjs)){try{apps.push(m[1]);}catch(e){return false;}}				return apps;			})(vjs); },		install:function(params){ var myapps=vada.plugins.store.getMyApps; if(myapps.indexOf(params.app)!=-1)return;//Don't double install. myapps.push(params.app); vada.plugins.store.save(myapps); vada.dom.call("plugins.store.run",{app:params.app}); },		uninstall:function(params){ var myapps=vada.plugins.store.getMyApps; for(var i in params.rm){ myapps.splice(myapps.indexOf(params.rm[i]),1); }			vada.plugins.store.save(myapps); vada.dom.call("plugins.store.uninstalled",{}); },		save:function(apps){ vada.plugins.store.mypage.text="/* This page is automatically updated from the app store. Do not change unless you know what you're doing. */\n\n"; for(var i in apps){ vada.plugins.store.mypage.text+='importScript("'+apps[i]+'"); //'+apps[i]+'\n'; }			vada.plugins.store.mypage.save("Updating installed apps"); }	}	vada.plugins.store.button=new vada.dom.menu.Button("store_start"); vada.plugins.store.button.text="App Store"; vada.plugins.store.button.click=vada.plugins.store.start; vada.dom.menu.buttons.vada.children.push(vada.plugins.store.button); vada.dom.menu.redraw; vada.plugins.store.mypage=new vada.Page("User:"+(vada.api({action:"query",meta:"userinfo"}).query.userinfo.name)+"/vada.js"); }