diff --git a/src/background.js b/src/background.js index 6a71d20..6142f8e 100644 --- a/src/background.js +++ b/src/background.js @@ -1,9 +1,9 @@ -const regex = /(.*docs.microsoft.com\/)([a-z][a-z]\-[a-z][a-z]]*)(\/.*)/g; +const regex = /(.*(learn\.microsoft\.com|docs\.microsoft\.com)\/)([a-z][a-z]-[a-z][a-z])(\/.*)/g; -function getFirstGroup(regexp, str) { +function getLocalizationGroup(regexp, str) { return Array.from(str.matchAll(regexp), m => { - if (m.length > 2){ - return m[2] + if (m.length > 3){ + return m[3] } else{ return []; }; @@ -12,10 +12,10 @@ function getFirstGroup(regexp, str) { chrome.webRequest.onBeforeRequest.addListener( function(details) { - var group = getFirstGroup(regex, details.url); + var group = getLocalizationGroup(regex, details.url); if (group.length > 0 && group[0].toLowerCase() != "en-us"){ - var newUrl = details.url.replace(regex, "$1en-us$3"); + var newUrl = details.url.replace(regex, "$1en-us$4"); return { redirectUrl: newUrl } } - }, { urls: ['*://docs.microsoft.com/*'] }, ['blocking'] + }, { urls: ['*://docs.microsoft.com/*', '*://learn.microsoft.com/*'] }, ['blocking'] ); \ No newline at end of file diff --git a/src/manifest.json b/src/manifest.json index beea338..e89d5a9 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -1,8 +1,8 @@ { - "name": "Docs.com Redirect to en-US", - "version": "0.2", - "description": "Auto-redirect to en-US version of Microsoft Docs.", - "permissions": ["background", "tabs", "webRequest", "webRequestBlocking", "*://docs.microsoft.com/*"], + "name": "Microsoft Docs and Learn Redirect to en-US", + "version": "0.3", + "description": "Auto-redirect to en-US version of Microsoft Docs and Microsoft Learn.", + "permissions": ["background", "tabs", "webRequest", "webRequestBlocking", "*://docs.microsoft.com/*", "*://learn.microsoft.com/*"], "background": { "scripts": ["background.js"], "persistent": true