-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gusted
committed
May 17, 2021
1 parent
5fc70ce
commit 12593be
Showing
14 changed files
with
181 additions
and
30 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
root = "." | ||
tmp_dir = "tmp" | ||
|
||
[build] | ||
exclude_dir = ["typescript"] |
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {ShareButton} from './share-button'; | ||
import {BroadcastReady} from './third-party'; | ||
import {addDOMReadyListener, isDOMReady} from './utils/dom'; | ||
|
||
const setup = () => { | ||
ShareButton(); | ||
BroadcastReady(); | ||
} | ||
|
||
// Setup contains code that only should be handle | ||
// when the DOM is ready to go. | ||
// Any other code shouldn't depend on this setup function. | ||
if (isDOMReady()) { | ||
setup(); | ||
} else { | ||
addDOMReadyListener(setup); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// +build ignore | ||
|
||
package main | ||
|
||
import ( | ||
"log" | ||
"os" | ||
|
||
"github.com/evanw/esbuild/pkg/api" | ||
) | ||
|
||
var ( | ||
isDebug = getEnv("DEBUG", "false") == "true" | ||
isProduction = !isDebug | ||
shouldWatch = getEnv("WATCH", "false") == "true" | ||
) | ||
|
||
func getEnv(name, fallback string) string { | ||
if val, set := os.LookupEnv(name); set { | ||
return val | ||
} | ||
return fallback | ||
} | ||
|
||
func main() { | ||
sourceMap := api.SourceMapInline | ||
var watch *api.WatchMode | ||
if isProduction { | ||
sourceMap = api.SourceMapNone | ||
} | ||
if shouldWatch { | ||
watch = &api.WatchMode{ | ||
OnRebuild: func(result api.BuildResult) { | ||
if len(result.Errors) > 0 { | ||
log.Printf("watch build failed: %d errors\n", len(result.Errors)) | ||
} else { | ||
log.Printf("watch build succeeded: %d warnings\n", len(result.Warnings)) | ||
} | ||
}, | ||
} | ||
} | ||
buildResult := api.Build(api.BuildOptions{ | ||
EntryPoints: []string{"./typescript/main.ts"}, | ||
Outfile: "./static/js/main.js", | ||
Bundle: true, | ||
Write: true, | ||
LogLevel: api.LogLevelInfo, | ||
Platform: api.PlatformBrowser, | ||
MinifySyntax: isProduction, | ||
MinifyWhitespace: isProduction, | ||
MinifyIdentifiers: isProduction, | ||
Sourcemap: sourceMap, | ||
Target: api.ES2017, | ||
Charset: api.CharsetUTF8, | ||
Format: api.FormatIIFE, | ||
Watch: watch, | ||
Banner: map[string]string{ | ||
"js": "\"use strict\";", | ||
}, | ||
}) | ||
|
||
if len(buildResult.Errors) > 0 { | ||
os.Exit(1) | ||
} | ||
|
||
// When we are watching we shouldn't exit program. | ||
// So a quick and dirty hack to let an never end loop run. | ||
// From Go 1.15 this section will be optimized away into (amd64). | ||
// any_label: | ||
// XCHGL AX, AX | ||
// JMP any_label | ||
// Whereby XCHGL acts as a "write block". | ||
if shouldWatch { | ||
for { | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export function ShareButton() { | ||
const i = document.getElementById('share') as HTMLInputElement; | ||
const shareButton = document.getElementById('btn-share') as HTMLButtonElement; | ||
shareButton.addEventListener("click", () => { | ||
i.select(); | ||
document.execCommand('copy'); | ||
i.blur(); | ||
shareButton.classList.add('copied'); | ||
}); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const onMessage = (ev: MessageEvent<any>) => { | ||
if (!ev.data || !ev.data.type) { | ||
return; | ||
} | ||
switch (ev.data.type) { | ||
case "usw-remove-stylus-button": { | ||
document.querySelector('a#stylus').remove(); | ||
} | ||
} | ||
} | ||
|
||
window.addEventListener("message", onMessage) | ||
|
||
export function BroadcastReady() { | ||
window.dispatchEvent(new MessageEvent('message', { | ||
data: {type: "usw-ready"}, | ||
origin: "https://userstyles.world" | ||
})); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2017", | ||
"baseUrl": ".", | ||
"module": "es2015", | ||
"moduleResolution": "node", | ||
"lib": [ | ||
"es2015", | ||
"es2017", | ||
"dom", | ||
"dom.iterable" | ||
], | ||
"downlevelIteration": true, | ||
"noEmit": true, | ||
"incremental": true, | ||
"isolatedModules": true | ||
}, | ||
"exclude": [ | ||
"node_modules" | ||
] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const readyStateListeners = new Set<() => void>(); | ||
|
||
export const isDOMReady = () => document.readyState === 'complete' || document.readyState === 'interactive'; | ||
export const addDOMReadyListener = (listener: () => void) => readyStateListeners.add(listener); | ||
|
||
if (!isDOMReady()) { | ||
const onReadyStateChange = () => { | ||
if (isDOMReady()) { | ||
document.removeEventListener('readystatechange', onReadyStateChange); | ||
readyStateListeners.forEach((listener) => listener()); | ||
readyStateListeners.clear(); | ||
} | ||
}; | ||
document.addEventListener('readystatechange', onReadyStateChange); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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