Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/background.js
Original file line number Diff line number Diff line change
@@ -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 [];
};
Expand All @@ -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']
);
8 changes: 4 additions & 4 deletions src/manifest.json
Original file line number Diff line number Diff line change
@@ -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
Expand Down