-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #793 from Splaxi/impl-new-bookmark
Refactor: Make favoritebookmark work with edge and chrome
- Loading branch information
Showing
5 changed files
with
132 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
|
||
<# | ||
.SYNOPSIS | ||
Set a new bookmark in the browser | ||
.DESCRIPTION | ||
Add a new bookmark to the favorite bar in the browser | ||
Edge and Chrome behaves the same | ||
.PARAMETER PathBrowser | ||
Path to the root folder of the profile in the browser | ||
Only default is tested / handled | ||
.PARAMETER Uri | ||
Uri of the system that you want to add as a bookmark | ||
.PARAMETER Name | ||
Name of the bookmark entry | ||
.EXAMPLE | ||
PS C:\> Set-BrowserBookmark -PathBrowser 'C:\Users\Admin....\AppData\Local\Microsoft\Edge\User Data\Default' -Uri 'https://devdevaos.axcloud.dynamics.com/?cmp=DAT&mi=DefaultDashboard' -Name "D365FO" | ||
This will work against the Edge browser. | ||
The bookmark will be for the 'https://devdevaos.axcloud.dynamics.com/?cmp=DAT&mi=DefaultDashboard' system. | ||
The name will be "D365FO". | ||
.NOTES | ||
Author: Mötz Jensen (@Splaxi) | ||
#> | ||
function Set-BrowserBookmark { | ||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")] | ||
[CmdletBinding()] | ||
param ( | ||
[string] $PathBrowser, | ||
|
||
[string] $Uri, | ||
|
||
[string] $Name | ||
) | ||
|
||
$pathBase = "$PathBrowser" | ||
|
||
if ((Test-PathExists -Path $pathBase -Type Container)) { | ||
$prefRaw = Get-Content -Path "$pathBase\Preferences" -Raw | ||
$prefObj = $prefRaw | ConvertFrom-Json | ||
|
||
if ($null -eq $prefObj.bookmark_bar) { | ||
# Sometimes the needed settings is missing | ||
$prefRaw.Replace(',"browser":', ',"bookmark_bar":{"show_on_all_tabs": true,"show_only_on_ntp":false},"browser":') | Out-File -FilePath "$pathBase\Preferences" -Encoding utf8 -Force | ||
} | ||
else { | ||
$prefObj.bookmark_bar.show_on_all_tabs = $true | ||
$($prefObj | ConvertTo-Json -Depth 10).Replace("`r`n", "") | Out-File -FilePath "$pathBase\Preferences" -Encoding utf8 -Force > $null | ||
} | ||
|
||
if (-not (Test-PathExists -Path "$pathBase\Bookmarks" -Type Leaf)) { | ||
# We might be handling bookmarks / favorites for the first time | ||
Copy-Item -Path "$script:ModuleRoot\internal\misc\Bookmarks" -Destination "$pathBase\Bookmarks" -Force > $null | ||
} | ||
|
||
$favRaw = Get-Content -Path "$pathBase\Bookmarks" -Raw | ||
$favObj = $favRaw | ConvertFrom-Json | ||
|
||
# If any bookmarks already exists - we need to up the counter / id | ||
$id = [int]$($favObj.roots.bookmark_bar.children.id | Sort-Object -Descending | Select-Object -First 1) | ||
$id++ | ||
|
||
$bookMark = [PsCustomObject][Ordered]@{ | ||
guid = [System.Guid]::NewGuid().Guid | ||
id = $id | ||
name = $name | ||
type = "url" | ||
url = $URL | ||
} | ||
|
||
# The children property is an array - which is a fixed size | ||
$children = [System.Collections.Generic.List[System.Object]]::new($favObj.roots.bookmark_bar.children) | ||
|
||
$children.Add($bookMark) | ||
$favObj.roots.bookmark_bar.children = $children.ToArray() | ||
$($favObj | ConvertTo-Json -Depth 10) | Out-File -FilePath "$pathBase\Bookmarks" -Encoding utf8 -Force > $null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"checksum": "a38a604289a5cdc83c5a0397d18a310e", | ||
"roots": { | ||
"bookmark_bar": { | ||
"children": [], | ||
"guid": "0bc5d13f-2cba-5d74-951f-3f233fe6c908", | ||
"id": "1", | ||
"name": "Favourites bar", | ||
"source": "unknown", | ||
"type": "folder" | ||
}, | ||
"other": { | ||
"children": [], | ||
"guid": "82b081ec-3dd3-529c-8475-ab6c344590dd", | ||
"id": "2", | ||
"name": "Other favourites", | ||
"source": "unknown", | ||
"type": "folder" | ||
}, | ||
"synced": { | ||
"children": [], | ||
"guid": "4cf2e351-0e85-532b-bb37-df045d8f8d0f", | ||
"id": "3", | ||
"name": "Mobile favourites", | ||
"source": "unknown", | ||
"type": "folder" | ||
} | ||
}, | ||
"version": 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters