Created
July 16, 2023 04:07
-
-
Save q00u/260c1100999b596adb43c63fe1bd1864 to your computer and use it in GitHub Desktop.
This file contains 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 Baka New Manga Counter | |
// @namespace https://gist.github.com/q00u | |
// @version 0.2 | |
// @description Appends a count of manga with new chapters to "Welcome to Your Reading List" | |
// @author Phoenix G | |
// @match https://www.mangaupdates.com/mylist.html* | |
// @match http*://www.mangaupdates.com/mylist.html* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=mangaupdates.com | |
// @grant GM_addStyle | |
// @run-at document-end | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// Your code here... | |
// Functions | |
const getID = (element) => { | |
const h = element.firstChild.href; | |
return h.substring(h.indexOf('=') + 1, h.indexOf('&')); // Just the comic ID | |
} | |
// Load old unreads (if any) | |
const key = 'oldnews'; | |
const oldNewsRaw = localStorage[key]; | |
const oldNews = oldNewsRaw ? JSON.parse(oldNewsRaw) : []; | |
//console.log('oldNews', oldNews); | |
// Look through the page for unread indicators | |
const main = document.getElementById('main_content'); | |
const news = main.getElementsByClassName('newlist'); | |
const newArray = Array.from(news).map(x => { | |
return getID(x); | |
}).filter(x => x!==undefined); | |
// Compare new unreads vs old unreads | |
const newNews = newArray.filter(x => !oldNews.includes(x)); | |
//console.log('newNews', newNews); | |
// Go through page again, and star new unreads | |
Array.from(news).forEach(e => { | |
//console.log(e); | |
const id = getID(e); | |
//console.log(id); | |
// Did we already know about this one? | |
if (id && !oldNews.includes(id)) { | |
console.log('New!', id); | |
const star = document.createElement('div'); | |
star.classList.add('star'); | |
e.appendChild(star); | |
} | |
}); | |
// ★ | |
// Make new element to display the counts (total unread, new unread) | |
const count = document.createElement('span'); | |
count.classList = 'newlist'; | |
count.innerText = ` (unread: ${newArray.length}, new: ${newNews.length})`; | |
main.children[0].children[0].children[0].appendChild(count); | |
if (newNews.length > 0) { | |
const teststar = document.createElement('div'); | |
teststar.classList.add('star'); | |
main.children[0].children[0].children[0].appendChild(teststar); | |
} | |
// Spinning star styles | |
GM_addStyle( | |
`@keyframes rotate { | |
0% { transform: rotate(0deg); } | |
100% { transform: rotate(360deg); } | |
} | |
.star { | |
animation: 2.5s rotate infinite; | |
animation-timing-function: linear; | |
background-color: black; | |
clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); | |
display: inline-block; | |
height: 15px; | |
width: 15px; | |
background-color: yellow; | |
}` | |
); | |
//console.log('newArray', newArray); | |
// Update list of unread comics | |
localStorage[key]=JSON.stringify(newArray); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment