Skip to content

Instantly share code, notes, and snippets.

@KevinBatdorf
Last active April 8, 2020 16:03
Show Gist options
  • Save KevinBatdorf/136b648cedccc2a127ff5cde0d354e1a to your computer and use it in GitHub Desktop.
Save KevinBatdorf/136b648cedccc2a127ff5cde0d354e1a to your computer and use it in GitHub Desktop.
Filter unwanted AlpineJS attributes from Tailwind UI components
// ==UserScript==
// @name Filter unwanted AlpineJS attributes from Tailwind UI components
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Remove Alpine JS code from Tailwind Ui copy/paste
// @author https://github.com/KevinBatdorf
// @match https://tailwindui.com/components/*
// @grant none
// ==/UserScript==
const code = document.querySelectorAll('[x-ref=clipboardCode]')
Array.from(code).forEach(node => {
node.addEventListener('copy', event => {
let selection = window.getSelection()
.toString().split(/\r?\n/)
.map(function(string, index) {
const alpine = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>| [:@x-][^"]*="[^"]*"|(\r\n)/g
return string.replace(alpine, '')
})
.filter(string => string.length)
.join("\r\n")
event.clipboardData.setData('text/plain', selection)
event.preventDefault()
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment