Basic browser extension support

This commit is contained in:
Eduard Urbach 2017-06-24 21:07:45 +02:00
parent 932ed7c165
commit 7e92409758
10 changed files with 75 additions and 6 deletions

View File

@ -21,7 +21,8 @@
"video",
"loading",
"fade",
"mobile"
"mobile",
"extension"
],
"scripts": {
"main": "main"

View File

@ -9,5 +9,5 @@ import (
// Render layout.
func Render(ctx *aero.Context, content string) string {
user := utils.GetUser(ctx)
return components.Layout(ctx.App, user, content)
return components.Layout(ctx.App, ctx, user, content)
}

View File

@ -1,4 +1,4 @@
component Layout(app *aero.Application, user *arn.User, content string)
component Layout(app *aero.Application, ctx *aero.Context, user *arn.User, content string)
html(lang="en")
head
title= app.Config.Title
@ -6,7 +6,7 @@ component Layout(app *aero.Application, user *arn.User, content string)
meta(name="theme-color", content=app.Config.Manifest.ThemeColor)
link(rel="manifest", href="/manifest.json")
body
#container
#container(class=utils.GetContainerClass(ctx))
#header
Navigation(user)
#content-container

View File

@ -14,6 +14,7 @@ import (
"github.com/animenotifier/notify.moe/pages/animelist"
"github.com/animenotifier/notify.moe/pages/animelistitem"
"github.com/animenotifier/notify.moe/pages/dashboard"
"github.com/animenotifier/notify.moe/pages/embed"
"github.com/animenotifier/notify.moe/pages/forum"
"github.com/animenotifier/notify.moe/pages/forums"
"github.com/animenotifier/notify.moe/pages/login"
@ -70,6 +71,7 @@ func configure(app *aero.Application) *aero.Application {
app.Ajax("/login", login.Get)
app.Ajax("/airing", airing.Get)
app.Ajax("/webdev", webdev.Get)
app.Ajax("/extension/embed", embed.Get)
// app.Ajax("/genres", genres.Get)
// app.Ajax("/genres/:name", genre.Get)

View File

@ -21,7 +21,7 @@ func Get(ctx *aero.Context) string {
animeList := viewUser.AnimeList()
if animeList == nil {
return ctx.Error(http.StatusNotFound, "Anime list not found", err)
return ctx.Error(http.StatusNotFound, "Anime list not found", nil)
}
sort.Slice(animeList.Items, func(i, j int) bool {

31
pages/embed/embed.go Normal file
View File

@ -0,0 +1,31 @@
package embed
import (
"net/http"
"sort"
"github.com/aerogo/aero"
"github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/utils"
)
// Get anime list in the browser extension.
func Get(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil {
return ctx.Error(http.StatusUnauthorized, "Not logged in", nil)
}
animeList := user.AnimeList()
if animeList == nil {
return ctx.Error(http.StatusNotFound, "Anime list not found", nil)
}
sort.Slice(animeList.Items, func(i, j int) bool {
return animeList.Items[i].FinalRating() < animeList.Items[j].FinalRating()
})
return utils.AllowEmbed(ctx, ctx.HTML(components.AnimeList(animeList)))
}

View File

@ -16,5 +16,5 @@ func Get(ctx *aero.Context) string {
return ctx.Error(http.StatusForbidden, "Not logged in", nil)
}
return ctx.HTML(components.Settings(user))
return utils.AllowEmbed(ctx, ctx.HTML(components.Settings(user)))
}

10
styles/extension.scarlet Normal file
View File

@ -0,0 +1,10 @@
.embedded
.anime-list
th
display none
#content
// font-size 0.9em
#header
display none

10
utils/allowembed.go Normal file
View File

@ -0,0 +1,10 @@
package utils
import "github.com/aerogo/aero"
// AllowEmbed allows the page to be called by the browser extension.
func AllowEmbed(ctx *aero.Context, response string) string {
// This is a bit of a hack.
ctx.SetResponseHeader("X-Frame-Options", "ALLOW-FROM chrome-extension://hjfcooigdelogjmniiahfiilcefdlpha/options.html")
return response
}

15
utils/container.go Normal file
View File

@ -0,0 +1,15 @@
package utils
import (
"github.com/aerogo/aero"
)
// GetContainerClass returns the class for the "container" element.
// In the browser extension it will get the "embedded" class.
func GetContainerClass(ctx *aero.Context) string {
if ctx.URI() == "/extension/embed" {
return "embedded"
}
return ""
}