Skip to content

Instantly share code, notes, and snippets.

@yutakahashi114
Created August 23, 2021 13:23
Show Gist options
  • Save yutakahashi114/60b573d4101cd8ac9af12915b7a8a50a to your computer and use it in GitHub Desktop.
Save yutakahashi114/60b573d4101cd8ac9af12915b7a8a50a to your computer and use it in GitHub Desktop.
package main
import (
"io/ioutil"
"log"
"net/http"
"os"
"strings"
)
func main() {
target := os.Args[1]
url := strings.Replace(target, "https://gist.github.com", "http://gist.github.com", 1)
// url := strings.Split(strings.Split(target, `<script src="`)[1], `"></script>`)[0]
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
log.Fatal(err)
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
log.Fatal(resp.StatusCode)
}
bodyBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
bodyString := string(bodyBytes)
bodyString =
strings.ReplaceAll(
strings.ReplaceAll(
strings.ReplaceAll(
strings.ReplaceAll(
strings.ReplaceAll(
strings.ReplaceAll(
bodyString, "\\n", "\n"),
`\"`, `"`),
`\/`, `/`),
"\\`", "`"),
"\\$", "$"),
`\\`, `\`)
out := `<!--<script src="` + target + `"></script>-->` + "\n"
for _, str := range strings.Split(bodyString, "document.write('")[1:] {
htmlTags := strings.Split(str, "')")[0]
out += htmlTags + "\n"
}
file, _ := os.Create(`./out.html`)
defer file.Close()
_, err = file.Write([]byte(out))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment