Skip to content

Instantly share code, notes, and snippets.

@heymartinadams
Created September 24, 2019 04:43
Show Gist options
  • Save heymartinadams/6a70c8c4d43720ced5b0cec34f638e3a to your computer and use it in GitHub Desktop.
Save heymartinadams/6a70c8c4d43720ced5b0cec34f638e3a to your computer and use it in GitHub Desktop.
(async () => {
const webdriver = require('selenium-webdriver')
const chrome = require('selenium-webdriver/chrome')
const chromedriver = require('chromedriver')
// Run Selenium with Chrome on Node
chrome.setDefaultService(new chrome.ServiceBuilder(chromedriver.path).build())
let driver = new webdriver.Builder()
.withCapabilities(webdriver.Capabilities.chrome())
// but make it headless, meaning we won’t see a browser window open
.setChromeOptions(new chrome.Options().headless())
.build()
try {
// Head on over to the Webflow site
await driver.get('https://__WEBFLOW_SITE__.webflow.io')
// Find and open the CSS file...
const cssFile = await driver.findElement(webdriver.By.tagName('link')).getAttribute('href')
await driver.get(cssFile)
// ...get its contents...
const allCss = await driver.findElement(webdriver.By.tagName('pre')).getAttribute('innerText')
// ...and, finally, just get the part that’s your own custom css.
const customCss = allCss.split(
'========================================================================== */'
)[3]
// Overwrite your custom css file on your hard drive with your new css
const fs = require('fs')
fs.writeFileSync(
// Path to your CSS file on your hard drive; to get the path of your css file, drag it from Finder into Terminal (on Mac)
'/Users/__PATH_TO_YOUR_CSS_FILE__/src/assets/css/index.css',
customCss
)
} finally {
// and be sure to quit Selenium
await driver.quit()
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment