-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquicklink.js
More file actions
1 lines (1 loc) · 5.21 KB
/
quicklink.js
File metadata and controls
1 lines (1 loc) · 5.21 KB
1
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e||self).quicklink={})}(this,function(e){function n(e,n){(null==n||n>e.length)&&(n=e.length);for(var r=0,t=Array(n);r<n;r++)t[r]=e[r];return t}function r(e,r){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(t)return(t=t.call(e)).next.bind(t);if(Array.isArray(e)||(t=function(e,r){if(e){if("string"==typeof e)return n(e,r);var t={}.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?n(e,r):void 0}}(e))||r&&e&&"number"==typeof e.length){t&&(e=t);var o=0;return function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function t(e,n,r,t){var o={headers:{accept:"*/*"}};return n||(o.mode="no-cors"),r&&(o.credentials="include"),o.priority=t?"high":"low",window.fetch?fetch(e,o):function(e,n){return new Promise(function(r,t,o){(o=new XMLHttpRequest).open("GET",e,o.withCredentials=n),o.setRequestHeader("Accept","*/*"),o.onload=function(){200===o.status?r():t()},o.send()})}(e,r)}var o,i=(o=document.createElement("link")).relList&&o.relList.supports&&o.relList.supports("prefetch")?function(e,n){return new Promise(function(r,t,o){(o=document.createElement("link")).rel="prefetch",o.href=e,n&&o.setAttribute("crossorigin","anonymous"),o.onload=r,o.onerror=t,document.head.appendChild(o)})}:t,c=window.requestIdleCallback||function(e){var n=Date.now();return setTimeout(function(){e({didTimeout:!1,timeRemaining:function(){return Math.max(0,50-(Date.now()-n))}})},1)},a=new Set,s=new Set,u=!1;function l(e,n){return Array.isArray(n)?n.some(function(n){return l(e,n)}):(n.test||n).call(n,e.href,e)}function f(e){if(e){if(e.saveData)return new Error("Save-Data is enabled");if(/2g/.test(e.effectiveType))return new Error("network conditions are poor")}return!0}function d(e,n,o,c,l){var d=f(navigator.connection);return d instanceof Error?Promise.reject(new Error("Cannot prefetch, "+d.message)):(s.size>0&&!u&&console.warn("[Warning] You are using both prefetching and prerendering on the same document"),Promise.all([].concat(e).map(function(e){return a.has(e)?[]:(a.add(e),function(e,n,t){var o=[].slice.call(arguments,3);if(!t)return e.apply(void 0,[n].concat(o));for(var i,c=Array.from(document.querySelectorAll("a")).filter(function(e){return e.href===n}),a=new Map,s=function(){var r=i.value,t=function(i){var s=setTimeout(function(){return r.removeEventListener("mouseenter",t),r.removeEventListener("mouseleave",c),e.apply(void 0,[n].concat(o))},200);a.set(r,s)},c=function(e){var n=a.get(r);n&&(clearTimeout(n),a.delete(r))};r.addEventListener("mouseenter",t),r.addEventListener("mouseleave",c)},u=r(c);!(i=u()).done;)s()}(n?t:i,new URL(e,location.href).toString(),l,o,c,n))})))}function h(e,n){void 0===n&&(n="immediate");var t=f(navigator.connection);if(t instanceof Error)return Promise.reject(new Error("Cannot prerender, "+t.message));if(!HTMLScriptElement.supports("speculationrules"))return d(e,!0,!1,!1,"moderate"===n||"conservative"===n),Promise.reject(new Error("This browser does not support the speculation rules API. Falling back to prefetch."));for(var o,i=r([].concat(e));!(o=i()).done;)s.add(o.value);a.size>0&&!u&&console.warn("[Warning] You are using both prefetching and prerendering on the same document");var c=function(e,n){var r=document.createElement("script");r.type="speculationrules",r.text='{"prerender":[{"source": "list",\n "urls": ["'+Array.from(e).join('","')+'"],\n "eagerness": "'+n+'"}]}';try{document.head.appendChild(r)}catch(e){return e}return!0}(s,n);return!0===c?Promise.resolve():Promise.reject(c)}e.listen=function(e){if(void 0===e&&(e={}),window.IntersectionObserver&&"isIntersecting"in IntersectionObserverEntry.prototype){var n=function(e){e=e||1;var n=[],r=0;function t(){r<e&&n.length>0&&(n.shift()(),r++)}return[function(e){n.push(e)>1||t()},function(){r--,t()}]}(e.throttle||1/0),r=n[0],t=n[1],o=e.limit||1/0,i=e.origins||[location.hostname],f=e.ignores||[],m=e.delay||0,p=[],v=e.timeoutFn||c,g="function"==typeof e.hrefFn&&e.hrefFn,y=e.prerender||!1;u=e.prerenderAndPrefetch||!1;var w=new IntersectionObserver(function(n){n.forEach(function(n){if(n.isIntersecting)p.push((n=n.target).href),function(e,n){n?setTimeout(e,n):e()}(function(){p.includes(n.href)&&(w.unobserve(n),(u||y)&&s.size<o?h(g?g(n):n.href,e.eagerness).catch(function(n){if(!e.onError)throw n;e.onError(n)}):a.size<o&&!y&&r(function(){d(g?g(n):n.href,e.priority,e.checkAccessControlAllowOrigin,e.checkAccessControlAllowCredentials,e.onlyOnMouseover).then(t).catch(function(n){t(),e.onError&&e.onError(n)})}))},m);else{var i=p.indexOf((n=n.target).href);i>-1&&p.splice(i)}})},{threshold:e.threshold||0});return v(function(){(e.el&&e.el.length&&e.el.length>0&&"A"===e.el[0].nodeName?e.el:(e.el||document).querySelectorAll("a")).forEach(function(e){i.length&&!i.includes(e.hostname)||l(e,f)||w.observe(e)})},{timeout:e.timeout||2e3}),function(){a.clear(),w.disconnect()}}},e.prefetch=d,e.prerender=h});