Skip to content

Commit

Permalink
【Microsoft & Xbox 网站地区&语言快捷切换】修复apps.microsoft.com商店页的地区参数位置识别有误导致跳转错…
Browse files Browse the repository at this point in the history
…误的问题;
  • Loading branch information
LonelyWindG committed Nov 11, 2023
1 parent 6124d9e commit 416a55e
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions ms_xbox_switch_region.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ function change(code)
return;
}

window.location.href = url.replace(urlRegion, code);
url = url.replace(urlRegion, code);
window.location.href = url;
}

function changeSpecialAppsUrl(url, code)
Expand All @@ -87,8 +88,20 @@ function changeSpecialAppsUrl(url, code)
var gl = url.substring(glIndex, glIndex + 2).toUpperCase();
var region = (code[3] + code[4]).toUpperCase();

var parmIndex = url.lastIndexOf("?hl=");
var hlIndex = parmIndex + "?hl=".length;
var parmStart = "?hl=";
var parmIndex = url.lastIndexOf(parmStart);
if (parmIndex == -1)
{
parmStart = "&hl=";
parmIndex = url.lastIndexOf(parmStart);
if (parmIndex == -1)
{
alert("识别URL中的语言地区参数失败, 无法切换");
return;
}
}

var hlIndex = parmIndex + parmStart.length;
var hl = url.substring(hlIndex, hlIndex + 5).toLowerCase();
code = code.toLowerCase();

Expand All @@ -113,7 +126,7 @@ function changeSpecialAppsUrl(url, code)

hl = change_hl ? code : hl;
gl = change_gl ? region : gl;
url = url.substring(0, parmIndex) + "?hl=" + hl + "&gl=" + gl;
url = url.substring(0, parmIndex) + parmStart + hl + "&gl=" + gl;

window.location.href = url;
}

0 comments on commit 416a55e

Please sign in to comment.