Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save sysnucleus/ec477701fef2d64fd93c3a0558d5e35f to your computer and use it in GitHub Desktop.

Select an option

Save sysnucleus/ec477701fef2d64fd93c3a0558d5e35f to your computer and use it in GitHub Desktop.
WebHarvy CMEF Scraping Code
(function () {
extracting = false;
FIXED = 'data-link-fixed';
document.addEventListener('click', function (e) {
if (extracting) return;
if (e.target.closest(`a[${FIXED}]`)) {
e.stopPropagation();
return;
}
card = e.target.closest('.ex-item-wrap');
if (!card) return;
e.preventDefault();
e.stopImmediatePropagation();
extracting = true;
origOpen = window.open;
window.open = function (u) {
url = u;
return { closed: false, focus() {}, close() {} };
};
try { card.click(); } finally {
window.open = origOpen;
extracting = false;
}
if (!url) return;
titleEl = e.target.closest('span') || card.querySelector('span');
if (titleEl && !titleEl.querySelector(`a[${FIXED}]`)) {
a = document.createElement('a');
a.href = url;
a.target = '_blank';
a.rel = 'noopener';
a.textContent = titleEl.textContent;
a.setAttribute(FIXED, '');
a.style.cssText = 'color:inherit; text-decoration:underline; cursor:pointer;';
titleEl.innerHTML = '';
titleEl.appendChild(a);
}
}, true);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment