lang/js/ MySnippets1


// jQuery-lite:
const q = (x,y=document) => y.querySelector(x)
const qq = (x,y=document) => Array.from(y.querySelectorAll(x))
// For taking a chunk of a webpage and making it the whole page.
const maxi = (x,y=document) => { let a; if( a = q(x,y) ) { document.body.innerHTML = a.innerHTML } }
const kill = (x,y=document) => qq(x,y).forEach(x => x.remove())

scraping example: get hrefs for all pdf links in a div element with class download

copy(Array.from(document.querySelectorAll("div.download a"))
  .map(x => x.getAttribute("href"))
  .filter(x => x.match(/\.pdf/))
  .join("\n"))