Skip to content

Instantly share code, notes, and snippets.

Dave Smart dwsmart

View GitHub Profile
View move_shadow_to_light.js
//Run this in the console, will cooy the shadow DOM to the light. Will only work for open ones, and will not recurse nested shadow DOMs
for (let elMnt of document.getElementsByTagName('*')) {
if (elMnt.shadowRoot) elMnt.innerHTML = elMnt.shadowRoot.innerHTML;
}
View move_shadow_to_light.js
//Run this in the console, will cooy the shadow DOM to the light. Will only work for open ones, and will not recurse nested shadow DOMs
for (let elMnt of document.getElementsByTagName('*')) {
if (elMnt.shadowRoot) elMnt.innerHTML = elMnt.shadowRoot.innerHTML;
}
View move_shadow_to_light.js
//Run this in the console, will cooy the shadow DOM to the light. Will only work for open ones, and will not recurse nested shadow DOMs
for (let elMnt of document.getElementsByTagName('*')) {
if (elMnt.shadowRoot) elMnt.innerHTML = elMnt.shadowRoot.innerHTML;
}
@dwsmart
dwsmart / shift.js
Last active Jan 23, 2020
Cumulative Shift Example
View shift.js
const puppeteer = require('puppeteer');
/* variables to allow for user-agent / device.
example use: URL='https://tamethebots.com' useragent='Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.96 Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)' viewportw=412 viewporth=732 node shift.js
*/
const url = process.env.URL || 'https://tamethebots.com/';
const useragent = process.env.useragent || 'Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.96 Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)';
const viewportw = process.env.viewportw || 412;
const viewporth = process.env.viewporth || 732;
const threeGee = {
'offline': false,
@dwsmart
dwsmart / codeCover.js
Created Jan 22, 2020
Code Coverage in Puppetter
View codeCover.js
// npm install puppeteer
const puppeteer = require('puppeteer');
/* variables to allow for user-agent / screensize choice
example use: URL='https://tamethebots.com' useragent='Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.96 Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)' viewportw=412 viewporth=732 node codeCover.js
*/
const url = process.env.URL || 'https://www.example.com';
const useragent = process.env.useragent || 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)';
const viewportw = process.env.viewportw || 1920;
const viewporth = process.env.viewporth || 1696;
@dwsmart
dwsmart / add_string_to_href.js
Last active Jan 13, 2020
Add a string to the start of all internal links on a page.
View add_string_to_href.js
//get base url
const getUrl = window.location;
const baseUrl = getUrl .protocol + "//" + getUrl.host + "/";
// the string you want to append
const stringToAdd = "test/"
// get all a tags
let elements = document.getElementsByTagName('a');
for (let node of elements) {
// is this internal to the site? If so update the link
if(node.href.startsWith(baseUrl)){
@dwsmart
dwsmart / test.js
Last active Dec 6, 2019
Puppeteer Shadow Dom > Dom
View test.js
const puppeteer = require('puppeteer');
const url = process.env.URL || 'https://lit-element.polymer-project.org/';
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(url);
await page.evaluate(() => {
// loop through elements and copy shadow to inner
You can’t perform that action at this time.