Skip to content

Commit

Permalink
fix: setTimeout for page load
Browse files Browse the repository at this point in the history
  • Loading branch information
usoonees committed Nov 1, 2022
1 parent f7067f5 commit 45dbdb4
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
A plugin for logseq to highlight the keyword in unlinked reference, and provide a button to automatically link them.

#### Screenshot
![](image/20221101194714.png)
![](image/screenshot.png)

#### Demo
![Demo](image/demo.gif)

#### Marketplace
<img src="image/20221101130630.png" alt="drawing" width="400"/>
<img src="image/marketplace.png" alt="drawing" width="400"/>
Binary file removed image/20221101130528.png
Binary file not shown.
File renamed without changes
File renamed without changes
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "logseq-plugin-link-unlinked",
"version": "1.1.0",
"version": "1.1.1",
"main": "dist/index.html",
"logseq": {
"title": "Link Unlinked References",
Expand Down
14 changes: 8 additions & 6 deletions public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,18 @@ async function main() {
function addObserverIfDesiredNodeAvailable() {
unlinkedRefsContainer = doc.querySelector(".page>div:nth-last-child(1) .references");
if(!unlinkedRefsContainer) {
setTimeout(addObserverIfDesiredNodeAvailable, 2000);
setTimeout(addObserverIfDesiredNodeAvailable, 1000);
return;
}
unlinkObserver.observe(unlinkedRefsContainer, obConfig);
}
addObserverIfDesiredNodeAvailable();

logseq.App.onRouteChanged(() => {
addObserverIfDesiredNodeAvailable();
});
setTimeout(() => {
addObserverIfDesiredNodeAvailable();
}, 1000) // wait for page load, otherwise would observer the previous page
});

logseq.beforeunload(async () => {
unlinkObserver.disconnect()
Expand Down Expand Up @@ -109,7 +111,6 @@ function addButton(blockEl, pageNames, isPureText) {
'[[cu]] #focus #f/ocus #cu [[cu]]s fo[[cu]]s [[cu]] [[focus]]'
*/
const newContent = content.replace(re, (match, _, i) => {
// console.log(match, token, i)
while(i>=0) {
if(/\s/.test(content[i])) {
break
Expand All @@ -121,8 +122,9 @@ function addButton(blockEl, pageNames, isPureText) {

return `[[${match}]]`
})
console.log("oldContent", content, pageNames)
console.log("newContent", newContent)
console.log("unlinked content: ", content, pageNames)
console.log("linked content: ", newContent)

await logseq.Editor.updateBlock(blockID, newContent)

if(!isPureText) { // sometimes header and paragraph would cause block render error
Expand Down

0 comments on commit 45dbdb4

Please sign in to comment.