Browse Source

fixed custom meta data support

Gerald 12 years ago
parent
commit
d6cd536150
3 changed files with 11 additions and 12 deletions
  1. 6 7
      background.js
  2. 4 4
      options.js
  3. 1 1
      popup.js

+ 6 - 7
background.js

@@ -356,11 +356,11 @@ function parseScript(o,src,callback) {
 		queryScript(o.id,meta,function(c){
 			if(!c.id){r.status=1;r.message=_('msgInstalled');}
 			if(o.more) for(i in o.more) c[i]=o.more[i];	// for import and user edit
-			c.meta=meta;c.code=o.code;r.obj=getMeta(c);c.uri=getNameURI(c);
+			c.meta=meta;c.code=o.code;c.uri=getNameURI(c);
 			if(o.from&&!c.meta.homepage&&!c.custom.homepage&&!/^(file|data):/.test(o.from)) c.custom.homepage=o.from;
 			if(o.url&&!c.meta.downloadURL&&!c.custom.downloadURL) c.custom.downloadURL=o.url;
 			saveScript(c,src).onsuccess=function(e){
-				r.id=c.id=e.target.result;finish();
+				r.id=c.id=e.target.result;r.obj=getMeta(c);finish();
 			};
 		});
 		meta.require.forEach(fetchRequire);	// @require
@@ -405,14 +405,13 @@ function setOption(data,src,callback){
 	o.put({key:data.key,value:data.value});
 	if(callback) callback(data.value);
 }
-function enableScript(d,src,callback) {
+function updateMeta(d,src,callback) {
 	var o=db.transaction('scripts','readwrite').objectStore('scripts');
 	o.get(d.id).onsuccess=function(e){
-		var r=e.target.result;
+		var r=e.target.result,i;
 		if(!r) return;
-		r.enabled=d.data?1:0;
+		for(i in d) if(i in r) r[i]=d[i];
 		o.put(r).onsuccess=function(e){	// store script without another transaction
-		//saveScript(r,src).onsuccess=function(e){
 			updateItem({id:d.id,obj:getMeta(r),status:0});
 		};
 	};
@@ -597,7 +596,7 @@ chrome.runtime.onMessage.addListener(function(req,src,callback) {
 		CheckUpdate: checkUpdate,
 		CheckUpdateAll: checkUpdateAll,
 		SaveScript: saveScript,
-		EnableScript: enableScript,
+		UpdateMeta: updateMeta,
 		SetValue: setValue,
 		GetOption: getOption,
 		SetOption: setOption,

+ 4 - 4
options.js

@@ -89,11 +89,11 @@ function addItem(o){
 	var maps={
 		edit:function(i){
 			E.cur=map[ids[i]];
-			chrome.runtime.sendMessage({cmd:'GetScript',data:E.cur.obj.id},gotScript);
+			chrome.runtime.sendMessage({cmd:'GetScript',data:ids[i]},gotScript);
 		},
 		enable:function(i,p,o){
 			var e=map[ids[i]].obj;
-			chrome.runtime.sendMessage({cmd:'EnableScript',data:{id:e.id,data:!e.enabled}});
+			chrome.runtime.sendMessage({cmd:'UpdateMeta',data:{id:e.id,enabled:!e.enabled?1:0}});
 		},
 		remove:function(i,p){
 			chrome.runtime.sendMessage({cmd:'RemoveScript',data:ids[i]});
@@ -310,6 +310,7 @@ function eSave(){
 			code:T.getValue(),
 			message:'',
 			more:{
+				custom:E.scr.custom,
 				update:E.scr.update=U.checked
 			}
 		}
@@ -361,8 +362,7 @@ $('mOK').onclick=function(){
 		c.match=split(mM.value);
 		c._exclude=cE.checked;
 		c.exclude=split(mE.value);
-		if(E.cur) loadItem(E.cur,E.scr);
-		chrome.runtime.sendMessage({cmd:'SaveScript',data:E.scr});
+		E.markDirty();
 	}
 	closeDialog();
 };

+ 1 - 1
popup.js

@@ -36,7 +36,7 @@ function menuScript(s) {
 		symbol: '✓',
     title: s.meta.name,
     onclick: function(e){
-			chrome.runtime.sendMessage({cmd:'EnableScript',data:{id:s.id,data:loadItem(this,!this.data)}});
+			chrome.runtime.sendMessage({cmd:'UpdateMeta',data:{id:s.id,enabled:loadItem(this,!this.data)?1:0}});
     }
   }),s.enabled);
 }