@pinnacle0/browser-util
Advanced tools
Comparing version 0.0.6 to 0.0.7
{ | ||
"name": "@pinnacle0/browser-util", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
export declare type BrowserOS = "Windows" | "Mac" | "iOS" | "Android" | "other"; | ||
export declare type BrowserKernel = "webkit" | "firefox" | "ie" | "other"; | ||
/** @deprecated */ | ||
declare function isMac(): boolean; | ||
/** @deprecated */ | ||
declare function isWebkit(): boolean; | ||
export interface BrowserNewTabSizeOptions { | ||
width: number; | ||
height: number; | ||
top: number; | ||
left: number; | ||
} | ||
declare function os(): BrowserOS; | ||
declare function kernel(): BrowserKernel; | ||
declare function isMobile(): boolean; | ||
/** @deprecated */ | ||
declare function isIos(): boolean; | ||
/** @deprecated */ | ||
declare function isAndroid(): boolean; | ||
declare function isWechat(): boolean; | ||
@@ -19,16 +19,14 @@ declare function removeElement(element: HTMLElement | null): void; | ||
*/ | ||
declare function openTabAndWait(url: string): Promise<void>; | ||
declare function newTab(url: string, sizeOptions?: Partial<BrowserNewTabSizeOptions>): Promise<void>; | ||
declare function openQQ(qq: string): void; | ||
export declare const BrowserUtil: Readonly<{ | ||
isMac: typeof isMac; | ||
isAndroid: typeof isAndroid; | ||
isIos: typeof isIos; | ||
os: typeof os; | ||
kernel: typeof kernel; | ||
isMobile: typeof isMobile; | ||
isWebkit: typeof isWebkit; | ||
isWechat: typeof isWechat; | ||
removeElement: typeof removeElement; | ||
scrollTo: typeof scrollTo; | ||
openTabAndWait: typeof openTabAndWait; | ||
newTab: typeof newTab; | ||
openQQ: typeof openQQ; | ||
}>; | ||
export {}; |
@@ -0,28 +1,40 @@ | ||
import { __read } from "tslib"; | ||
function os() { | ||
// TODO | ||
return "other"; | ||
if (navigator.userAgent.toUpperCase().indexOf("WINDOWS") >= 0) { | ||
// https://stackoverflow.com/a/19176790 | ||
return "Windows"; | ||
} | ||
else if (navigator.platform.toUpperCase().indexOf("MAC") >= 0) { | ||
return "Mac"; | ||
} | ||
else if (/iPhone|iPad|iPod/i.test(navigator.userAgent)) { | ||
return "iOS"; | ||
} | ||
else if (/Android|webOS|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) { | ||
return "Android"; | ||
} | ||
else { | ||
return "other"; | ||
} | ||
} | ||
function kernel() { | ||
// TODO | ||
return "other"; | ||
var userAgentUpperCase = navigator.userAgent.toUpperCase(); | ||
if ("WebkitAppearance" in document.documentElement.style) { | ||
return "webkit"; | ||
} | ||
else if (userAgentUpperCase.indexOf("FIREFOX") >= 0 && userAgentUpperCase.indexOf("SEAMONKEY") === -1) { | ||
// https://github.com/keithws/browser-report/blob/6fa7a2bb33ce8b8621b2c4538a1ebefac38af57f/index.js#L64 | ||
return "firefox"; | ||
} | ||
else if (userAgentUpperCase.indexOf("MSIE") >= 0) { | ||
// https://github.com/keithws/browser-report/blob/6fa7a2bb33ce8b8621b2c4538a1ebefac38af57f/index.js#L56 | ||
return "ie"; | ||
} | ||
else { | ||
return "other"; | ||
} | ||
} | ||
/** @deprecated */ | ||
function isMac() { | ||
return navigator.platform.toUpperCase().indexOf("MAC") >= 0; | ||
} | ||
/** @deprecated */ | ||
function isWebkit() { | ||
return "WebkitAppearance" in document.documentElement.style; | ||
} | ||
function isMobile() { | ||
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent); | ||
} | ||
/** @deprecated */ | ||
function isIos() { | ||
return /iPhone|iPad|iPod/i.test(navigator.userAgent); | ||
} | ||
/** @deprecated */ | ||
function isAndroid() { | ||
return /Android|webOS|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent); | ||
} | ||
function isWechat() { | ||
@@ -72,5 +84,13 @@ return /MicroMessenger/i.test(navigator.userAgent); | ||
*/ | ||
function openTabAndWait(url) { | ||
function newTab(url, sizeOptions) { | ||
if (sizeOptions === void 0) { sizeOptions = {}; } | ||
return new Promise(function (resolve) { | ||
var newWindow = window.open(url, "_blank"); | ||
var features; | ||
if (Object.keys(sizeOptions).length > 0) { | ||
features = "toolbar=no,location=no,status=no,menubar=no,resizable=no" + Object.entries(sizeOptions).map(function (_a) { | ||
var _b = __read(_a, 2), key = _b[0], value = _b[1]; | ||
return "," + key + "=" + value; | ||
}); | ||
} | ||
var newWindow = window.open(url, "newTab", features); | ||
if (newWindow) { | ||
@@ -88,4 +108,3 @@ newWindow.addEventListener("load", function () { return resolve(); }, true); | ||
if (isMobile()) { | ||
// TODO: use `os() === "iOS"` | ||
if (isIos()) { | ||
if (os() === "iOS") { | ||
window.open("mqq://im/chat?chat_type=wpa&uin=" + qq + "&version=1&src_type=web"); | ||
@@ -102,13 +121,11 @@ } | ||
export var BrowserUtil = Object.freeze({ | ||
isMac: isMac, | ||
isAndroid: isAndroid, | ||
isIos: isIos, | ||
os: os, | ||
kernel: kernel, | ||
isMobile: isMobile, | ||
isWebkit: isWebkit, | ||
isWechat: isWechat, | ||
removeElement: removeElement, | ||
scrollTo: scrollTo, | ||
openTabAndWait: openTabAndWait, | ||
newTab: newTab, | ||
openQQ: openQQ, | ||
}); | ||
//# sourceMappingURL=BrowserUtil.js.map |
Sorry, the diff of this file is not supported yet
37779
596