Skip to content

Instantly share code, notes, and snippets.

@zakuroishikuro
Last active October 18, 2023 17:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zakuroishikuro/635baa26ac0cb5726c0cfaf1acf5b57a to your computer and use it in GitHub Desktop.
Save zakuroishikuro/635baa26ac0cb5726c0cfaf1acf5b57a to your computer and use it in GitHub Desktop.
logseq bookmarklet
javascript: (()=>{
const {hostname, pathname} = location;
let page = hostname + pathname;
let content = "";
const now = new Date();
const date = now.toLocaleDateString().replace(/\//g, "-");
const time = now.toLocaleTimeString();
content = `source:: [${document.title}](${location.href})\ncreated:: [[${date}]] ${time}`;
if (hostname == "www.youtube.com" && pathname == "/watch") {
const title = document.querySelector("#title.ytd-watch-metadata").textContent.trim();
const id = location.search.slice(3);
const channel = document.querySelector("#upload-info a").textContent.trim();
page = `${channel}/${title}`;
content = `type:: youtube\n ${content}\n{{youtube ${location.href}}}`;
}
;if (hostname == "www.uta-net.com" && pathname.match(/song/)) {
const title = document.querySelector("h2").textContent.trim();
const propElements = [...document.querySelectorAll("[itemprop]")];
const propList = propElements.map(prop=>{
return [prop.attributes.itemprop.value, prop.textContent.trim()];
}
);
const dict = Object.fromEntries(propList);
page = `${title}`;
const props = [
`type:: song`,
`artist:: ${dict.byArtist}`,
`作詞:: ${dict.lyricist}`,
`作曲:: ${dict.composer}`,
`編曲:: ${dict.arranger}`,
content,
];
content = props.join("\n");
};
content = encodeURIComponent(content);
page = encodeURIComponent(page);
const url = `logseq://x-callback-url/quickCapture?page=${page}&content=${content}`;
/*const url = `logseq://graph/JungleGraph?page=${page}`;*/
location.href = url;
}
)();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment