44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
|
|
export function url_find_key(url: string, key: string): string {
|
||
|
|
/*
|
||
|
|
// URL 類別在Android 上出錯
|
||
|
|
// E jswrapper: ERROR: Uncaught TypeError: Cannot read property 'toLowerCase' of undefined, location: jsb-adapter/jsb-builtin.js:0:0
|
||
|
|
// E jswrapper: STACK:
|
||
|
|
// E jswrapper: [0]exports.URL@jsb-adapter/jsb-builtin.js:90
|
||
|
|
// E jswrapper: [1]t.url_find_key@src/project.js:602
|
||
|
|
// E jswrapper: [2]anonymous@src/project.js:291
|
||
|
|
// E jswrapper: [3]anonymous@src/project.js:356
|
||
|
|
// E jswrapper: [4]211.l.emit@src/cocos2d-jsb.js:29277
|
||
|
|
// E jswrapper: [5]anonymous@(no filename):1
|
||
|
|
// E jswrapper: ScriptEngine::evalString script (no filename), failed!
|
||
|
|
|
||
|
|
const o_url = new URL(url);
|
||
|
|
if (o_url.searchParams.has(key) == false)
|
||
|
|
return "";
|
||
|
|
|
||
|
|
return o_url.searchParams.get(key);
|
||
|
|
*/
|
||
|
|
|
||
|
|
var _key = key + "=";
|
||
|
|
var tokens = url.split("?", 2);
|
||
|
|
tokens = tokens[1].split("&");
|
||
|
|
|
||
|
|
for (let x of tokens) {
|
||
|
|
if (x.indexOf(_key) == 0) {
|
||
|
|
return x.substring(_key.length);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return "";
|
||
|
|
}
|
||
|
|
|
||
|
|
export function get_deeplink_url(packageName: string, lastPath: string): string {
|
||
|
|
if (lastPath) {
|
||
|
|
return "coresdk://coresdk.games/" + packageName;
|
||
|
|
}
|
||
|
|
|
||
|
|
return "coresdk://coresdk.games/" + packageName + "/" + lastPath;
|
||
|
|
}
|
||
|
|
|
||
|
|
export function open_url(url: string): void {
|
||
|
|
cc.sys.openURL(url);
|
||
|
|
}
|