如何通过命令行在Firefox中添加或删除书签标签?

时间:2021-11-19 21:03:17

I have been looking at the places database and at the Web Extension Bookmarks API but I'm not sure how to do it or if it is possible.

我一直在查看places数据库和Web Extension Bookmarks API,但我不知道该怎么做或者是否可能。

1 个解决方案

#1


2  

I believe that is not possible via the Web Extension Bookmarks API. That is reserved and can be used only within an add-on.

我认为这不可能通过Web Extension Bookmarks API实现。这是保留的,只能在附加组件中使用。

To quote:

JavaScript APIs for WebExtensions can be used inside the extension's background scripts and in any other documents bundled with the extension, including browser action or page action popups, sidebars, options pages, or new tab pages. A few of these APIs can also be accessed by an extension's content scripts (see the list in the content script guide).

用于WebExtensions的JavaScript API可以在扩展程序的后台脚本和与扩展程序捆绑在一起的任何其他文档中使用,包括浏览器操作或页面操作弹出窗口,侧边栏,选项页面或新选项卡页面。扩展程序的内容脚本也可以访问其中一些API(请参阅内容脚本指南中的列表)。

To use the more powerful APIs you need to request permission in your extension's manifest.json

要使用更强大的API,您需要在扩展程序的manifest.json中请求权限

I don't know if you are on windows or *nix. The general idea would be to manipulate the SQLite database.

我不知道你是在Windows还是* nix。一般的想法是操纵SQLite数据库。

For bookmarks you need a file called places.sqlite which you can find on windows at - C:\Users\login\AppData\Roaming\Mozilla\Firefox\Profiles

对于书签,您需要一个名为places.sqlite的文件,您可以在Windows上找到它 - C:\ Users \ login \ AppData \ Roaming \ Mozilla \ Firefox \ Profiles

On *nix you can do:

在* nix上你可以这样做:

find . -name 'places.sqlite' and usually you will get it somewhere in your home:

找 。 -name'sites.sqlite'通常你会在你家的某个地方找到它:

e.g. /home/tukanos/.mozilla/firefox/tf8oiuhk.default/places.sqlite

I'll cover only windows & powershell now (you can do that also for *nix):

I think it is also good idea to follow a best practices guide for the places.sqlfile. Be sure to read it before you start changing the file.

我认为遵循places.sqlfile的最佳实践指南也是个好主意。在开始更改文件之前,请务必阅读它。

NOTE: make backup of your places.sqlite before playing with it!

注意:在玩之前备份你的places.sqlite!

In powershell you would

在powershell中,你会

Import-Module pssqlite 

(Download the module here if you are using PS version < 5.0)

(如果您使用PS版本<5.0,请在此处下载模块)

Then get your path for places.sqlite

然后获取places.sqlite的路径

$db = 'C:\Users\login\AppData\Roaming\Mozilla\Firefox\Profiles\tf8oiuhk.default\places.sqlite'

To query the sql database:

要查询sql数据库:

$sqlFirefoxQuery = "SELECT places.id, 
                           places.URL,
                           places.GUID,
                           bookmarks.title,
                           bookmarks.id,
                           bookmarks.parent
                      FROM moz_places as places
                      JOIN moz_bookmarks as bookmarks 
                        ON places.id = bookmarks.fk"


Invoke-SqliteQuery -DataSource $db -QueryTimeout 20 -Query $sqlFirefoxQuery | Out-file -Encoding UTF8 Bookmarks_firefox.txt

The logic is the same for inserting, updating, deleting data.

插入,更新,删除数据的逻辑相同。

Below you can find example of insert and delete as that was your question.

下面你可以找到插入和删除的例子,因为这是你的问题。

To insert data use sql INSERT INTO For example:

要插入数据,请使用sql INSERT INTO例如:

insert into moz_bookmarks (attributes) VALUES (your_values), (next_values)

e.g.

INSERT INTO moz_bookmarks (type, parent, title, dateAdded)  
     VALUES (1,5,'MyBookmark',CURRENT_TIMESTAMP)

To remove values you should use sql's delete:

要删除值,您应该使用sql的删除:

DELETE FROM from moz_places
     WHERE id=1112

