Skip to content

Instantly share code, notes, and snippets.

@litewarp
Last active August 2, 2021 20:31
Show Gist options
  • Save litewarp/394b80c45835155aa383f2f15119e8e4 to your computer and use it in GitHub Desktop.
Save litewarp/394b80c45835155aa383f2f15119e8e4 to your computer and use it in GitHub Desktop.
Wix Functions

To use

  1. Enable Dev Mode in Wix

  2. Click Site tab in the editor

  3. Copy entirety of function into the onready function and call it like below

$w.onReady(function () {

  // <-- copy entirety of function from relevant file here
  const replaceCompanyName = () => {
    // ...
    // ...
  };

  // <--- then call it 
  replaceCompanyName();
});
const replaceCompanyName = () => {
const rows = Array.from(document.querySelector('table > tbody').childNodes);
rows.forEach(row => {
const firstChild = row.firstChild;
// text is two divs down
const contentDiv = firstChild.firstChild.firstChild;
const name = contentDiv.innerText;
const anchor = document.createElement('a');
anchor.setAttribute('style', 'text-decoration: underline');
const href = `https://legaltech.com/companies/${name.replace(/\s/g, '-').toLowerCase()}`;
anchor.setAttribute('href', href);
anchor.innerText = name;
const span = document.createElement('span');
span.appendChild(anchor);
contentDiv.replaceChild(span, contentDiv.firstChild);
});
};
const replaceInvestorNames = () => {
const rows = Array.from(document.querySelector('table > tbody').childNodes);
rows.forEach(row => {
const lastChild = row.lastChild;
// text is two divs down
const contentDiv = lastChild.firstChild.firstChild;
const investors = contentDiv.innerText.split(', ');
const span = document.createElement('span');
investors.forEach((name, index) => {
const anchor = document.createElement('a');
anchor.setAttribute('style', "text-decoration: underline; padding-right: 5px;" );
const href = `https://legaltech.com/investors/${name.replace(/\s/g, '-').toLowerCase()}`;
anchor.setAttribute('href', href);
// if last element, don't add ','
anchor.innerText = index + 1 === investors.length ? name : `${name},`;
span.appendChild(anchor);
});
contentDiv.replaceChild(span, contentDiv.firstChild);
})
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment