pure Javascript implementation of some Chrome Console APIs
来源:     阅读:488
云上智慧
发布于 2020-04-24 18:15
查看主页

When I was writing bookmarklet I found that I can't use those handy Chrome Console APIs like $, $$, copy, so I have to implement them myself.

$

This is similar to document.querySelector but $ supports the second optional parameter startNode (see here) but document.querySelector does not. Instead, we need to use element.querySelector (see here).

var $ = (selector, startNode) => (startNode || document).querySelector(selector);

$$

This is similar to document.querySelectorAll.

One caviat is that the returned value is of type NodeList. It supports APIs like forEach but doesn't support map as Array does. One way to get around it is to wrap it in Array.from.

var $$ = (selector, startNode) => Array.from((startNode || document).querySelectorAll(selector));

copy

See my other post

免责声明:本文为用户发表,不代表网站立场,仅供参考,不构成引导等用途。 系统环境 服务器应用
相关推荐
go 语言中 RPC
前台面试每日 3+1 —— 第447天
如何在3天内“将Excel的功能嵌入Web 系统”|关于新手训练营,他们有话说
linux 之 jailkit
vue少量笔记20200403
首页
搜索
订单
购物车
我的