Skip to content

Instantly share code, notes, and snippets.

@maximal
Last active January 30, 2019 20:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maximal/5dc2720c08fb99be2e452552af80aaf7 to your computer and use it in GitHub Desktop.
Save maximal/5dc2720c08fb99be2e452552af80aaf7 to your computer and use it in GitHub Desktop.
Highlight Engagement User Script
/**
* Highlight high engagements on any Instagram page.
*
* The script needs this Chrome extension to work:
* @link https://chrome.google.com/webstore/detail/social-media-analytics-by/kiadoddngdeggkkmlaedmhghhoigccpf
*
* Use as a user script or a bookmarklet: javascript:void(... script minified version...)
* To minify (select Simple optimization mode):
* @link https://closure-compiler.appspot.com
*
* @author MaximAL
* @since 2019-01-30
* @date 2019-01-30
* @time 20:47 MSK
* @copyright © MaximAL 2019
* @link https://maximals.ru
*/
(function (document) {
const ENGAGEMENT_TRESHOLD = 2.0;
const elements = document.querySelectorAll('.wefind-post-engagement');
let found = 0;
let total = 0;
elements.forEach(function (element) {
total++;
const match = element.innerText.match(/Engagement:\s*([0-9\.]+)%/i);
if (match) {
if (parseFloat(match[1]) >= ENGAGEMENT_TRESHOLD) {
element.style.outline = '1px red solid';
element.style.fontWeight = 'bold';
element.style.color = '#ffbebe';
found++;
}
}
});
let divResult = document.querySelector('div.maximal-engagement-result');
if (!divResult) {
divResult = document.createElement('div');
divResult.classList.add('maximal-engagement-result');
document.body.appendChild(divResult);
}
const style = divResult.style;
style.position = 'fixed';
style.display = 'block';
style.top = 0;
style.left = '50%';
style.width = '160px';
style.height = '38px';
style.color = 'black';
style.fontSize = '14px';
style.backgroundColor = '#ffeada';
style.boxShadow = '0 0 10px rgba(0, 0, 0, 0.2)';
style.textAlign = 'center';
style.transition = 'all 1s';
style.opacity = 1;
if (found > 0) {
divResult.innerHTML = 'Found (≥' + ENGAGEMENT_TRESHOLD + '): <strong style="font-weight: bold">' + found + '</strong> of ' + total;
} else {
divResult.innerText = 'Nothing found :-(';
}
divResult.innerHTML += '<br/><small style="font-size: 80%">© <a href="https://maximals.ru" target="_blank">MaximAL</a> 2019</small>';
setTimeout(function () {style.opacity = 0}, 1500);
})(document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment