Skip to content

Instantly share code, notes, and snippets.

View captainbrosset's full-sized avatar
👋

Patrick Brosset captainbrosset

👋
View GitHub Profile
@captainbrosset
captainbrosset / position.css
Created March 5, 2021 09:36
Code snippets for the "How we built the DevTools Tooltips" article
.tooltips-wrapper {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
@captainbrosset
captainbrosset / generate-path.ts
Created March 5, 2021 09:34
Code snippets for the "How we built the DevTools Tooltips" article
// Get the first segment's start point.
const points = [segments[0].start];
// And append the end point of each segment, one by one, after that.
for (const segment of segments) {
if (!segment) {
continue;
}
points.push(segment.end);
}
@captainbrosset
captainbrosset / order-segments.ts
Created March 5, 2021 09:13
Code snippets for the "How we built the DevTools Tooltips" article
// Our list of all segments. Each one being an object like
// {start: {x, y}, end: {x, y}}
const allSegments = [...];
// Start at the first segment.
const orderedSegments = [allSegments[0]];
while (true) {
// The previous segment.
const previous = orderedSegments[orderedSegments.length - 1];
@captainbrosset
captainbrosset / get-coordinates.ts
Created March 5, 2021 09:10
Code snippets for the "How we built the DevTools Tooltips" article
// Get the coordinates of the element.
const rect = element.getBoundingClientRect();
// Apply any offset that might be configured for it.
for (const {direction, size} of offsets) {
if (direction === Direction.Top) {
rect.y -= size;
rect.height += size;
}
if (direction === Direction.Right) {
rect.width += size;
@captainbrosset
captainbrosset / queryselector-shadow.ts
Created March 5, 2021 09:08
Code snippets for the "How we built the DevTools Tooltips" article
function querySelectorShadow(selector: string): Element|null {
let found: Element|null = null;
const search = (root: Element|ShadowRoot) => {
const iter = document.createTreeWalker(
root,
NodeFilter.SHOW_ELEMENT,
);
do {
const currentNode = iter.currentNode as HTMLElement;
@captainbrosset
captainbrosset / intersections.ts
Last active March 5, 2021 09:08
Code snippets for the "How we built the DevTools Tooltips" article
{
// The ID of the area we're highlighting
"elements-panel": {
// Some information for the displayed content
"tooltip": {
"title": "...",
"description": "...",
},
// The list of DOM elements to wrap
"selectors": [
const {writeFile} = require('fs');
const CDP = require('chrome-remote-interface');
const WIDTH = 892;
const HEIGHT = 689;
const URL = 'https://google.com';
let client;
async function getClient() {
if (!client) {
@captainbrosset
captainbrosset / data.txt
Created July 9, 2020 15:24
css grid website scraping
column-gap: 0.375rem
column-gap: 1rem
column-gap: 2rem
column-gap: 2vw
column-gap: 35px
column-gap: 5rem
column-gap:.625rem
column-gap:1.875rem
column-gap:10px
column-gap:10px
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// Verify the content page can be zoomed in within RDM.
// We do not verify here that the fullZoom level applied to the page before RDM starts is
// carried over to the content page after RDM is open. This bug hasn't been fixed.
// See bug 1529166.
function findRulesMatching(el) {
const rules = [];
for (const { cssRules } of document.styleSheets) {
for (const rule of cssRules) {
if (el.matches(rule.selectorText)) {
rules.push(rule);
}
}
}