Fork me on GitHub

Safelinkify

npm version www.webmanajemen.com LICENSE GitHub language count Github Workflow GitHub forks GitHub stars

Customized safelink url redirector. Transform and Anonymize all hyperlinks to outbound pages. Useful for SEO external links and ADS. READ FULL DOCUMENTATION

Installation

npm install safelinkify --production
# or
yarn install safelinkify --production=true

Development

git clone --single-branch --branch main https://github.com/dimaslanjaka/safelink foldername
cd foldername
# install dependents
yarn install
# or
npm install
commanddescription
yarn startwatch tests and start server
watch src and compile tsc webpack
tscbuild definition and js files
webpackbuild safelink script

Usages

Setup options:

const options = {
  // exclude patterns (dont anonymize these patterns)
  exclude: ['domain.com', /another.domain.com/, /https?:\/\/?(?:([^*]+)\.)?webmanajemen\.com/, /([a-z0-9](?:[a-z0-9-]{1,61}[a-z0-9])?[.])*webmanajemen\.com/],
  // url redirector
  redirect: 'https://www.webmanajemen.com/page/safelink.html?url=',
  // debug
  verbose: false,
  // encryption type = 'base64' | 'aes'
  type: 'base64',
  // password aes, default = root
  password: 'unique-password'
}

Browser

script location: node_modules/safelinkify/dist/bundle.min.js.

Call Core Script:

<script src="dist/bundle.min.js"></script>
<!--or using rawgit-->
<script src="https://raw.githack.com/dimaslanjaka/safelink/main/dist/bundle.min.js"></script>
<!--or using statically-->
<script src="https://cdn.statically.io/gh/dimaslanjaka/safelink/main/dist/bundle.min.js"></script>

Execute functions:

<script>
  const sf = new safelink(options);
  // automated safelinkify all hyperlinks in body
  sf.parse(document.querySelector('body'));
  // in page redirector
  sf.resolveQueryUrl(window.location.href);
</script>

NodeJS

full sample here

import safelinkify from 'safelinkify'; // const safelinkify = require('safelinkify')
const sf = new safelinkify.safelink(options);
const processedExternalLinks = sf.parse(`
<a href="www.example.com/page.php?id=xxxx&name=yyyy" ....>external</a>
<a href="http://www.example.com/page.php?id=xxxx&name=yyyy" ....>external</a>
<a href="https://www.example.com/page.php?id=xxxx&name=yyyy" ....>external</a>
<a href="www.example.com/page.php/404" ....></a>
<a href="http://external.domain.com">internal</a>
<a href="http://www.webmanajemen.com">internal</a>
<a href="http://webmanajemen.com">internal</a>
<a href="#http://webmanajemen.com">#internal</a>
<a href="?http://webmanajemen.com">?internal</a>
<a href="">internal</a>
`);
console.log(processedExternalLinks);
/*
<a href="www.example.com/page.php?id=xxxx&name=yyyy" ....>external</a>
<a href="https://www.webmanajemen.com/page/safelink.html?url=aHR0cDovL3d3dy5leGFtcGxlLmNvbS9wYWdlLnBocD9pZD14eHh4Jm5hbWU9eXl5eQ==" ....>external</a>
<a href="https://www.webmanajemen.com/page/safelink.html?url=aHR0cHM6Ly93d3cuZXhhbXBsZS5jb20vcGFnZS5waHA/aWQ9eHh4eCZuYW1lPXl5eXk=" ....>external</a>
<a href="www.example.com/page.php/404" ....></a>
<a href="http://external.domain.com">internal</a>
<a href="http://www.webmanajemen.com">internal</a>
<a href="http://webmanajemen.com">internal</a>
<a href="#http://webmanajemen.com">#internal</a>
<a href="?http://webmanajemen.com">?internal</a>
<a href="">internal</a>
*/

Result Above Examples

Query URL Resolver Samples
To Encode
Decode base64
Decode AES
Decode AES using hash
External Link Samples (Hover)
example google facebook
Internal Link Samples (Hover)
Homepage Search
global parseQuery
global resolveQueryUrl
Current Page Script
    
<script src="dist/bundle.min.js"></script>
<script>document.addEventListener('DOMContentLoaded', function () {
  const table = document.querySelector('table#table');
  table.querySelector('#resolveQueryUrl').innerHTML = typeof resolveQueryUrl;
  table.querySelector('#parseQuery').innerHTML = typeof parseQuery;

  function isClass(f) {
    return (
      typeof f === 'function' &&
      (() => {
        try {
          f();
          return false;
        } catch {
          return true;
        }
      })()
    );
  }

  const isSafelinkClass = isClass(safelink);
  table.innerHTML += `<tr><td>global safelink</td><td>is ES5 Class: ${isSafelinkClass}</td></tr>`;

  if (isSafelinkClass) {
    const instance = new safelink({
      // exclude patterns (dont anonymize these patterns)
      exclude: [/([a-z0-9](?:[a-z0-9-]{1,61}[a-z0-9])?[.])*webmanajemen\.com/],
      // url redirector
      redirect: 'https://www.webmanajemen.com/page/safelink.html?url=',
      // debug
      verbose: false,
      // encryption type = 'base64' | 'aes'
      type: 'base64',
      // password aes, default = root
      password: 'unique-password'
    });
    instance.parse(document.querySelector('div#external'));
    instance.parse(document.querySelector('div#internal'));

    const currentQuery = JSON.stringify(instance.resolveQueryUrl(location.href), null, 2);
    table.innerHTML += `<tr id="current-queries"><td>Redirector Resolver Using <code>sf.resolveQueryUrl(location.href)</code> <a href="#query-url">Change</a></td><td><pre><code class="language-json">${currentQuery}</code></pre></td></tr>`;

    const param = new URLSearchParams(location.search);
    if (param.has('o') || param.has('url') || location.href.match(/#(o|url)=/)) {
      document.getElementById('current-queries').scrollIntoView();
    }
  }

  Array.from(document.links).forEach((el) => {
    if (!el.innerHTML.length) {
      el.textContent = el.getAttribute('href');
      el.addEventListener('click', (e) => {
        e.preventDefault();
        window.location.href = el.href;
        if (el.href.match(/#(o|url)=/)) location.reload();
      });
    }
  });
});
</script>
    
  

CHANGELOG

1.0.0

1.0.1

1.0.2

1.0.3

1.0.5 - 1.0.6

1.0.7

1.0.8 - 1.0.9

1.1.0

1.1.1

1.1.2