Skip to content

Instantly share code, notes, and snippets.

View dwsmart's full-sized avatar

Dave Smart dwsmart

View GitHub Profile
@dwsmart
dwsmart / add_string_to_href.js
Last active January 13, 2020 11:43
Add a string to the start of all internal links on a page.
//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 December 6, 2019 15:52
Puppeteer Shadow Dom > Dom
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