-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
2 changed files
with
39 additions
and
14 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
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 |
---|---|---|
@@ -1,20 +1,42 @@ | ||
import { Plugin } from "siyuan"; | ||
import { sql } from "./api"; | ||
import { hash_time33 } from "@llej/js_util/src/hash"; | ||
|
||
export default class OceanPress extends Plugin { | ||
private btn_selector = "oceanpress_widget_button"; | ||
private timeID: ReturnType<typeof setInterval> | null = null; | ||
type attribute = { | ||
block_id: "id"; | ||
box: "id"; | ||
id: "id"; | ||
name: "bookmark"; | ||
path: "/id/id.sy"; | ||
root_id: "id"; | ||
type: "b"; | ||
value: "expr"; | ||
}; | ||
|
||
async onLayoutReady() { | ||
console.log("启动"); | ||
|
||
} | ||
async onunload() { | ||
} | ||
|
||
async addButton() { | ||
export default class expr extends Plugin { | ||
async onload() { | ||
/** 查询所有 bookmark = 'expr' or name = "custom-expr" 的属性 */ | ||
const attr: attribute[] = await sql(` | ||
SELECT * FROM attributes | ||
WHERE | ||
name = "custom-expr" | ||
OR | ||
(name = "bookmark" AND VALUE ="expr")`); | ||
console.log("启动", hash_time33("dfadfa"), attr, filterNotInitBlock(attr)); | ||
} | ||
previewCurrentPage() {} | ||
async onunload() {} | ||
} | ||
function sleep(time: number) { | ||
return new Promise((s) => setTimeout(s, time)); | ||
function filterNotInitBlock(attrs: attribute[]) { | ||
const idCount: { [block_id: string]: { count: number; attrs: attribute[] } } = {}; | ||
attrs.forEach(async (attr: attribute) => { | ||
if (idCount[attr.block_id] === undefined) { | ||
idCount[attr.block_id] = { count: 0, attrs: [] }; | ||
} | ||
idCount[attr.block_id].count += 1; | ||
idCount[attr.block_id].attrs.push(attr); | ||
}); | ||
return Object.keys(idCount) | ||
.filter((block_id: string) => idCount[block_id].count === 1) | ||
.map((block_id: string) => idCount[block_id].attrs[0]); | ||
} | ||
async function exprBlockInit(block: any) {} |