我想自动计算Firefox中打开的标签数量,以便我可以随时跟踪.
因此,我可以获得一个在状态栏或浏览器中的其他位置显示当前数字的加载项是不够的.
我已经查看了firefox为每个配置文件保存的.sqlite表的内容,但是我无法解读是否存在当前打开的选项卡表.我还查看了历史表中是否有一个列,告诉该页面当前是否打开.
这些信息是否在数据库中可用?
如果是,那么存储的信息在哪里可用于计算当前打开的选项卡的数量?
如果没有,像Tab Counter这样的附加组件如何找到这个数字?我将向开发人员提出的最后一个问题,如果它不是常见的知识,我可以在这里得到答案,而不是要求那些可能希望你使用他或她的附加组件的人.
ave*_*rin 14
打开about:telemetry链接.
在下面,scalars您将找到browser.engagement.max_concurrent_tab_count其值为您提供打开的标签数量的键.
在正在运行的Firefox会话中,使用Mozilla Add-on API可以轻松提取数据.我写了一个简单的Tab Count Logger扩展,它执行此操作,并将计数保存到SQLite数据库.
代码的相关部分是:
const tabs = require("sdk/tabs");
const windows = require("sdk/windows").browserWindows;
console.log("Windows: " + windows.length + "; tabs: " + tabs.length);
Run Code Online (Sandbox Code Playgroud)
打开的选项卡存储在sessionstore.js配置文件目录中,而不是存储在SQLite中.这个文件是JSON.计算标签的脚本:
#!/usr/bin/env python3
# Count open tabs from a firefox profile
# Working directory is the root of a Firefox profile.
import json
j = json.loads(open("sessionstore.js", 'rb').read().decode('utf-8'))
def info_for_tab(tab):
try:
return (tab['entries'][0]['url'], tab['entries'][0]['title'])
except IndexError:
return None
except KeyError:
return None
def tabs_from_windows(window):
return list(map(info_for_tab, window['tabs']))
all_tabs = list(map(tabs_from_windows, j['windows']))
print('Statistics: {wins} windows, {tabs} total tabs'.format(wins=len(all_tabs), tabs=sum(map(len, all_tabs))))
Run Code Online (Sandbox Code Playgroud)
保存完成后~/bin/firefox_count_tabs,您可以获取所有配置文件的信息,如下所示:
for i in ~/.mozilla/firefox/*.*; do test -d $i && (echo "== $i =="; cd $i; ~/bin/firefox_count_tabs ); done
Run Code Online (Sandbox Code Playgroud)
小智 6
您可以使用以下方法对浏览器控制台(而非 Web 控制台)中的选项卡进行计数:
gBrowser.tabs.length
Run Code Online (Sandbox Code Playgroud)
默认情况下禁用浏览器控制台。要启用它,您可以:
"Enable browser chrome and add-on debugging toolboxes"勾选Web 开发人员工具设置中的选项。about:config并搜索devtools.chrome.enabled,并将其切换为true。之后在更多工具菜单中查找浏览器控制台,或者使用 打开开发者控制台,现在您可以输入上面的内容。[CTRL]+[SHIFT]+J
option-1
option-2
[CTRL]+[SHIFT]+J
小智 2
@Xidus:历史记录和书签存储在places.sqlite中。这里你无法确定tabs和windows信息。tabs和windows信息存储在sessionstore.js文件中。你可以参考这个链接:
http://kb.mozillazine.org/sessionstore.js http://forums.mozillazine.org/viewtopic.php?f=38&t=622036&start=60&p=12098147#p12098147
| 归档时间: |
|
| 查看次数: |
3598 次 |
| 最近记录: |