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
Array.from(document.styleSheets) | |
.filter((sheet) => { | |
try { | |
sheet.cssRules; | |
return true; | |
} catch (err) { | |
console.log( | |
`Due to CORS issues, this script can't access "${sheet.href}"` | |
); | |
return false; |
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
styleSheets.map((sheet) => | |
Array.from(sheet.cssRules).map((rule) => | |
rule.type === rule.FONT_FACE_RULE | |
? { /* include this rule */ } | |
: rule.type === rule.STYLE_RULE | |
? { /* include this rule if above-the-fold */ } | |
: rule.type === rule.MEDIA_RULE | |
? Array.from(rule.cssRules) | |
.map((mediaRule) => | |
mediaRule.type === mediaRule.FONT_FACE_RULE |
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
Array.from(document.querySelectorAll(rule.selectorText)).some( | |
(node) => | |
node.getBoundingClientRect().top < window.innerHeight && | |
window.getComputedStyle(node).display !== 'none' | |
) |
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
cssRuleList | |
.flat() | |
.filter((rule) => rule != null && !new RegExp(/^@media.*{}$/).test(rule)) | |
.join(' '); |
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
<link | |
rel="preload" | |
as="image" | |
imagesrcset="/subsecond.webp?width=414&quality=70 414w,/subsecond.webp?width=785&quality=70 785w,/subsecond.webp?width=1024&quality=70 1024w,/subsecond.webp?width=1600&quality=70 1600w" | |
imagesizes="100vw" | |
media="(-webkit-min-device-pixel-ratio: 0.1) and (-webkit-max-device-pixel-ratio: 1)" | |
/> | |
<link | |
rel="preload" | |
as="image" |
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
function __ss(){fetch("/checkout",{method:"POST"}).then((b,c)=>{if(c)throw c;if(b.url.includes("/cart"))return;let a=document.createElement("link");a.setAttribute("rel","prefetch"),a.setAttribute("href",b.url),a.setAttribute("id","_ss_pre"),document.head.append(a),Array.from(document.querySelectorAll("button[name='checkout']")).forEach(a=>{a.setAttribute("type","button"),a.setAttribute("onclick","window.location = '"+b.url+"';")})})}__ss(),function(a,b){"function"==typeof b&&(a.fetch=function(){var c=b.apply(this,arguments);if(arguments[0].includes("cart")){let a=document.getElementById("_ss_pre");if(null==a)__ss();else{let d=a.getAttribute("href");a.setAttribute("href",""),setTimeout(()=>{a.setAttribute("href",d),Array.from(document.querySelectorAll("button[name='checkout']")).forEach(a=>{a.setAttribute("type","button"),a.setAttribute("onclick","window.location = '"+d+"';")})},500)}}return c})}(window,window.fetch) |
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
S('JSXOpeningElement.Button JSXAttribute.primary').text('type="primary"'); |
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
S('JSXOpeningElement').each((openingTag) => { | |
const attributes = openingTag.children('JSXAttribute'); | |
const sortedAttributes = attributes | |
.map((attribute) => attribute.text()) | |
.sort(); | |
attributes.each((attribute, i) => attribute.text(sortedAttributes[i])); | |
}); |
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
S('Program').each((file) => { | |
const imports = file | |
.children('ImportDeclaration') | |
.map((imp) => ({ | |
text: imp.text(), | |
hasNamedImports: imp.children().length !== 1, | |
packageName: imp.children('Literal').text(), | |
})) | |
.sort((a, b) => (a.packageName > b.packageName ? -1 : 1)); |
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
const { parsers: typescriptParsers } = require('prettier/parser-typescript'); | |
const { parsers: javascriptParsers } = require('prettier/parser-babel'); | |
const S = require('subsecond'); | |
function preprocess(text, opts) { | |
S.load({ 'any.tsx': text }); | |
// A quick test to make sure everything works. | |
S().append('// its working!'); |