Skip to content

Instantly share code, notes, and snippets.

@Nodws
Last active October 18, 2024 23:14
Show Gist options
  • Save Nodws/8778622 to your computer and use it in GitHub Desktop.
Save Nodws/8778622 to your computer and use it in GitHub Desktop.
JQuery
(function (a, e, h, b, d) {
b = e.createElement(h);
b.src = "//www.googleadservices.com/pagead/conversion.js"; b.async=1;
d = e.getElementsByTagName(h)[0];
d.parentNode.insertBefore(b, d);
})(window, document, "script");
$('body').on('click','a[href*="pop-"]',function(e){
e.preventDefault();
var id = $(this).attr('href').split('#pop-')[1];
elementorProFrontend.modules.popup.showPopup({'id':id});
});
var wrap = $(".navbar");
$(document).scroll(function(e) {
if ($(this).scrollTop() > 247)
wrap.addClass("fixed");
else
wrap.removeClass("fixed");
});
javascript:(function() {
const colors = [ "#18445D", "#1F7799", "#04C4D9", "#79E6F2", "#ced74d", "#acfa70"];
const headings = document.querySelectorAll('h1, h2, h3, h4, h5, h6');
const containerId = 'heading-list-container';
if (document.getElementById(containerId)) return;
const container = document.createElement('div');
container.id = containerId;
container.style.cssText = ` position: fixed; top: 1vh; left: 1vh; width: 50vw; max-width: 500px; max-height: 80vh; overflow-y: auto; background-color: #fffd; border: 1px solid #ccc;border-radius:5px; padding: 10px; font-family: sans-serif; font-size: 14px; z-index: 999999; transition: max-height 0.3s; `;
const header = document.createElement('div');
header.style.cssText = `display: flex; justify-content: space-between; align-items: center;`;
const title = document.createElement('b');
title.innerText = 'Headings List';
header.appendChild(title);
const closeBtn = document.createElement('button');
closeBtn.innerText = '[Close]';
closeBtn.style.cssText = 'background:#aaa; border:none; cursor:pointer; font-size:14px;padding:5px 10px';
closeBtn.onclick = () => {
if (container.style.maxHeight === '50vh') {
container.style.maxHeight = '2vh';
closeBtn.innerText = '[Open]';
} else {
container.style.maxHeight = '50vh';
closeBtn.innerText = '[Close]';
}
};
header.appendChild(closeBtn);
container.appendChild(header);
let h1Count = 0;
headings.forEach((heading, idx) => {
const level = parseInt(heading.tagName[1]);
if (level === 1) h1Count++;
const headingItem = document.createElement('div');
headingItem.style.cssText = `
color: ${colors[level - 1]};
font-size: ${20 - level}px;
cursor: pointer;
`;
headingItem.innerHTML = `<b>${heading.tagName}</b>: ${heading.textContent.trim().substring(0, 50)}`;
if (level === 1 && h1Count > 1) {
headingItem.innerHTML += `<small>⚠️ No more than 1 H1 tag!</small>`;
}
headingItem.onclick = () => {
document.querySelectorAll('.highlighted').forEach(el => el.classList.remove('highlighted'));
heading.scrollIntoView({ behavior: 'smooth', block: 'center' });
heading.classList.add('highlighted');
heading.style.outline = `2px solid ${colors[level - 1]}`;
};
container.appendChild(headingItem);
});
const style = document.createElement('style');
style.textContent = ` .highlighted { background-color: yellow !important; } `;
document.head.appendChild(style);
document.body.appendChild(container);
})();
setInterval(function() {
$("#refresh").load(location.href+" #refresh>*","");
}, 10000); // milliseconds to wait
String.prototype.str_replace = function(search, replacement) {
var target = this;
return target.replace(new RegExp(search, 'g'), replacement);
};
string.str_replace('needle','replaced');
var maxheight = 0;
$("div.col").each(function(){
if($(this).height() > maxheight) { maxheight = $(this).height(); }
});
$("div.col").height(maxheight);
if(location.hash){
var e = document.getElementById(location.hash.substr(1));
e.scrollIntoView();
}
$("a[href='#top']").click(function() {
//$("#section").offset().top
$("html, body").animate({ scrollTop: 0 }, "slow");
return false;
});
const updateDebounceText = debounce(() => {
incrementCount(debounceText)
})
const updateThrottleText = throttle(() => {
incrementCount(throttleText)
}, 100)
function debounce(cb, delay = 1000) {
let timeout
return (...args) => {
clearTimeout(timeout)
timeout = setTimeout(() => {
cb(...args)
}, delay)
}
}
function throttle(cb, delay = 1000) {
let shouldWait = false
let waitingArgs
const timeoutFunc = () => {
if (waitingArgs == null) {
shouldWait = false
} else {
cb(...waitingArgs)
waitingArgs = null
setTimeout(timeoutFunc, delay)
}
}
return (...args) => {
if (shouldWait) {
waitingArgs = args
return
}
cb(...args)
shouldWait = true
setTimeout(timeoutFunc, delay)
}
}
document.addEventListener("mousemove", e => {
incrementCount(defaultText)
updateDebounceText()
updateThrottleText()
})
function incrementCount(element) {
element.textContent = (parseInt(element.innerText) || 0) + 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment