Last active
April 8, 2020 16:03
-
-
Save KevinBatdorf/136b648cedccc2a127ff5cde0d354e1a to your computer and use it in GitHub Desktop.
Filter unwanted AlpineJS attributes from Tailwind UI components
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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