Back to Repository

Parse and add links to facecheck.id search

0 upvotes
By wrighthisd@gmail.com
Manual (context menu)

Description

Adds free public links to facecheck.id results

Match Pattern

https://facecheck.id/*

Script Code

setTimeout(() => {
  const getRating = confidence =>
    confidence >= 90 ? {
      color: 'green'
    } :
    confidence >= 83 ? {
      color: 'yellow'
    } :
    confidence >= 70 ? {
      color: 'orange'
    } :
    confidence >= 50 ? {
      color: 'red'
    } : {
      color: 'white'
    };

  const addLinksToDiv = () => {
    let i = 0;
    while (true) {
      const fimgDiv = document.querySelector(`#fimg${i}`);
      if (!fimgDiv) break;

      const bgImage = window.getComputedStyle(fimgDiv).backgroundImage;
      const base64Match = bgImage.match(/base64,(.*)"/);
      const urlMatch = base64Match ? atob(base64Match[1]).match(/https?:\/\/[^\s"]+/) : null;

      if (urlMatch) {
        const domain = new URL(urlMatch[0]).hostname.replace('www.', '');
        const distSpan = fimgDiv.parentElement.querySelector('.dist');
        const confidence = distSpan ? parseInt(distSpan.textContent) : 0;
        const {
          color
        } = getRating(confidence);
        const linkDiv = document.createElement('div');
        linkDiv.style.cssText = 'position:absolute;bottom:0;left:0;right:0;background:rgba(0,0,0,0.8);padding:5px;font-size:12px;text-align:center;';

        const link = document.createElement('a');
        link.href = urlMatch[0];
        link.target = '_blank';
        link.rel = 'noopener noreferrer';
        link.style.cssText = `color:${color};text-decoration:none;`;
        link.textContent = domain + ' ↗';

        linkDiv.appendChild(link);
        fimgDiv.appendChild(linkDiv);

        const parentAnchor = fimgDiv.parentElement;
        if (parentAnchor && parentAnchor.tagName === 'A') {
          const newContainer = document.createElement('div');
          newContainer.style.cssText = parentAnchor.style.cssText;
          parentAnchor.parentNode.insertBefore(newContainer, parentAnchor);
          newContainer.appendChild(fimgDiv);
          parentAnchor.remove();
        }
      }
      i++;
    }
  };

  if (/https:\/\/facecheck\.id\/(?:[a-z]{2})?\#.+/.test(window.location.href)) {
    const checkInterval = setInterval(() => {
      if (document.querySelector("#fimg0")) {
        addLinksToDiv();
        clearInterval(checkInterval);
      }
    }, 1000);
  }
}, 3000);
Install requires the InjectJS Chrome extension. Scripts run only on sites matching the pattern above. Review code before installing any community script.