AO3 Bookmark Maker (Adds title, author, workID, summary to bookmark notes automatically)

Automatically adds the fic info (title, author, series/workID, and summary) to the bookmark notes while preserving any existing notes. It also adds word count tags or a "WIP" tag. Automatically sets all new bookmarks to default to being private as well. Great for tracking bookmarks. Helpful for re-readers! Or to figure out what that deleted fic used to be! (Note this is included in my AO3 Re-read Savior script)

< AO3 Bookmark Maker (Adds title, author, workID, summary to bookmark notes automatically)についてのフィードバック

レート:良 – スクリプトは良好に動作する

§
投稿日: 2023/05/23

Hi there, really like the userscript but I just wanna add a few things. You've mentioned in the user-config area of the script that Anonymous accounts break the author variable. While I haven't extensively tested what I'm about to comment, I've found that for normal works you can use

document.querySelector(`#workskin > .preface .byline`).textContent.trim();

to retrieve the author name regardless of whether it's a normal user, Anonymous, or orphan_account.

When it comes to series with Anonymous authors, I've found that

document.evaluate(`.//*[@id="main"]//dl[contains(concat(" ",normalize-space(@class)," ")," series ")][contains(concat(" ",normalize-space(@class)," ")," meta ")][contains(concat(" ",normalize-space(@class)," ")," group ")]//dt[text()[contains(.,'Creator')]]/following-sibling::*[1]/self::dd`, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.textContent

works well to retrieve the author name. I understand that it looks a lot messier than using CSS selectors but XPath it a lot more flexible in what it can do, especially since it can ensure that a sibling contains a specific text. The simple explanation is that the above document.evaluate() is doing the same thing as document.querySelector('#main dl.series.meta.group dt+dd').textContent but with the additional step of making sure that the dt element contains Creator as it's text content.

I initially found out about using XPath like this on StackExchange, and if you'd like to read more it's well documented on MDN. Hope this helped.

§
投稿日: 2023/05/23

P.S. I've used backticks to form strings in my code (they're called template literals/template strings (SE | MDN) and they're really neat) but they're not compatible with Internet Explorer, so if you plan to implement any of my code suggestions and you want to keep compatibilty with IE you'll want to replace those with single or double quotes.

§
投稿日: 2023/07/09

Thank you so much for your help fixing the issue with Anonymous authors! I've incorporated the code into the update :)

返信を投稿

返信を投稿するにはログインしてください。