Skip to content

Instantly share code, notes, and snippets.

@zaygraveyard
Last active March 5, 2020 18:13
Show Gist options
  • Save zaygraveyard/1593567208039623cff3edd5904272a3 to your computer and use it in GitHub Desktop.
Save zaygraveyard/1593567208039623cff3edd5904272a3 to your computer and use it in GitHub Desktop.
Bookmarklet to filter Histoire d'Or's rings by size

HOF

javascript:(function(t%2Ce%2Cl%2Cn%2Ci%2Ca%2Co%2Cr%2Cd)%7Bif((o%3Dt.z%3Dt.z%7C%7C%7B%7D).t)return%20o.t()%3Bd%3De%2B%22All%22%2Cr%3Dl%2B%22%3Anot(%5Bdata-zc%5D)%22%2Co.F%3Dt%3D%3E%7BzF.disabled%3D!0%2Ci(a%5Bd%5D(r)%2Ct%3D%3Et%5Be%5D(n)%7C%7C(t.style.display%3D%22none%22))%2CPromise.all(i(a%5Bd%5D(r%2B%60%20%24%7Bn%7D%20a%60)%2Casync(t%2Ce%2Cn%2Co)%3D%3E%7B(e%3Da.createElement(%22html%22)).innerHTML%3Dawait(await%20fetch(t.href)).text()%2C0!%3D%3D(n%3Di(e%5Bd%5D('.select-style%20%5Bdata-code%3D%22size%22%5D%20option%2C%20.declination-selector%20option')%2C(t%2Ce)%3D%3E(e%3Dt.innerText.match(%2F%5Cd%2B%2Fg))%3FparseFloat(e%5B0%5D)%3Anull).filter(Boolean)).length%26%26((o%3Dt.closest(l)).setAttribute(%22data-zc%22%2C%22%22)%2CMath.min(...n)%3E46%26%26(o.style.display%3D%22none%22))%7D)).then(t%3D%3EzF.disabled%3D!1)%7D%2Co.M%3Dt%3D%3E%7B(t%3Da%5Be%5D(%22.infinite-view%22))%3Ft.click()%3A!a%5Be%5D(%22.loading%22)%26%26o.r%26%26o.A()%7D%2Co.A%3Dt%3D%3E%7BclearInterval(o.r)%2Co.r%3Do.r%3F0%3AsetInterval(o.M%2C100)%2CzA.innerText%3Do.r%3F%22Stop%22%3A%22All%22%7D%2Co.t%3De%3D%3E%7Bt.zt%3Ft.zt.style.display%3Dt.zt.style.display%3F%22%22%3A%22none%22%3Aa.body.insertAdjacentHTML(%22beforeend%22%2C%60%3Cdiv%20id%3D%22zt%22%20style%3D%22position%3Afixed%3Btop%3A0%3Bleft%3A0%3Bbackground%3A%23ccc%3Bpadding%3A10px%3Bz-index%3A999%22%3E%24%7B%22Filter%2CMore%2CAll%22.split(%22%2C%22).map(t%3D%3E%60%3Cbutton%20id%3D%22z%24%7Bt%5B0%5D%7D%22%20onclick%3D%22z.%24%7Bt%5B0%5D%7D()%22%3E%24%7Bt%7D%3C%2Fbutton%3E%60).join(%22%22)%7D%3C%2Fdiv%3E%60)%7D%2Co.t()%7D)(this%2C%22querySelector%22%2C%22.product-line%22%2C%22.product-label%22%2CArray.from%2Cdocument)

(function(w, _, p, pl, a, d, z, s, _a) {
z = w.z = w.z || {};
if (z.t) return z.t();
_a = _ + 'All';
s = p + ':not([data-zc])';
z.F = x => {
zF.disabled = true;
a(d[_a](s), e => (e[_](pl) || (e.style.display = 'none')));
Promise.all(a(d[_a](s + ` ${pl} a`), async (l, html, sizes, product) => {
html = d.createElement('html');
html.innerHTML = await (await fetch(l.href)).text();
sizes = a(html[_a]('.select-style [data-code="size"] option, .declination-selector option'), (o, match) => {
match = o.innerText.match(/\d+/g);
return match ? parseFloat(match[0]) : null;
}).filter(Boolean);
if (sizes.length === 0) {
return;
}
product = l.closest(p);
product.setAttribute('data-zc', '');
if (Math.min(...sizes) > 46) {
product.style.display = 'none';
}
})).then(x => zF.disabled = false);
};
z.M = (btn) => {
btn = d[_]('.infinite-view');
if (btn) {
btn.click();
} else if (!d[_]('.loading') && z.r) {
z.A();
}
};
z.A = x => {
clearInterval(z.r);
z.r = z.r ? 0 : setInterval(z.M, 100);
zA.innerText = z.r ? 'Stop' : 'All';
};
z.t = x => {
if (w.zt) {
w.zt.style.display = w.zt.style.display ? '' : 'none';
} else {
d.body.insertAdjacentHTML('beforeend', `<div id="zt" style="position:fixed;top:0;left:0;background:#ccc;padding:10px;z-index:999">${'Filter,More,All'.split(',').map(l => `<button id="z${l[0]}" onclick="z.${l[0]}()">${l}</button>`).join('')}</div>`);
}
};
z.t();
})(this, 'querySelector', '.product-line', '.product-label', Array.from, document)
!function(t,e,l,n,i,a,o,r,d){if((o=t.z=t.z||{}).t)return o.t();d=e+"All",r=l+":not([data-zc])",o.F=t=>{zF.disabled=!0,i(a[d](r),t=>t[e](n)||(t.style.display="none")),Promise.all(i(a[d](r+` ${n} a`),async(t,e,n,o)=>{(e=a.createElement("html")).innerHTML=await(await fetch(t.href)).text(),0!==(n=i(e[d]('.select-style [data-code="size"] option, .declination-selector option'),(t,e)=>(e=t.innerText.match(/\d+/g))?parseFloat(e[0]):null).filter(Boolean)).length&&((o=t.closest(l)).setAttribute("data-zc",""),Math.min(...n)>46&&(o.style.display="none"))})).then(t=>zF.disabled=!1)},o.M=t=>{(t=a[e](".infinite-view"))?t.click():!a[e](".loading")&&o.r&&o.A()},o.A=t=>{clearInterval(o.r),o.r=o.r?0:setInterval(o.M,100),zA.innerText=o.r?"Stop":"All"},o.t=e=>{t.zt?t.zt.style.display=t.zt.style.display?"":"none":a.body.insertAdjacentHTML("beforeend",`<div id="zt" style="position:fixed;top:0;left:0;background:#ccc;padding:10px;z-index:999">${"Filter,More,All".split(",").map(t=>`<button id="z${t[0]}" onclick="z.${t[0]}()">${t}</button>`).join("")}</div>`)},o.t()}(this,"querySelector",".product-line",".product-label",Array.from,document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment