Skip to content

Instantly share code, notes, and snippets.

@sleemanj
Last active October 31, 2020 11:07
Show Gist options
  • Save sleemanj/b5e75f18d7292ab43e37b96e2a7ef905 to your computer and use it in GitHub Desktop.
Save sleemanj/b5e75f18d7292ab43e37b96e2a7ef905 to your computer and use it in GitHub Desktop.
Adds a button to @yaqwsx JLC PCB Component Catalog to send the (filtered) resistors to a parallel-resistor-finder so you can find parallel resistor combinations based only on resistors JLC has available (especially useful for "Basic" ones).
// ==UserScript==
// @name Resistor Paralleler For JLC Parts
// @namespace https://gist.github.com/sleemanj/b5e75f18d7292ab43e37b96e2a7ef905
// @downloadURL https://gist.github.com/sleemanj/b5e75f18d7292ab43e37b96e2a7ef905/raw/resistor-paralleler-for-jlcpcb-assembly-parts.js
// @updateURL https://gist.github.com/sleemanj/b5e75f18d7292ab43e37b96e2a7ef905/raw/resistor-paralleler-for-jlcpcb-assembly-parts.js
// @version 0.3
// @description Send the resistors to the resistor paralleler. You must add Resistance as the last column in the table.
// @author James Sleeman
// @match https://yaqwsx.github.io/jlcparts/
// @grant none
// ==/UserScript==
(function() {
'use strict';
function goToParalleler()
{
if(!document.querySelector('.w-full thead tr th:last-child').innerHTML.match(/Resistance/))
{
alert("The last column in the table must be Resistance");
return false;
}
var howManyRows = 0;
function forceTheLazyLoaderFirst()
{
if(howManyRows != document.querySelectorAll('.w-full tbody tr').length)
{
howManyRows = document.querySelectorAll('.w-full tbody tr').length;
window.scrollBy({ left:0, top:document.body.scrollHeight, behaviour:'smooth'});
window.setTimeout(forceTheLazyLoaderFirst, 500);
return;
}
var bumps = [ ];
var x = document.querySelectorAll('.w-full tbody tr td:last-child');
for(var y = 0; y < x.length; y++) { if(x.item(y).innerHTML) bumps.push(x.item(y).innerHTML.replace(/\s+/,'')); };
window.open( 'https://sparks.gogo.co.nz/resistor_paralleler.html?Bases=&Bumps='+encodeURIComponent(bumps.join(',')) );
return true;
}
forceTheLazyLoaderFirst();
}
function setup()
{
window.setTimeout(setup, 1000);
if(document.querySelector('.ourbutton')) return;
if(!document.querySelector(".pt-4 button")) return;
var a = document.createElement('button');
a.innerText = 'Open Resistor Paralleler With These Results';
a.onclick = function(){
goToParalleler();
};
a.className = 'flex-none ml-auto block flex-none bg-blue-500 hover:bg-blue-700 text-black py-1 px-2 rounded ourbutton';
document.querySelector(".pt-4 button").parentNode.insertBefore(a, document.querySelector(".pt-4 button"));
}
setup();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment