Skip to content
This repository has been archived by the owner on Oct 3, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1268 from nukooo/nowPlaying
Browse files Browse the repository at this point in the history
Improve now playing banner
  • Loading branch information
bakape committed Feb 10, 2021
2 parents 6de2e1b + fb71b55 commit 34e2cbe
Show file tree
Hide file tree
Showing 22 changed files with 315 additions and 388 deletions.
9 changes: 5 additions & 4 deletions client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Post, FormModel, PostView, lightenThread } from './posts'
import { PostLink, Command, PostData, ImageData, ModerationEntry } from "./common"
import { postAdded } from "./ui"
import { incrementPostCount } from "./page"
import { posterName } from "./options"
import { getPostName } from "./options"
import { OverlayNotification } from "./ui"
import { setCookie } from './util';

Expand Down Expand Up @@ -48,9 +48,10 @@ function handle(id: number, fn: (m: Post) => void) {

// Insert a post into the models and DOM
export function insertPost(data: PostData) {
// R/a/dio song name override
if (posterName()) {
data.name = posterName()
// Now playing post name override
const postName = getPostName()
if (postName !== undefined) {
data.name = postName
}

const existing = posts.get(data.id)
Expand Down
41 changes: 24 additions & 17 deletions client/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,30 @@ async function start() {
await loadFromDB(page.thread)
}

// Check for legacy options and remap
const oldNowPlaying = localStorage.getItem("nowPlaying")
switch (oldNowPlaying) {
case "false":
case "none":
localStorage.setItem("nowPlaying", "" + (0 ^ 0));
break;
case "true":
case "r/a/dio":
localStorage.setItem("nowPlaying", "" + (0 ^ 1));
break;
case "eden":
localStorage.setItem("nowPlaying", "" + (0 ^ 2));
break;
case "both":
localStorage.setItem("nowPlaying", "" + (0 ^ 1 ^ 2));
break;
// Migrate nowPlaying options
const nowPlaying = localStorage.getItem("nowPlaying")
if (nowPlaying !== null) {
switch (nowPlaying) {
case "true":
case "r/a/dio":
localStorage.setItem("radio", "true")
break
case "eden":
localStorage.setItem("eden", "true")
break
case "both":
localStorage.setItem("radio", "true")
localStorage.setItem("eden", "true")
break
default:
const flags = parseInt(nowPlaying, 10)
for (const [i, key] of ["radio", "eden", "shamiradio"].entries()) {
if (flags & 1 << i) {
localStorage.setItem(key, "true")
}
}
}
localStorage.removeItem("nowPlaying")
}

initOptions()
Expand Down
16 changes: 5 additions & 11 deletions client/options/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { bgVideos } from "../state"
export { store as storeBackground } from "./background"
export { store as storeMascot } from "./mascot"
export * from "./specs"
export { posterName } from "./nowPlaying"
export { getPostName } from "./nowPlaying"
export { persistMessages } from "./meguTV"

// Delete legacy options localStorage entry, if any
Expand All @@ -28,10 +28,10 @@ interface Options extends ChangeEmitter {
postInlineExpand: boolean
relativeTime: boolean
meguTV: boolean
nowPlaying: number
horizontalNowPlaying: boolean
radio: boolean
eden: boolean
shami: boolean
shamiradio: boolean
bgVideo: string
bgMute: boolean
horizontalPosting: boolean
Expand Down Expand Up @@ -105,9 +105,6 @@ class OptionModel {

// Retrieve option value from storage and parse result. If none, return
public get(): any {
if (this.spec.getfn) {
return this.spec.getfn();
}
const stored = this.read()
if (!stored) {
return this.spec.default
Expand Down Expand Up @@ -141,7 +138,7 @@ class OptionModel {

// Write value to localStorage, if needed
public set(val: any) {
if (this.id === "meguTV" || this.spec.getfn) {
if (this.id === "meguTV") {
return;
}
if (val !== this.spec.default || this.read()) {
Expand Down Expand Up @@ -169,10 +166,7 @@ export function initOptions() {
}

// Conditionally load and execute optional modules
for (let opt of [
"userBG", "nowPlaying", "bgVideo", "mascot", "customCSSToggle",
"meguTV",
]) {
for (let opt of ["userBG", "bgVideo", "mascot", "customCSSToggle", "meguTV"]) {
if (options[opt]) {
models[opt].execute(true)
}
Expand Down
Loading

0 comments on commit 34e2cbe

Please sign in to comment.