ifree's Blog - it's my way

豆瓣fm的全局快捷键

最近用上了pentadacty, 感觉不错,高效强大. 个人有一个习惯,只要不是思考密集的时间都会抽时间来听会歌,同时也有开大量tabs的习惯,所以在听豆瓣电台的时候免不了频繁的切换,于是就有了下面的代码:

"eval script in tabs 
js <<EOF
function execScriptInTabs(filter,domjs){
	 tabs.allTabs.forEach(function(itm){
	var ctab=gBrowser.getBrowserForTab(itm);
	if(filter(ctab)){
		var s=ctab.contentDocument.createElement('script')
		s.textContent=domjs;
		ctab.contentDocument.body.appendChild(s);
	}
	 })
}
EOF

"douban.fm utilities

js <<EOF
group.mappings.add(
[modes.NORMAL],
[",ds"],"skip",
function(){
execScriptInTabs(function(ctab){
return ctab.contentDocument.location.host.match("douban\.fm");
},"DBR.act('skip')");//skip,pause,love
}
);
group.mappings.add(
[modes.NORMAL],
[",dd"],"ban",
function(){
execScriptInTabs(function(ctab){
return ctab.contentDocument.location.host.match("douban\.fm");
},"DBnnR.act('ban')");//skip,pause,love
}
);
group.mappings.add(
[modes.NORMAL],
[",dl"],"like",
function(){
execScriptInTabs(function(ctab){
return ctab.contentDocument.location.host.match("douban\.fm");
},"DBR.act('love')");//skip,pause,love
}
);
group.mappings.add(
[modes.NORMAL],
[",dp"],"pause",
function(){
execScriptInTabs(function(ctab){
return ctab.contentDocument.location.host.match("douban\.fm");
},"DBR.act('pause')");//skip,pause,love
}
);
EOF


 

ultraEdit 注释插件

不要跟我说vim,不要跟我说linux,我也是被逼的

直接上代码:(ue还不内部脚本还不支持activeX对象,所以好多功能都没法实现...所以我一直都用vim )

 

//file: auth.js
//desc: pig
//author: ifree
//last modified date: Monday, December 19, 2010 21:54:55
(
function(ue){
	var currentDoc=ue.activeDocument;
	var debug=ue.outputWindow;
	function getFileName(){
		 var path=currentDoc.path;	
		 return path.substring(path.lastIndexOf("\\")+1,path.length);
	}
	function getDate(){
		return new Date().toLocaleString();	
	}
	function desc(obj){
		for(var i in obj){
			debug.write("{"+i+":"+obj[i]+"}\r\n");	
		}
	}
	//render whole or single template
	function templateHandler(){
		var template=[];
		template["file"]="//file: {getFileName()}";
		template["desc"]="//desc: {desc}";
		template["author"]="//author: {author}";
		template["last modified date"]="//last modified date: {getDate()}";
		
		var reg=/{(.+)}/;
		function renderSelf(key,value){
				if(!key)return;
				var str=template[key];
				if(!str)return;
				reg.exec(str);
				
				if(RegExp.$1.indexOf('(')>=0){
					str=str.replace(reg,eval(RegExp.$1));
				}else
					str=str.replace(reg,value);
				return str;
		}
		
		return {
				render:function(obj){
						var ret="";
						for(var i in template){
								ret+=renderSelf(i,obj[i]?obj[i]:'')+"\r\n";
						}
						return ret;
				},
				renderSingle:function(k,v){
					return renderSelf(k,v);	
				}
		}
	}
	//get output
	return function(cfg){
		currentDoc.write("{"+"cursor"+"}");
		
		
		var reg=/\/\/([\w\s]+):(\s?.+)/;
		currentDoc.gotoLine(5);
		currentDoc.selectToTop();
		
		var texts=currentDoc.selection.split("\r\n");
		//detect if comment has added
  	if(reg.test(texts[0])){
  		
	  	for(var i=0,il=texts.length;i<il;i++){
	  			if(reg.test(texts[i])){
	  					texts[i]=templateHandler().renderSingle(RegExp.$1.trim(),RegExp.$2.trim());
	  			}
	  	}
	  	currentDoc.deleteText();
	  	currentDoc.write(texts.join('\r\n'));
  	}else{
  		currentDoc.selectAll();
  		currentDoc.write(templateHandler().render(cfg)+currentDoc.selection);
  	}

  	//set cursor to orign posi
  	currentDoc.top();
  	currentDoc.findReplace.find("{"+"cursor"+"}");
  	currentDoc.deleteText();
	}
}
)(UltraEdit)({author:"ifree"});