MCPcopy Create free account
hub / github.com/ampproject/amphtml / getAmpHtmlLinkHref

Function getAmpHtmlLinkHref

validator/js/chromeextension/content_script.js:46–65  ·  view source on GitHub ↗

* Determine if exists in the page and * return the href's value iff it starts with http:// or https://. * Otherwise returns empty string. * * @return {string} * @private

()

Source from the content-addressed store, hash-verified

44 * @private
45 */
46function getAmpHtmlLinkHref() {
47 let ampHtmlLinkHref = '';
48 // URL must begin with http:// or https://
49 const validUrlPrefixRe = /^[\s\xa0]*https?:\/\//;
50 const headLinks = document.head.getElementsByTagName('link');
51 if (headLinks.length > 0) {
52 for (const index in headLinks) {
53 const link = headLinks[index];
54 if (link instanceof HTMLLinkElement &&
55 link.hasAttribute('rel') &&
56 globals.amphtmlRegex.test(link.getAttribute('rel')) &&
57 link.hasAttribute('href') &&
58 validUrlPrefixRe.test(link.getAttribute('href'))) {
59 ampHtmlLinkHref = link.getAttribute('href');
60 break;
61 }
62 }
63 }
64 return ampHtmlLinkHref;
65}
66
67/**
68 * Determine if the page is from an AMP Cache.

Callers 1

content_script.jsFile · 0.85

Calls 2

getAttributeMethod · 0.80
testMethod · 0.45

Tested by

no test coverage detected