https://github.com/no-gravity/dqs.js
Which turns document.querySelector('.some .thing') into dqs('.some .thing').
The other one is Handlebars:
https://github.com/handlebars-lang/handlebars.js/
Which I use for all my frontend templating needs.
https://github.com/no-gravity/dqs.js
Which turns document.querySelector('.some .thing') into dqs('.some .thing').
The other one is Handlebars:
https://github.com/handlebars-lang/handlebars.js/
Which I use for all my frontend templating needs.
const $ = document.querySelector.bind(document);
const $$ = document.querySelectorAll.bind(document); function $(selector, element = document) {
return element.querySelector(selector);
}
function $$(selector, element = document) {
return Array.from(element.querySelectorAll(selector));
}
Reference on more magic available in the console (there’s a lot of good stuff):• https://firefox-source-docs.mozilla.org/devtools-user/web_co... (I think “:help” is my new favourite: opens that URL, which is not particularly discoverable)
• https://developer.chrome.com/docs/devtools/console/utilities...
const $ = (query) => document.querySelector(query);
const $$ = (query) => document.querySelectorAll(query);
(How do I write monospace on HN?)
Two-space indentation.
Thank youLine that start with four spaces
like this Looks like 2 spaces are sufficient. But I sympathize with 4-space indentation. import {qsA} from './dqs.js';
rows = qsA(myTable, 'tr');myTable.qsA('tr')
TypeError: myTable.qsA is not a function
HTMLElement.prototype.qsA = HTMLElement.prototype.querySelectorAll;
Now myTable.qsA('tr') will work. You can try it right here on the HN page in the browser console: HTMLElement.prototype.qsA = HTMLElement.prototype.querySelectorAll;
document.querySelector('#hnmain').qsA('tr');
Why do you prefer chaining?I suppose habit plus I find it easier to grok in that order, targetelement->childelements->foreach.
how much is truly saved by this? these seem like the things of a solo dev vs building something for other people to follow
You are talking to me on a site done by one.
This is the frontend code:
… upvote/downvotes are does by fetching an "image", i.e., it does a GET request with side-effects! … also seems like a trivial CSRF vuln, too…