-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
1 lines (1 loc) · 2.9 KB
/
index.js
1
(function(){"use strict";const w="";function k(t,e,n,i,l,h,c,o){var r=typeof t=="function"?t.options:t;e&&(r.render=e,r.staticRenderFns=n,r._compiled=!0),i&&(r.functional=!0),h&&(r._scopeId="data-v-"+h);var s;if(c?(s=function(a){a=a||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,!a&&typeof __VUE_SSR_CONTEXT__<"u"&&(a=__VUE_SSR_CONTEXT__),l&&l.call(this,a),a&&a._registeredComponents&&a._registeredComponents.add(c)},r._ssrRegister=s):l&&(s=o?function(){l.call(this,(r.functional?this.parent:this).$root.$options.shadowRoot)}:l),s)if(r.functional){r._injectStyles=s;var u=r.render;r.render=function(C,f){return s.call(f),u(C,f)}}else{var d=r.beforeCreate;r.beforeCreate=d?[].concat(d,s):[s]}return{exports:t,options:r}}const _={props:{base:String,urls:{type:Array,default:[]}},computed:{linksCount(){return this.urls.length},errorsCount(){return this.urls.filter(t=>t.status!==200).length}},methods:{addToUrls(t,e,n=null,i=null){if(this.isChecked(t)===!1){n&&(n={text:n.replace(this.base,"")||"/",href:n});const l={url:{text:t.replace(this.base,"")||"/",href:t},code:e,status:e===200?"\u{1F7E2}":"\u{1F534}",source:n,link:i,date:new Date().toLocaleString()};e===200?this.urls.push(l):this.urls.unshift(l)}},async crawlUrl(t,e=null,n=null){if(e===null&&(this.urls=[]),this.isChecked(t)===!0)return!1;await fetch(t).then(async i=>{const l=await i.text();if(this.addToUrls(t,i.status,e,n),this.isWebpage(i)!==!0)return!1;const o=new DOMParser().parseFromString(l,"text/html").documentElement.querySelectorAll("a");for(let r=0;r<o.length;r++){let s=o[r].getAttribute("href"),u=o[r].innerHTML;this.isInternal(s)===!0&&await this.crawlUrl(s,t,u)}}).catch(i=>{this.addToUrls(t,i.code,e)})},isInternal(t){return t.startsWith(this.base)},isChecked(t){return this.urls.filter(e=>e.url.href===t).length>0},isWebpage(t){var e,n;return(n=(e=t==null?void 0:t.headers)==null?void 0:e.get("content-type"))==null?void 0:n.startsWith("text/html")}}};var p=function(){var e=this,n=e._self._c;return n("k-inside",[n("k-view",{staticClass:"k-broken-links-checker-view"},[n("header",{staticClass:"k-header k-broken-links-checker-view-header"},[n("h2",[e._v("Broken links checker")]),n("k-button",{attrs:{tooltip:"Scan now",text:"Scan now",icon:"search"},on:{click:function(i){return e.crawlUrl(e.base)}}})],1),n("section",{staticClass:"k-broken-links-checker-view-section"},[n("header",[n("k-headline",[e._v("Checked URLs ("+e._s(e.linksCount)+") | Errors found: ("+e._s(e.errorsCount)+") ")])],1),n("k-table",{attrs:{columns:{url:{label:"Link",type:"url",mobile:!0},code:{label:"Code",width:"1/20"},status:{label:"Status",width:"1/20"},source:{label:"Source",type:"url",width:"5/20"},link:{label:"Link content",type:"html",width:"5/20"}},rows:e.urls,empty:"No links checked yet"}})],1)])],1)},b=[],m=k(_,p,b,!1,null,null,null,null);const v=m.exports;panel.plugin("ahmetbora/broken-links-checker",{components:{BrokenLinksChecker:v}})})();