98 lines
3.4 KiB
JavaScript
98 lines
3.4 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.getWindowMetadata = void 0;
|
|
const window_getters_1 = require("@walletconnect/window-getters");
|
|
function getWindowMetadata() {
|
|
let doc;
|
|
let loc;
|
|
try {
|
|
doc = window_getters_1.getDocumentOrThrow();
|
|
loc = window_getters_1.getLocationOrThrow();
|
|
}
|
|
catch (e) {
|
|
return null;
|
|
}
|
|
function getIcons() {
|
|
const links = doc.getElementsByTagName("link");
|
|
const icons = [];
|
|
for (let i = 0; i < links.length; i++) {
|
|
const link = links[i];
|
|
const rel = link.getAttribute("rel");
|
|
if (rel) {
|
|
if (rel.toLowerCase().indexOf("icon") > -1) {
|
|
const href = link.getAttribute("href");
|
|
if (href) {
|
|
if (href.toLowerCase().indexOf("https:") === -1 &&
|
|
href.toLowerCase().indexOf("http:") === -1 &&
|
|
href.indexOf("//") !== 0) {
|
|
let absoluteHref = loc.protocol + "//" + loc.host;
|
|
if (href.indexOf("/") === 0) {
|
|
absoluteHref += href;
|
|
}
|
|
else {
|
|
const path = loc.pathname.split("/");
|
|
path.pop();
|
|
const finalPath = path.join("/");
|
|
absoluteHref += finalPath + "/" + href;
|
|
}
|
|
icons.push(absoluteHref);
|
|
}
|
|
else if (href.indexOf("//") === 0) {
|
|
const absoluteUrl = loc.protocol + href;
|
|
icons.push(absoluteUrl);
|
|
}
|
|
else {
|
|
icons.push(href);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return icons;
|
|
}
|
|
function getWindowMetadataOfAny(...args) {
|
|
const metaTags = doc.getElementsByTagName("meta");
|
|
for (let i = 0; i < metaTags.length; i++) {
|
|
const tag = metaTags[i];
|
|
const attributes = ["itemprop", "property", "name"]
|
|
.map((target) => tag.getAttribute(target))
|
|
.filter((attr) => {
|
|
if (attr) {
|
|
return args.includes(attr);
|
|
}
|
|
return false;
|
|
});
|
|
if (attributes.length && attributes) {
|
|
const content = tag.getAttribute("content");
|
|
if (content) {
|
|
return content;
|
|
}
|
|
}
|
|
}
|
|
return "";
|
|
}
|
|
function getName() {
|
|
let name = getWindowMetadataOfAny("name", "og:site_name", "og:title", "twitter:title");
|
|
if (!name) {
|
|
name = doc.title;
|
|
}
|
|
return name;
|
|
}
|
|
function getDescription() {
|
|
const description = getWindowMetadataOfAny("description", "og:description", "twitter:description", "keywords");
|
|
return description;
|
|
}
|
|
const name = getName();
|
|
const description = getDescription();
|
|
const url = loc.origin;
|
|
const icons = getIcons();
|
|
const meta = {
|
|
description,
|
|
url,
|
|
icons,
|
|
name,
|
|
};
|
|
return meta;
|
|
}
|
|
exports.getWindowMetadata = getWindowMetadata;
|
|
//# sourceMappingURL=index.js.map
|