Created
July 10, 2023 17:04
-
-
Save daranable/d3333661b8e98ee7a69c00121e4729ca to your computer and use it in GitHub Desktop.
Neopets Neoboards - Viewed Topics
This file contains hidden or 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
// ==UserScript== | |
// @name Neoboards Enhancement - Viewed threads | |
// @namespace https://gist.github.com | |
// @version 0.1 | |
// @description Automatically marks thread as viewed when you view them, and allows following threads. | |
// @author Daranable | |
// @match https://www.neopets.com/neoboards/boardlist.phtml* | |
// @match https://www.neopets.com/neoboards/topic.phtml?topic=* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=neopets.com | |
// @grant GM_setValue | |
// @grant GM_getValue | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// Check the page we're on. | |
const url = window.location.href; | |
const isBoardList = url.includes('boardlist.phtml'); | |
const isTopic = url.includes('topic.phtml'); | |
// If we're on a topic page, mark it as viewed. | |
if (isTopic) { | |
const topicId = url.match(/topic=(\d+)/)[1]; | |
const viewedTopics = JSON.parse(GM_getValue('viewedTopics', "[]")); | |
// Add the topic to the viewed topics list. | |
// Format: [{topicId: 1234, date: 1234567890}, ...] | |
if (!viewedTopics.find((topic) => topic.topicId === topicId)) { | |
viewedTopics.push({topicId, date: Date.now()}); | |
GM_setValue('viewedTopics', JSON.stringify(viewedTopics)); | |
console.log('Marked topic as viewed: ', topicId); | |
} | |
} else if (isBoardList) { | |
// If we're on the board list, color viewed topics grey. | |
const viewedTopics = JSON.parse(GM_getValue('viewedTopics', "[]")); | |
const topicLinks = document.querySelectorAll('a[href*="topic="]'); | |
console.log('viewedTopics: ', viewedTopics); | |
topicLinks.forEach((link) => { | |
const topicId = link.href.match(/topic=(\d+)/)[1]; | |
if (viewedTopics.find((topic) => topic.topicId === topicId)) { | |
link.style.color = 'grey'; | |
} | |
}); | |
// Remove any topics that are older than a day. | |
const newViewedTopics = viewedTopics.filter((topic) => { | |
const oneDayAgo = Date.now() - 86400000; | |
return topic.date > oneDayAgo; | |
}); | |
GM_setValue('viewedTopics', JSON.stringify(newViewedTopics)); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment