added a unique class to each custom frame

Closes #53
This commit is contained in:
Ell 2022-08-21 17:59:12 +02:00
parent b425e9671f
commit a91735dc44
5 changed files with 215 additions and 168 deletions

173
main.js

File diff suppressed because one or more lines are too long

View file

@ -1,5 +1,5 @@
import { Platform } from "obsidian"; import { Platform } from "obsidian";
import { CustomFrameSettings, CustomFramesSettings } from "./settings"; import { CustomFrameSettings, CustomFramesSettings, getId } from "./settings";
export class CustomFrame { export class CustomFrame {
@ -30,6 +30,7 @@ export class CustomFrame {
style += `transform: scale(${this.data.zoomLevel}); transform-origin: 0 0;`; style += `transform: scale(${this.data.zoomLevel}); transform-origin: 0 0;`;
} }
this.frame.addClass("custom-frames-frame"); this.frame.addClass("custom-frames-frame");
this.frame.addClass(`custom-frames-${getId(this.data)}`);
this.frame.setAttribute("style", style); this.frame.setAttribute("style", style);
let src = this.data.url; let src = this.data.url;

View file

@ -1,6 +1,6 @@
import { Plugin, Platform } from "obsidian"; import { Plugin, Platform } from "obsidian";
import { CustomFrame } from "./frame"; import { CustomFrame } from "./frame";
import { CustomFramesSettings, defaultSettings, getIcon } from "./settings"; import { CustomFramesSettings, defaultSettings, getIcon, getId } from "./settings";
import { CustomFramesSettingTab } from "./settings-tab"; import { CustomFramesSettingTab } from "./settings-tab";
import { CustomFrameView } from "./view"; import { CustomFrameView } from "./view";
@ -14,7 +14,7 @@ export default class CustomFramesPlugin extends Plugin {
for (let frame of this.settings.frames) { for (let frame of this.settings.frames) {
if (!frame.url || !frame.displayName) if (!frame.url || !frame.displayName)
continue; continue;
let name = `custom-frames-${frame.displayName.toLowerCase().replace(/\s/g, "-")}`; let name = `custom-frames-${getId(frame)}`;
if (Platform.isMobileApp && frame.hideOnMobile) { if (Platform.isMobileApp && frame.hideOnMobile) {
console.log(`Skipping frame ${name} which is hidden on mobile`); console.log(`Skipping frame ${name} which is hidden on mobile`);
continue; continue;

View file

@ -14,21 +14,21 @@ export const presets: Record<string, CustomFrameSettings> = {
forceIframe: false, forceIframe: false,
customCss: "" customCss: ""
}, },
"detexify": { "detexify": {
url: "https://detexify.kirelabs.org/classify.html", url: "https://detexify.kirelabs.org/classify.html",
displayName: "Detexify", displayName: "Detexify",
icon: "type", icon: "type",
hideOnMobile: true, hideOnMobile: true,
addRibbonIcon: true, addRibbonIcon: true,
openInCenter: false, openInCenter: false,
zoomLevel: .95, zoomLevel: .95,
forceIframe: false, forceIframe: false,
customCss: `/* hide info clutter and ad banner */ customCss: `/* hide info clutter and ad banner */
#classify--info-area, #classify--info-area,
.adsbygoogle { .adsbygoogle {
display: none !important display: none !important
}` }`
}, },
"calendar": { "calendar": {
url: "https://calendar.google.com/calendar/u/0/r/day", url: "https://calendar.google.com/calendar/u/0/r/day",
displayName: "Google Calendar", displayName: "Google Calendar",
@ -135,3 +135,7 @@ export interface CustomFrameSettings {
export function getIcon(settings: CustomFrameSettings) { export function getIcon(settings: CustomFrameSettings) {
return settings.icon ? `lucide-${settings.icon}` : "documents"; return settings.icon ? `lucide-${settings.icon}` : "documents";
} }
export function getId(settings: CustomFrameSettings) {
return settings.displayName.toLowerCase().replace(/\s/g, "-");
}

File diff suppressed because one or more lines are too long