[Userscript] Book Club Tracker

So I’ve discovered a weird issue. The Add button wasn’t showing up for me consistently here on the forums. For example, I went to the Takagi-san thread and it wasn’t there at first; I refreshed and then it was; I refreshed again and it disappeared again and then never came back no matter how many times I refreshed.

It turns out it wasn’t showing up because it thinks the nodeList for the badge-categories is empty. Why does it think this when inspecting shows that they have the right classes? Well apparently it’s because the document returned by the GET doesn’t have the updated class name; it still uses category-name. But it’s only like this while the document is in “interactive” readyState; if it reaches “completed” we’re all good.

So I put a little {sleep for 1s if readyState is interactive} line in checkPage and now the button seems to get added consistently.

Also! I got the date-rolling-over-into-the-next-year thing working. Using the thread creation date was indeed the key as suggested and very very helpfully the timestamp is included as a data- attribute on the span containing the date.

// under: let possibleTables = ...
let threadCreatedDate = new Date(parseInt(document.querySelector('#post_1 span[data-time]').getAttribute('data-time')));

// around let startDate = ... | changed getFullYear() to use threadCreateDate; added line to reassign date if months suddenly go backward
if(!startDateText.match(/\d{4}/)) startDateText += " " + threadCreatedDate.getFullYear();
let startDate = new Date(startDateText);
startDate = startDate.getMonth() < threadCreatedDate.getMonth() ?
    new Date(startDate.getFullYear() + 1, startDate.getMonth(), startDate.getDate()) : startDate;

You can check that it works using the Cells At Work thread.