Skip to content

Commit e1b807f

Browse files
Chi-IrohThomas Sayen
authored andcommitted
Updated URL search params manipulation
1 parent e3e36af commit e1b807f

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

web_src/js/features/repo-commit.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,13 @@ export function initCommitFileHistoryFollowRename() {
3131
if (!checkbox) {
3232
return;
3333
}
34-
checkbox.checked = location.toString().includes('history_follow_rename=true');
34+
const url = new URL(window.location.toString());
35+
checkbox.checked = url.searchParams.has('history_follow_rename', 'true');
3536

3637
checkbox.addEventListener('change', () => {
37-
let url = location.toString();
38+
const url = new URL(location.toString());
3839

39-
url = url.replaceAll(/history_follow_rename=(true|false)&*/g, '');
40-
if (url.endsWith('?')) {
41-
url = url.slice(0, -1);
42-
}
43-
if (url.includes('?')) {
44-
url += '&';
45-
} else {
46-
url += '?';
47-
}
48-
49-
url += `history_follow_rename=${checkbox.checked}`;
50-
window.location.href = url;
40+
url.searchParams.set('history_follow_rename', `${checkbox.checked}`);
41+
window.location.replace(url);
5142
});
5243
}

0 commit comments

Comments
 (0)