(don't forget to close your Firefox)

(别忘了关闭你的Firefox)

Use your database link - to find the attributes: https://developer.mozilla.org/en-US/docs/Mozilla/Tech/Places/Database

使用数据库链接 - 查找属性:https://developer.mozilla.org/en-US/docs/Mozilla/Tech/Places/Database

Edit - How to get a tag from sqlite DB?

To simply list all tabs in the bookmarks directory:

要简单地列出书签目录中的所有选项卡:

select * from moz_bookmarks where parent=4

explanation: This will get you all the bookmarks stored in your places.sqlite file. The tags are stored in the column title the TAGs folder has id=4

解释:这将为您提供存储在places.sqlite文件中的所有书签。标签存储在TAGs文件夹id = 4的列标题中

You can check the ID from in table moz_bookmarks_roots:

您可以在表moz_bookmarks_roots中查看ID:

╔═══╦═════════════════╦═══════════════╗
║   ║ root_name       ║ folder_id     ║
╠═══╬═════════════════╬═══════════════╣
║ 1 ║ places          ║   1           ║
║ 2 ║ menu            ║   2           ║
║ 3 ║ toolbar         ║   3           ║
║ 4 ║ tags            ║   4           ║
║ 5 ║ unfiled         ║   5           ║
╚═══╩═════════════════╩═══════════════╝

Now how to find a tag with certain bookmarks?

现在如何找到带有某些书签的标签?

  1. First find your bookmark which you want to work with e.g. title from this question "%How can I add or remove a bookmark tag%"

    首先找到您要使用的书签,例如此问题的标题“%我如何添加或删除书签标签%”

    SELECT * FROM moz_places where title LIKE '%How can I add or remove a bookmark tag%'
    

The result:

id              : 20079
url             : https://*.com/questions/51124179/how-can-i-add-or-remove-a-bookmark-tag-in-firefox-via-the-command-line/51264053?noredirect=1#
                  comment89523757_51264053
title           : How can I add or remove a bookmark tag in Firefox via the command line? - Stack Overflow
rev_host        : moc.wolfrevokcats.
visit_count     : 1
hidden          : 0
typed           : 0
favicon_id      : 238
frecency        : 125
last_visit_date : 1531301813682000
guid            : w6vYlxdKQU6V
foreign_count   : 2
url_hash        : 47357855952022
  1. Then you go to moz_bookmarks table where you can find the actual records (id from moz_places is fk from moz_bookmarks).

    然后你去moz_bookmarks表,在那里你可以找到实际记录(来自moz_places的id是来自moz_bookmarks的fk)。

    select * from moz_bookmarks where fk=20079
    

This result:

    id           : 76
    type         : 1
    fk           : 20079
    parent       : 75
    position     : 0
    title        : How can I add or remove a bookmark tag in Firefox via the command line? - Stack Overflow
    keyword_id   :
    folder_type  :
    dateAdded    : 1531298577890000
    lastModified : 1531298577894000
    guid         : R0961JLfZYKj

    id           : 78
    type         : 1
    fk           : 20079
    parent       : 77
    position     : 0
    title        :
    keyword_id   :
    folder_type  :
    dateAdded    : 1531298593884000
    lastModified : 1531298593884000
    guid         : BW__oMQbHerd

As you see you get two records. One has parent=75 which is the bookmark folder. Second one is a mapping of fk=20079 (id) to parent=77 which are the actual tag(s):

如你所见,你得到两条记录。一个有parent = 75,这是书签文件夹。第二个是fk = 20079(id)到parent = 77的映射,它们是实际的标记:

    SELECT * FROM moz_bookmarks where id = 77

Where you get the tags in the title attribute:

在title属性中获取标记的位置:

    id           : 77
    type         : 2
    fk           :
    parent       : 4
    position     : 0
    title        : stack_overflow test
    keyword_id   :
    folder_type  :
    dateAdded    : 1531298593878000
    lastModified : 1531298593884000
    guid         : AVcyFpGkrfzV

So the tags in my case were: stack_overflow test

所以我的案例中的标签是:stack_overflow test

The E-R schema for places.sqlite you can find here.

您可以在这里找到places.sqlite的E-R架构。

Edit 2 Forgot to answer the question directly.

When changing the sqlite database close Firefox instance.

更改sqlite数据库时关闭Firefox实例。

To add a tag - you have to understand the logic (I have to pick a new bookmark which has no tags yet):

要添加标记 - 您必须了解逻辑(我必须选择一个没有标记的新书签):

First to create I have to have a new bookmark

首先要创建我必须有一个新的书签

$sqlFirefoxQuery = "SELECT * FROM moz_places where title LIKE '%Cnn%'"

PS C:\> Invoke-SqliteQuery -DataSource $db -QueryTimeout 20 -Query $sqlFirefoxQuery


id              : 20223
url             : https://edition.cnn.com/
title           : CNN International - Breaking News, US News, World News and Video
rev_host        : moc.nnc.noitide.
visit_count     : 1
hidden          : 0
typed           : 0
favicon_id      : 2015
frecency        : 75
last_visit_date : 1531392673997000
guid            : qqCRafq4FIcn
foreign_count   : 1
url_hash        : 47358730651511

Then I select from moz_bookmarks table:

然后我从moz_bookmarks表中选择:

$sqlFirefoxQuery = "select * from moz_bookmarks where fk=20223"
PS C:\> Invoke-SqliteQuery -DataSource $db -QueryTimeout 20 -Query $sqlFirefoxQuery

id           : 79
type         : 1
fk           : 20223
parent       : 75
position     : 1
title        : CNN International - Breaking News, US News, World News and Video
keyword_id   :
folder_type  :
dateAdded    : 1531392718191000
lastModified : 1531392718197000
guid         : 2ywnKBmbDWJI

As you see there is only one record instead of two (check above the section where I select the moz_bookmarks and find two records)

如您所见,只有一个记录而不是两个(在我选择moz_bookmarks并查找两条记录的部分上方检查)

You then have to find out a free id(s) at table moz_bookmarks. In my case it is id=80 and id=81 (can be different in your case):

然后你必须在表moz_bookmarks找到一个免费的id。在我的情况下,它是id = 80和id = 81(在你的情况下可以是不同的):

Now comes the tricky part where you have to get GUID. You can get one via GUI - SQLite Manager and its SELECT GENERATE_GUID(). However, we need one without gui so we have to create it.

现在是你需要获得GUID的棘手部分。您可以通过GUI获得一个 - SQLite Manager及其SELECT GENERATE_GUID()。但是,我们需要一个没有gui的人,所以我们必须创建它。

If you check the gecko's python makeGuid() function you will see that they are using md5, hex. I will do it with similar functions hex() and randomblob().

如果你检查gecko的python makeGuid()函数,你会发现它们正在使用md5,hex。我将使用类似函数hex()和randomblob()来完成它。

First to generate the tag record: Then the record itself (type=2, parent=4):

首先生成标记记录:然后记录本身(type = 2,parent = 4):

id           : 80
type         : 2
fk           :
parent       : 4
position     : 0
title        : news insert_firefox_tag_example
keyword_id   :
folder_type  :
dateAdded    : 1531298593878000
lastModified : 1531298593884000
guid         : <generated_GUID>

The actual insert:

实际插入:

$sqlFirefoxQuery = "INSERT INTO moz_bookmarks (id, type, parent, position, title, dateAdded, lastModified, guid)
     VALUES (80,
             2,
             4,
             0,
             'news insert_firefox_tag_example',
             strftime('%s',CURRENT_TIMESTAMP)*1000000,
             strftime('%s',CURRENT_TIMESTAMP)*1000000,
             hex(randomblob(2)) || hex(randomblob(2)) || hex(randomblob(2)))"

Then you have to create the record that links it:

然后你必须创建链接它的记录:

    id          : 81
    type       : 1
    fk          : 20223
    parent       : 80
    position     : 0
    title        :
    keyword_id   :
    folder_type  :
    dateAdded    : 1531298593884000
    lastModified : 1531298593884000
    guid         : <generated_GUID>

The actual insert:

实际插入:

$sqlFirefoxQuery = "INSERT INTO moz_bookmarks (id, type, fk, parent, position, dateAdded, lastModified, guid)
     VALUES (81,
             1,
             20223,
             80,
             0,
             strftime('%s',CURRENT_TIMESTAMP)*1000000,
             strftime('%s',CURRENT_TIMESTAMP)*1000000,
             hex(randomblob(2)) || hex(randomblob(2)) || hex(randomblob(2)))"

Now you can check your record where you have added two new tags news insert_firefox_tag_example.

现在,您可以检查记录,其中添加了两个新标签news insert_firefox_tag_example。

To update a tag with new_tag (you have to add the current tags too!):

要使用new_tag更新标记(您还必须添加当前标记!):

$sqlFirefoxQuery = "UPDATE moz_bookmarks
                       SET title = 'stack_overflow test new_tag' 
                     WHERE id = 77"

Then execute it:

然后执行它:

Invoke-SqliteQuery -DataSource $db -QueryTimeout 20 -Query $sqlFirefoxQuery

You will get updated tags:

您将获得更新的标签:

PS C:\> $sqlFirefoxQuery = "SELECT * FROM moz_bookmarks where id = 77"
PS C:\> Invoke-SqliteQuery -DataSource $db -QueryTimeout 20 -Query $sqlFirefoxQuery


id           : 77
type         : 2
fk           :
parent       : 4
position     : 0
title        : stack_overflow test new_tag
keyword_id   :
folder_type  :
dateAdded    : 1531298593878000
lastModified : 1531298593884000
guid         : AVcyFpGkrfzV

To remove the tags you can do simply put an empty string (don't forget that the changes will be probably seen after Firefox restart):

要删除标记,您只需放置一个空字符串(不要忘记在Firefox重启后可能会看到更改):

$sqlFirefoxQuery = "UPDATE moz_bookmarks
                       SET title = '' 
                     WHERE id = 77"

The result:

PS C:\> $sqlFirefoxQuery = "SELECT * FROM moz_bookmarks where id = 77"
PS C:\> Invoke-SqliteQuery -DataSource $db -QueryTimeout 20 -Query $sqlFirefoxQuery


id           : 77
type         : 2
fk           :
parent       : 4
position     : 0
title        :
keyword_id   :
folder_type  :
dateAdded    : 1531298593878000
lastModified : 1531298593884000
guid         : AVcyFpGkrfzV

So that is it.

就是这样。

#1


2  

I believe that is not possible via the Web Extension Bookmarks API. That is reserved and can be used only within an add-on.

我认为这不可能通过Web Extension Bookmarks API实现。这是保留的,只能在附加组件中使用。

To quote:

JavaScript APIs for WebExtensions can be used inside the extension's background scripts and in any other documents bundled with the extension, including browser action or page action popups, sidebars, options pages, or new tab pages. A few of these APIs can also be accessed by an extension's content scripts (see the list in the content script guide).

用于WebExtensions的JavaScript API可以在扩展程序的后台脚本和与扩展程序捆绑在一起的任何其他文档中使用,包括浏览器操作或页面操作弹出窗口,侧边栏,选项页面或新选项卡页面。扩展程序的内容脚本也可以访问其中一些API(请参阅内容脚本指南中的列表)。

To use the more powerful APIs you need to request permission in your extension's manifest.json

要使用更强大的API,您需要在扩展程序的manifest.json中请求权限

I don't know if you are on windows or *nix. The general idea would be to manipulate the SQLite database.

我不知道你是在Windows还是* nix。一般的想法是操纵SQLite数据库。

For bookmarks you need a file called places.sqlite which you can find on windows at - C:\Users\login\AppData\Roaming\Mozilla\Firefox\Profiles

对于书签,您需要一个名为places.sqlite的文件,您可以在Windows上找到它 - C:\ Users \ login \ AppData \ Roaming \ Mozilla \ Firefox \ Profiles

On *nix you can do:

在* nix上你可以这样做:

find . -name 'places.sqlite' and usually you will get it somewhere in your home:

找 。 -name'sites.sqlite'通常你会在你家的某个地方找到它:

e.g. /home/tukanos/.mozilla/firefox/tf8oiuhk.default/places.sqlite

I'll cover only windows & powershell now (you can do that also for *nix):

I think it is also good idea to follow a best practices guide for the places.sqlfile. Be sure to read it before you start changing the file.

我认为遵循places.sqlfile的最佳实践指南也是个好主意。在开始更改文件之前,请务必阅读它。

NOTE: make backup of your places.sqlite before playing with it!

注意:在玩之前备份你的places.sqlite!

In powershell you would

在powershell中,你会

Import-Module pssqlite 

(Download the module here if you are using PS version < 5.0)

(如果您使用PS版本<5.0,请在此处下载模块)

Then get your path for places.sqlite

然后获取places.sqlite的路径

$db = 'C:\Users\login\AppData\Roaming\Mozilla\Firefox\Profiles\tf8oiuhk.default\places.sqlite'

To query the sql database:

要查询sql数据库:

$sqlFirefoxQuery = "SELECT places.id, 
                           places.URL,
                           places.GUID,
                           bookmarks.title,
                           bookmarks.id,
                           bookmarks.parent
                      FROM moz_places as places
                      JOIN moz_bookmarks as bookmarks 
                        ON places.id = bookmarks.fk"


Invoke-SqliteQuery -DataSource $db -QueryTimeout 20 -Query $sqlFirefoxQuery | Out-file -Encoding UTF8 Bookmarks_firefox.txt

The logic is the same for inserting, updating, deleting data.

插入,更新,删除数据的逻辑相同。

Below you can find example of insert and delete as that was your question.

下面你可以找到插入和删除的例子,因为这是你的问题。

To insert data use sql INSERT INTO For example:

要插入数据,请使用sql INSERT INTO例如:

insert into moz_bookmarks (attributes) VALUES (your_values), (next_values)

e.g.

INSERT INTO moz_bookmarks (type, parent, title, dateAdded)  
     VALUES (1,5,'MyBookmark',CURRENT_TIMESTAMP)

To remove values you should use sql's delete:

要删除值,您应该使用sql的删除:

DELETE FROM from moz_places
     WHERE id=1112

(don't forget to close your Firefox)

(别忘了关闭你的Firefox)

Use your database link - to find the attributes: https://developer.mozilla.org/en-US/docs/Mozilla/Tech/Places/Database

使用数据库链接 - 查找属性:https://developer.mozilla.org/en-US/docs/Mozilla/Tech/Places/Database

Edit - How to get a tag from sqlite DB?

To simply list all tabs in the bookmarks directory:

要简单地列出书签目录中的所有选项卡:

select * from moz_bookmarks where parent=4

explanation: This will get you all the bookmarks stored in your places.sqlite file. The tags are stored in the column title the TAGs folder has id=4

解释:这将为您提供存储在places.sqlite文件中的所有书签。标签存储在TAGs文件夹id = 4的列标题中

You can check the ID from in table moz_bookmarks_roots:

您可以在表moz_bookmarks_roots中查看ID:

╔═══╦═════════════════╦═══════════════╗
║   ║ root_name       ║ folder_id     ║
╠═══╬═════════════════╬═══════════════╣
║ 1 ║ places          ║   1           ║
║ 2 ║ menu            ║   2           ║
║ 3 ║ toolbar         ║   3           ║
║ 4 ║ tags            ║   4           ║
║ 5 ║ unfiled         ║   5           ║
╚═══╩═════════════════╩═══════════════╝

Now how to find a tag with certain bookmarks?

现在如何找到带有某些书签的标签?

  1. First find your bookmark which you want to work with e.g. title from this question "%How can I add or remove a bookmark tag%"

    首先找到您要使用的书签,例如此问题的标题“%我如何添加或删除书签标签%”

    SELECT * FROM moz_places where title LIKE '%How can I add or remove a bookmark tag%'
    

The result:

id              : 20079
url             : https://*.com/questions/51124179/how-can-i-add-or-remove-a-bookmark-tag-in-firefox-via-the-command-line/51264053?noredirect=1#
                  comment89523757_51264053
title           : How can I add or remove a bookmark tag in Firefox via the command line? - Stack Overflow
rev_host        : moc.wolfrevokcats.
visit_count     : 1
hidden          : 0
typed           : 0
favicon_id      : 238
frecency        : 125
last_visit_date : 1531301813682000
guid            : w6vYlxdKQU6V
foreign_count   : 2
url_hash        : 47357855952022
  1. Then you go to moz_bookmarks table where you can find the actual records (id from moz_places is fk from moz_bookmarks).

    然后你去moz_bookmarks表,在那里你可以找到实际记录(来自moz_places的id是来自moz_bookmarks的fk)。

    select * from moz_bookmarks where fk=20079
    

This result:

    id           : 76
    type         : 1
    fk           : 20079
    parent       : 75
    position     : 0
    title        : How can I add or remove a bookmark tag in Firefox via the command line? - Stack Overflow
    keyword_id   :
    folder_type  :
    dateAdded    : 1531298577890000
    lastModified : 1531298577894000
    guid         : R0961JLfZYKj

    id           : 78
    type         : 1
    fk           : 20079
    parent       : 77
    position     : 0
    title        :
    keyword_id   :
    folder_type  :
    dateAdded    : 1531298593884000
    lastModified : 1531298593884000
    guid         : BW__oMQbHerd

As you see you get two records. One has parent=75 which is the bookmark folder. Second one is a mapping of fk=20079 (id) to parent=77 which are the actual tag(s):

如你所见,你得到两条记录。一个有parent = 75,这是书签文件夹。第二个是fk = 20079(id)到parent = 77的映射,它们是实际的标记:

    SELECT * FROM moz_bookmarks where id = 77

Where you get the tags in the title attribute:

在title属性中获取标记的位置:

    id           : 77
    type         : 2
    fk           :
    parent       : 4
    position     : 0
    title        : stack_overflow test
    keyword_id   :
    folder_type  :
    dateAdded    : 1531298593878000
    lastModified : 1531298593884000
    guid         : AVcyFpGkrfzV

So the tags in my case were: stack_overflow test

所以我的案例中的标签是:stack_overflow test

The E-R schema for places.sqlite you can find here.

您可以在这里找到places.sqlite的E-R架构。

Edit 2 Forgot to answer the question directly.

When changing the sqlite database close Firefox instance.

更改sqlite数据库时关闭Firefox实例。

To add a tag - you have to understand the logic (I have to pick a new bookmark which has no tags yet):

要添加标记 - 您必须了解逻辑(我必须选择一个没有标记的新书签):

First to create I have to have a new bookmark

首先要创建我必须有一个新的书签

$sqlFirefoxQuery = "SELECT * FROM moz_places where title LIKE '%Cnn%'"

PS C:\> Invoke-SqliteQuery -DataSource $db -QueryTimeout 20 -Query $sqlFirefoxQuery


id              : 20223
url             : https://edition.cnn.com/
title           : CNN International - Breaking News, US News, World News and Video
rev_host        : moc.nnc.noitide.
visit_count     : 1
hidden          : 0
typed           : 0
favicon_id      : 2015
frecency        : 75
last_visit_date : 1531392673997000
guid            : qqCRafq4FIcn
foreign_count   : 1
url_hash        : 47358730651511

Then I select from moz_bookmarks table:

然后我从moz_bookmarks表中选择:

$sqlFirefoxQuery = "select * from moz_bookmarks where fk=20223"
PS C:\> Invoke-SqliteQuery -DataSource $db -QueryTimeout 20 -Query $sqlFirefoxQuery

id           : 79
type         : 1
fk           : 20223
parent       : 75
position     : 1
title        : CNN International - Breaking News, US News, World News and Video
keyword_id   :
folder_type  :
dateAdded    : 1531392718191000
lastModified : 1531392718197000
guid         : 2ywnKBmbDWJI

As you see there is only one record instead of two (check above the section where I select the moz_bookmarks and find two records)

如您所见,只有一个记录而不是两个(在我选择moz_bookmarks并查找两条记录的部分上方检查)

You then have to find out a free id(s) at table moz_bookmarks. In my case it is id=80 and id=81 (can be different in your case):

然后你必须在表moz_bookmarks找到一个免费的id。在我的情况下,它是id = 80和id = 81(在你的情况下可以是不同的):

Now comes the tricky part where you have to get GUID. You can get one via GUI - SQLite Manager and its SELECT GENERATE_GUID(). However, we need one without gui so we have to create it.

现在是你需要获得GUID的棘手部分。您可以通过GUI获得一个 - SQLite Manager及其SELECT GENERATE_GUID()。但是,我们需要一个没有gui的人,所以我们必须创建它。

If you check the gecko's python makeGuid() function you will see that they are using md5, hex. I will do it with similar functions hex() and randomblob().

如果你检查gecko的python makeGuid()函数,你会发现它们正在使用md5,hex。我将使用类似函数hex()和randomblob()来完成它。

First to generate the tag record: Then the record itself (type=2, parent=4):

首先生成标记记录:然后记录本身(type = 2,parent = 4):

id           : 80
type         : 2
fk           :
parent       : 4
position     : 0
title        : news insert_firefox_tag_example
keyword_id   :
folder_type  :
dateAdded    : 1531298593878000
lastModified : 1531298593884000
guid         : <generated_GUID>

The actual insert:

实际插入:

$sqlFirefoxQuery = "INSERT INTO moz_bookmarks (id, type, parent, position, title, dateAdded, lastModified, guid)
     VALUES (80,
             2,
             4,
             0,
             'news insert_firefox_tag_example',
             strftime('%s',CURRENT_TIMESTAMP)*1000000,
             strftime('%s',CURRENT_TIMESTAMP)*1000000,
             hex(randomblob(2)) || hex(randomblob(2)) || hex(randomblob(2)))"

Then you have to create the record that links it:

然后你必须创建链接它的记录:

    id          : 81
    type       : 1
    fk          : 20223
    parent       : 80
    position     : 0
    title        :
    keyword_id   :
    folder_type  :
    dateAdded    : 1531298593884000
    lastModified : 1531298593884000
    guid         : <generated_GUID>

The actual insert:

实际插入:

$sqlFirefoxQuery = "INSERT INTO moz_bookmarks (id, type, fk, parent, position, dateAdded, lastModified, guid)
     VALUES (81,
             1,
             20223,
             80,
             0,
             strftime('%s',CURRENT_TIMESTAMP)*1000000,
             strftime('%s',CURRENT_TIMESTAMP)*1000000,
             hex(randomblob(2)) || hex(randomblob(2)) || hex(randomblob(2)))"

Now you can check your record where you have added two new tags news insert_firefox_tag_example.

现在,您可以检查记录,其中添加了两个新标签news insert_firefox_tag_example。

To update a tag with new_tag (you have to add the current tags too!):

要使用new_tag更新标记(您还必须添加当前标记!):

$sqlFirefoxQuery = "UPDATE moz_bookmarks
                       SET title = 'stack_overflow test new_tag' 
                     WHERE id = 77"

Then execute it:

然后执行它:

Invoke-SqliteQuery -DataSource $db -QueryTimeout 20 -Query $sqlFirefoxQuery

You will get updated tags:

您将获得更新的标签:

PS C:\> $sqlFirefoxQuery = "SELECT * FROM moz_bookmarks where id = 77"
PS C:\> Invoke-SqliteQuery -DataSource $db -QueryTimeout 20 -Query $sqlFirefoxQuery


id           : 77
type         : 2
fk           :
parent       : 4
position     : 0
title        : stack_overflow test new_tag
keyword_id   :
folder_type  :
dateAdded    : 1531298593878000
lastModified : 1531298593884000
guid         : AVcyFpGkrfzV

To remove the tags you can do simply put an empty string (don't forget that the changes will be probably seen after Firefox restart):

要删除标记,您只需放置一个空字符串(不要忘记在Firefox重启后可能会看到更改):

$sqlFirefoxQuery = "UPDATE moz_bookmarks
                       SET title = '' 
                     WHERE id = 77"

The result:

PS C:\> $sqlFirefoxQuery = "SELECT * FROM moz_bookmarks where id = 77"
PS C:\> Invoke-SqliteQuery -DataSource $db -QueryTimeout 20 -Query $sqlFirefoxQuery


id           : 77
type         : 2
fk           :
parent       : 4
position     : 0
title        :
keyword_id   :
folder_type  :
dateAdded    : 1531298593878000
lastModified : 1531298593884000
guid         : AVcyFpGkrfzV

So that is it.

就是这样。