Last active
February 14, 2025 19:15
-
-
Save natzir/fb7fdaef6655cef3da5424c7ef976eea to your computer and use it in GitHub Desktop.
Internal Link Checker Bookmarklet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:void%20function(){javascript:(function(){function%20a(a,b){if(b.length){let%20c=100/b.length,d=b.map((a,b)=%3E`${a}%20${b*c}%25%20${b*c+c}%25`);a.style.backgroundImage=%22linear-gradient(to%20right,%20%22+d.join(%22,%20%22)+%22)%22,a.style.color=%22black%22}}function%20b(a){if(a.href%26%26a.href.includes(g)){let%20b=a.href;d(b).then(b=%3E{300%3C=b.status%26%26400%3Eb.status%3F(c(a,%22olive%22,%223XX%20Redirect%22),i.redirect++):400%3C=b.status%26%26500%3Eb.status%3F(c(a,%22silver%22,%224XX%20Client%20Error%22),i.clientError++):500%3C=b.status%26%26(c(a,%22aqua%22,%225XX%20Server%20Error%22),i.serverError++),e()})}}function%20c(b,c,d){let%20e=b.getAttribute(%22colors%22);e=e%3FJSON.parse(e):[],e.includes(c)||e.push(c),b.setAttribute(%22colors%22,JSON.stringify(e)),b.setAttribute(%22status%22,d),a(b,e)}function%20d(a){let%20b=3e4,c={status:null,document:null};return%20new%20Promise(d=%3E{let%20e=new%20XMLHttpRequest;e.onreadystatechange=function(){4==e.readyState%26%26(clearTimeout(b),200%3C=e.status%26%26400%3Ee.status%26%26(c.document=e.responseText),c.status=e.responseURL===a.split(%22%23%22)[0]%3Fe.status:300,d(c))};try{e.open(%22GET%22,a,!0),e.send()}catch(a){c.status=0,d(c)}b=setTimeout(()=%3E{c.status=408,d(c),e.abort()},b+1e3)})}function%20e(){Object.keys(i).forEach(a=%3E{document.getElementById(a).innerText=`${a.charAt(0).toUpperCase()+a.slice(1).replace(/([A-Z])/g,%22%20$1%22)}:%20${i[a]}`})}let%20f=document.querySelectorAll(%22a%22),g=window.location.origin,h=[],i={queryString:0,noFollow:0,blockedByRobots:0,redirect:0,clientError:0,serverError:0},j={queryString:%22yellow%22,noFollow:%22orange%22,blockedByRobots:%22red%22,redirect:%22olive%22,clientError:%22silver%22,serverError:%22aqua%22};(function(){let%20a=document.createElement(%22div%22);Object.assign(a.style,{position:%22fixed%22,bottom:%2210px%22,right:%2210px%22,backgroundColor:%22white%22,padding:%2210px%22,border:%221px%20solid%20black%22,zIndex:%2210000%22,color:%22black%22,fontFamily:%22Helvetica%22,fontSize:%2218px%22});let%20b=document.createElement(%22strong%22);Object.assign(b.style,{display:%22block%22,fontFamily:%22Helvetica%22,fontSize:%2220px%22}),b.innerText=%22Internal%20Link%20Checker%22,a.appendChild(b),a.appendChild(document.createElement(%22br%22));Object.keys(i).forEach(b=%3E{let%20c=document.createElement(%22div%22);c.id=b,c.innerText=`${b.charAt(0).toUpperCase()+b.slice(1).replace(/([A-Z])/g,%22%20$1%22)}:%20${i[b]}`,Object.assign(c.style,{backgroundColor:j[b]||%22white%22,color:%22black%22}),a.appendChild(c)});let%20c=document.createElement(%22a%22);Object.assign(c.style,{fontSize:%22small%22,color:%22grey%22,display:%22block%22,textAlign:%22right%22,textDecoration:%22underline%22,fontFamily:%22Helvetica%22,fontSize:%2216px%22}),c.href=%22https://twitter.com/natzir9%22,c.innerText=%22By%20%40natzir9%22,a.appendChild(c),document.body.appendChild(a)})(),f.forEach(a=%3E{a.href%26%26a.href.includes(g)%26%26(a.href.includes(%22%3F%22)%26%26(c(a,%22yellow%22,%22Query%20String%22),i.queryString++),a.rel%26%26/nofollow|sponsored|ugc/.test(a.rel)%26%26(c(a,%22orange%22,%22No%20Follow%22),i.noFollow++),h.push(a.href),b(a))});fetch(%22https://tools.estevecastells.com/api/bulk-robots-txt/v1%22,{method:%22POST%22,headers:{%22Content-Type%22:%22application/json%22},body:JSON.stringify({robots_txt_url:g+%22/robots.txt%22,links:h})}).then(a=%3Ea.json()).then(a=%3E{for(let%20b%20in%20a)a[b]||f.forEach(a=%3E{a.href===b%26%26(c(a,%22red%22,%22Blocked%20by%20robots.txt%22),i.blockedByRobots++)});e()}).catch(a=%3Econsole.error(%22Error:%20%22,a))})()}(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This JavaScript code is a bookmarklet designed to assess and visually represent the status of internal links on a webpage. The script checks each internal link's status and applies a background color depending on the state of the link. Here's what the script does in detail:
Usage:
To use this script, you can create a new bookmark and paste the provided JavaScript code as the bookmark's URL. When you click on this bookmark while on any webpage, it will execute the script and visually modify the internal links according to their statuses as described.
Note:
Ensure that the web page is fully loaded before executing the script, as it may not properly identify and mark all links if the page is still loading.