1
- const enabledPages = [ "/communities" , "c/[^/]+/?$" ] ;
1
+ // const enabledPages = ["/communities", "c/[^/]+/?$"];
2
2
3
3
type UrlStructure = {
4
4
protocol : string ;
@@ -54,6 +54,13 @@ async function checkBetaRedirect(
54
54
beta : UrlStructure ,
55
55
goToBetaRoR2 : boolean
56
56
) {
57
+ const legacyOnlyPages = [
58
+ "/settings" ,
59
+ "/package/create" ,
60
+ "c/[^/]+/p/[^/]+/[^/]+/wiki/?$" ,
61
+ "c/[^/]+/p/[^/]+/[^/]+/source/?$" ,
62
+ ] ;
63
+
57
64
if ( goToBetaRoR2 ) {
58
65
// Don't include the search params as those differ in projects and are not handled gracefully
59
66
window . location . assign (
@@ -63,31 +70,44 @@ async function checkBetaRedirect(
63
70
) ;
64
71
} else {
65
72
let switchProject = legacy ;
73
+ let path = window . location . pathname ;
66
74
67
75
if ( window . location . hostname === beta . hostname ) {
68
76
switchProject = legacy ;
69
77
} else if ( window . location . hostname === legacy . hostname ) {
70
78
switchProject = beta ;
79
+ legacyOnlyPages . forEach ( ( regPath ) => {
80
+ const regExecuted = new RegExp ( regPath ) . exec ( window . location . pathname ) ;
81
+ const found = regExecuted !== null && regExecuted . length < 2 ;
82
+ if ( found ) {
83
+ path = "/communities" ;
84
+ }
85
+ } ) ;
86
+ // legacyOnlyPages.forEach((lop) => {
87
+ // if (window.location.pathname.startsWith(lop)) {
88
+ // path = "/";
89
+ // }
90
+ // });
71
91
}
72
92
73
93
// Don't include the search params as those differ in projects and are not handled gracefully
74
94
window . location . assign (
75
95
`${ switchProject . protocol } ${ switchProject . hostname } ${
76
96
switchProject . port !== "" ? ":" : ""
77
- } ${ switchProject . port } ${ window . location . pathname } `
97
+ } ${ switchProject . port } ${ path } `
78
98
) ;
79
99
}
80
100
}
81
101
82
102
async function insertSwitchButton ( legacy : UrlStructure , beta : UrlStructure ) {
83
- let betaIsAvailable = false ;
84
- enabledPages . forEach ( ( regPath ) => {
85
- const regExecuted = new RegExp ( regPath ) . exec ( window . location . pathname ) ;
86
- const found = regExecuted !== null && regExecuted . length < 2 ;
87
- if ( ! betaIsAvailable && found ) {
88
- betaIsAvailable = true ;
89
- }
90
- } ) ;
103
+ // let betaIsAvailable = false;
104
+ // enabledPages.forEach((regPath) => {
105
+ // const regExecuted = new RegExp(regPath).exec(window.location.pathname);
106
+ // const found = regExecuted !== null && regExecuted.length < 2;
107
+ // if (!betaIsAvailable && found) {
108
+ // betaIsAvailable = true;
109
+ // }
110
+ // });
91
111
92
112
const isDoNotRenderPage =
93
113
window . location . hostname === legacy . hostname &&
@@ -98,7 +118,7 @@ async function insertSwitchButton(legacy: UrlStructure, beta: UrlStructure) {
98
118
( window . location . pathname === "/" ||
99
119
window . location . pathname === "/package/" ) ;
100
120
101
- if ( ( betaIsAvailable && ! isDoNotRenderPage ) || goToBetaRoR2 ) {
121
+ if ( ! isDoNotRenderPage || goToBetaRoR2 ) {
102
122
const switchButton = document . createElement ( "button" ) ;
103
123
104
124
// Add styles
@@ -125,7 +145,7 @@ async function insertSwitchButton(legacy: UrlStructure, beta: UrlStructure) {
125
145
window . location . hostname === legacy . hostname ? "beta" : "legacy"
126
146
} `;
127
147
128
- // Insert button to desktop
148
+ // Insert button to mobile
129
149
if (
130
150
window . location . hostname === beta . hostname ||
131
151
window . location . pathname . startsWith ( "/communities" )
0 commit comments