mirror of
https://github.com/NohamR/safari-internal-js.git
synced 2026-10-11 02:49:41 +00:00
Add 27.0 js src
This commit is contained in:
105
27.0/js/metadata/MetadataExtractor.js
Normal file
105
27.0/js/metadata/MetadataExtractor.js
Normal file
@@ -0,0 +1,105 @@
|
||||
//# sourceURL=__InjectedScript_MetadataExtractor.js
|
||||
/* Copyright (c) 2026 Apple Inc. All rights reserved. */
|
||||
function getIconType(e) {
|
||||
var o = e.getAttribute("rel");
|
||||
return "apple-touch-icon" === o
|
||||
? IconTypeAppleTouchIcon
|
||||
: "apple-touch-icon-precomposed" === o
|
||||
? IconTypeAppleTouchIconPrecomposed
|
||||
: IconTypeFavicon;
|
||||
}
|
||||
function compareIconsDescending(e, o) {
|
||||
var c = getIconType(e),
|
||||
t = getIconType(o);
|
||||
if (c === IconTypeFavicon && t !== IconTypeFavicon) return 1;
|
||||
if (t === IconTypeFavicon && c !== IconTypeFavicon) return -1;
|
||||
var n = e.getAttribute("sizes"),
|
||||
r = o.getAttribute("sizes"),
|
||||
p = 0,
|
||||
a = 0;
|
||||
return (
|
||||
n
|
||||
? (p = parseInt(n))
|
||||
: n ||
|
||||
(c !== IconTypeAppleTouchIcon &&
|
||||
c !== IconTypeAppleTouchIconPrecomposed) ||
|
||||
(p = AppleTouchIconDefaultWidth),
|
||||
r
|
||||
? (a = parseInt(r))
|
||||
: r ||
|
||||
(t !== IconTypeAppleTouchIcon &&
|
||||
t !== IconTypeAppleTouchIconPrecomposed) ||
|
||||
(a = AppleTouchIconDefaultWidth),
|
||||
a > p
|
||||
? 1
|
||||
: a < p
|
||||
? -1
|
||||
: c !== IconTypeAppleTouchIconPrecomposed &&
|
||||
t === IconTypeAppleTouchIconPrecomposed
|
||||
? 1
|
||||
: t !== IconTypeAppleTouchIconPrecomposed &&
|
||||
c === IconTypeAppleTouchIconPrecomposed
|
||||
? -1
|
||||
: 0
|
||||
);
|
||||
}
|
||||
function colorComponentsFromString(e) {
|
||||
var o = document.createElement("canvas");
|
||||
((o.width = 1), (o.height = 1));
|
||||
var c = o.getContext("2d");
|
||||
((c.fillStyle = e), c.fillRect(0, 0, 1, 1));
|
||||
var t = c.getImageData(0, 0, 1, 1);
|
||||
return [t.data[0], t.data[1], t.data[2]];
|
||||
}
|
||||
var MetadataExtractor = function () {};
|
||||
const IconTypeFavicon = 0,
|
||||
IconTypeAppleTouchIcon = 1,
|
||||
IconTypeAppleTouchIconPrecomposed = 2,
|
||||
AppleTouchIconDefaultWidth = 60;
|
||||
MetadataExtractor.prototype = {
|
||||
extractAndSortIconsWithSelector: function (e) {
|
||||
var o = document.head.querySelectorAll(e);
|
||||
return o.length
|
||||
? Array.prototype.slice.call(o).sort(compareIconsDescending)
|
||||
: [];
|
||||
},
|
||||
extractAppleTouchIconURLs: function () {
|
||||
for (
|
||||
var e = this.extractAndSortIconsWithSelector(
|
||||
"link[rel=apple-touch-icon], link[rel=apple-touch-icon-precomposed]",
|
||||
),
|
||||
o = [],
|
||||
c = 0;
|
||||
c < e.length;
|
||||
++c
|
||||
) {
|
||||
var t = e[c].href;
|
||||
t && o.push(t);
|
||||
}
|
||||
return o;
|
||||
},
|
||||
extractFaviconURLs: function () {
|
||||
for (
|
||||
var e = this.extractAndSortIconsWithSelector(
|
||||
"link[rel='shortcut icon'], link[rel=icon]",
|
||||
),
|
||||
o = [],
|
||||
c = e.length,
|
||||
t = 0;
|
||||
t < c;
|
||||
++t
|
||||
)
|
||||
o.push(e[t].href);
|
||||
return o;
|
||||
},
|
||||
extractTemplateIconURLAndColor: function () {
|
||||
var e = document.head.querySelector("link[rel=mask-icon]");
|
||||
if (!e) return null;
|
||||
var o = e.getAttribute("color");
|
||||
return o && e.href
|
||||
? { url: e.href, color: colorComponentsFromString(o) }
|
||||
: null;
|
||||
},
|
||||
};
|
||||
var MetadataExtractorJS = new MetadataExtractor();
|
||||
0;
|
||||
116
27.0/js/metadata/WebClipMetadataFetcher.js
Normal file
116
27.0/js/metadata/WebClipMetadataFetcher.js
Normal file
@@ -0,0 +1,116 @@
|
||||
//# sourceURL=__InjectedScript_WebClipMetadataFetcher.js
|
||||
/* Copyright (c) 2026 Apple Inc. All rights reserved. */
|
||||
/*
|
||||
* Copyright (c) 2014 Apple Inc. All rights reserved.
|
||||
*/
|
||||
const MetaTagNamesToScrape = [
|
||||
"apple-mobile-web-app-capable",
|
||||
"apple-mobile-web-app-title",
|
||||
"viewport",
|
||||
"apple-mobile-web-app-status-bar-style",
|
||||
],
|
||||
LinkRelTypesToScrape = [
|
||||
"apple-touch-icon",
|
||||
"apple-touch-icon-precomposed",
|
||||
"apple-touch-startup-image",
|
||||
"icon",
|
||||
"shortcut icon",
|
||||
];
|
||||
var Orientation = { Portrait: 0, Landscape: 1 },
|
||||
WebClipMetadataFinder = function () {};
|
||||
WebClipMetadataFinder.prototype = {
|
||||
webClipMetadata: function () {
|
||||
return {
|
||||
metaTags: this.metaTagsMetadata(),
|
||||
linkTags: this.linkTagsMetadata(),
|
||||
canonicalURLString: this.canonicalURLStringForPage(),
|
||||
};
|
||||
},
|
||||
metaTagsMetadata: function () {
|
||||
function e(e) {
|
||||
if ("apple-mobile-web-app-status-bar-style" === e.name)
|
||||
e.content.toLowerCase();
|
||||
}
|
||||
for (
|
||||
var t = {},
|
||||
a = document.head.getElementsByTagName("meta"),
|
||||
i = a.length,
|
||||
n = 0;
|
||||
n < i;
|
||||
++n
|
||||
) {
|
||||
var r = a[n],
|
||||
o = r.name;
|
||||
-1 !== MetaTagNamesToScrape.indexOf(o) && (e(r), (t[o] = r.content));
|
||||
}
|
||||
return t;
|
||||
},
|
||||
currentOrientation: function () {
|
||||
return (
|
||||
void 0 === this._currentOrientation &&
|
||||
(window.matchMedia("(orientation: portrait)").matches
|
||||
? (this._currentOrientation = Orientation.Portrait)
|
||||
: (this._currentOrientation = Orientation.Landscape)),
|
||||
this._currentOrientation
|
||||
);
|
||||
},
|
||||
canonicalURLStringForPage: function () {
|
||||
var e = document.head.querySelector("link[rel='canonical']");
|
||||
return e ? e.href : "";
|
||||
},
|
||||
linkTagsMetadata: function () {
|
||||
for (
|
||||
var e = [],
|
||||
t = document.head.getElementsByTagName("link"),
|
||||
a = t.length,
|
||||
i = 0;
|
||||
i < a;
|
||||
++i
|
||||
) {
|
||||
var n = t[i],
|
||||
r = n.rel;
|
||||
if (-1 !== LinkRelTypesToScrape.indexOf(r)) {
|
||||
var o = n.href,
|
||||
c = n.getAttribute("sizes");
|
||||
if (o) {
|
||||
var s = n.media,
|
||||
p = !0,
|
||||
d = !0;
|
||||
if (s) {
|
||||
var u = window.matchMedia(s);
|
||||
((p = this.mediaQueryListMatchesOrientation(
|
||||
u,
|
||||
Orientation.Portrait,
|
||||
)),
|
||||
(d = this.mediaQueryListMatchesOrientation(
|
||||
u,
|
||||
Orientation.Landscape,
|
||||
)));
|
||||
}
|
||||
var l = {
|
||||
rel: r,
|
||||
href: o,
|
||||
mediaMatchesPortraitOrientation: p,
|
||||
mediaMatchesLandscapeOrientation: d,
|
||||
};
|
||||
(c && (l.sizes = c), e.push(l));
|
||||
}
|
||||
}
|
||||
}
|
||||
return e;
|
||||
},
|
||||
mediaQueryListMatchesOrientation: function (e, t) {
|
||||
var a = e.media;
|
||||
if ("invalid" === a) return !1;
|
||||
if (t === this.currentOrientation()) return e.matches;
|
||||
var i = this.reverseMediaQueryOrientation(a);
|
||||
return window.matchMedia(i).matches;
|
||||
},
|
||||
reverseMediaQueryOrientation: function (e) {
|
||||
return e.replace(/orientation: (portrait|landscape)/, function (e, t) {
|
||||
return "orientation: " + ("portrait" === t ? "landscape" : "portrait");
|
||||
});
|
||||
},
|
||||
};
|
||||
var WebClipMetadataFinderJS = new WebClipMetadataFinder();
|
||||
0;
|
||||
Reference in New Issue
Block a user