使用 org-mode 管理 emacs 中的 Firefox 选项卡
我最近找到了一种在 emacs 中管理 Firefox 选项卡的方法。这听起来有点疯狂。我使用树形选项卡(firefox 插件)、Moz Repl、emacs、org-mode 来完成此操作。
对于 10-15 个选项卡,我的计划效果很好。但是超过 20 个标签页时,我的 Firefox 会随机挂起。也许是javascript堆栈溢出或者其他什么?我不知道我的代码有什么问题。我在这里发布了最重要的代码。有人帮我找到一些错误吗?
下面是一个基本的 Firefox chrome 代码,您可以在 Firefox 中运行它,而不需要 emacs 和 MozPepl。
我使用树形选项卡 api 来获取选项卡并将每个选项卡设置为某个级别。输出将在带有 org-mode 的 emacs 中使用。 树样式选项卡 api: http://piro.sakura.ne.jp/ xul/_treestyletab.html.en#api
代码可以通过多种方式运行。我推荐“工作区插件”。复制我的代码,选择 chrome 上下文来运行它。 https://addons.mozilla.org/en-US/firefox/addon/工作区/
// two helper function to get title and url of tab
function getTitle(tab)
{
var brower = gBrowser.getBrowserForTab(tab)
var url = brower.currentURI.spec
var title = brower.contentTitle
return title
}
function getUrl(tab)
{
var brower = gBrowser.getBrowserForTab(tab)
var url = brower.currentURI.spec
var title = brower.contentTitle
return ":PROPERTIES:\n:URL:"+url+"\n:END:\n"
}
var L = gBrowser.tabContainer.childNodes.length //firefox tabs length
var str = "" //global string for output
//parse tabs. If tab has child, parse it. It tab has no child, just output.
for(i = 0; i < L; i++){
level = "*"
tab = gBrowser.tabContainer.childNodes[i]
if ('TreeStyleTabService' in window){
if(TreeStyleTabService.hasChildTabs(tab))
{
str = [str, level, " [+] ", getTitle(tab), "\n", getUrl(tab)].join("") //output title and url. level used in org-mode
treeparse(TreeStyleTabService.getChildTabs(tab), "**") //if a tab has child tabs. parse it and level up
}
str = [str, level, " ", getTitle(tab), "\n", getUrl(tab)].join("")
}
function treeparse(tablist,level) //parse a list of tabs. If tab has not a child, output. If it has childs, parse again
{
for(i=0 ; i < tablist.length;i++) {
tab = tablist[i]
if ('TreeStyleTabService' in window){
if(TreeStyleTabService.hasChildTabs(tab))
{
str = [str, level, " [+] ", getTitle(tab), "\n", getUrl(tab)].join("")
newlevel = level + "*"
treeparse(TreeStyleTabService.getChildTabs(tab),newlevel)
}
} }
str = [str, level, " ", getTitle(tab), "\n", getUrl(tab)].join("")
}
}
alert(str) //alert to view result. You can also write the result into a file.
I recently find a way to manage firefox tab in emacs. This sounds a little crazy. I use tree style tabs(firefox addon), Moz Repl, emacs, org-mode to do it.
For 10-15 tabs, my plan works fine. But 20+ tabs, My firefox hangs randomly. Maybe javascript stack overflow or something else? I don't know what's wrong with my code. I post the most import code here. Somesone help me to find some bugs?
It's a basic firefox chrome code below, you can run it in firefox without emacs and MozPepl.
I use tree style tabs api to get tabs and set each tab a cetain level. The output will be used in emacs with org-mode.
tree style tabs api: http://piro.sakura.ne.jp/xul/_treestyletab.html.en#api
The Code can run in many ways. I recommend "workspace addon". Copy My code, choose chrome context to run it.
https://addons.mozilla.org/en-US/firefox/addon/workspace/
// two helper function to get title and url of tab
function getTitle(tab)
{
var brower = gBrowser.getBrowserForTab(tab)
var url = brower.currentURI.spec
var title = brower.contentTitle
return title
}
function getUrl(tab)
{
var brower = gBrowser.getBrowserForTab(tab)
var url = brower.currentURI.spec
var title = brower.contentTitle
return ":PROPERTIES:\n:URL:"+url+"\n:END:\n"
}
var L = gBrowser.tabContainer.childNodes.length //firefox tabs length
var str = "" //global string for output
//parse tabs. If tab has child, parse it. It tab has no child, just output.
for(i = 0; i < L; i++){
level = "*"
tab = gBrowser.tabContainer.childNodes[i]
if ('TreeStyleTabService' in window){
if(TreeStyleTabService.hasChildTabs(tab))
{
str = [str, level, " [+] ", getTitle(tab), "\n", getUrl(tab)].join("") //output title and url. level used in org-mode
treeparse(TreeStyleTabService.getChildTabs(tab), "**") //if a tab has child tabs. parse it and level up
}
str = [str, level, " ", getTitle(tab), "\n", getUrl(tab)].join("")
}
function treeparse(tablist,level) //parse a list of tabs. If tab has not a child, output. If it has childs, parse again
{
for(i=0 ; i < tablist.length;i++) {
tab = tablist[i]
if ('TreeStyleTabService' in window){
if(TreeStyleTabService.hasChildTabs(tab))
{
str = [str, level, " [+] ", getTitle(tab), "\n", getUrl(tab)].join("")
newlevel = level + "*"
treeparse(TreeStyleTabService.getChildTabs(tab),newlevel)
}
} }
str = [str, level, " ", getTitle(tab), "\n", getUrl(tab)].join("")
}
}
alert(str) //alert to view result. You can also write the result into a file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定具体是什么导致了这个问题,因为我无法重现它,但我发现这段代码存在很多问题。我不记得 MozRepl 是如何工作的,但是这个改进的代码应该会给你一个很好的组织模式友好的选项卡输出。我希望这对您或任何偶然发现此线程的人有所帮助。
我希望这会有所帮助。
I'm not sure what's specifically causing the problem, as I couldn't reproduce it, but I see loads of issues with this code. I can't remember how MozRepl works, but this improved code should give you a nice org-mode friendly tab output. I hope this helps you, or whoever stumbles across this thread.
I hope this helps somehow.