Skip to content

Instantly share code, notes, and snippets.

@shotasenga
Created September 27, 2025 22:03
Show Gist options
  • Save shotasenga/3d9ee35999faea468ce6a33a7e27030d to your computer and use it in GitHub Desktop.
Save shotasenga/3d9ee35999faea468ce6a33a7e27030d to your computer and use it in GitHub Desktop.
Manga Plus Auto Sort
// ==UserScript==
// @name Manga Plus Auto Sort
// @namespace https://shotasenga.com/
// @version 1.0.1
// @description Automatically sorts chapter list in descending order on Manga Plus
// @author shotasenga
// @match https://mangaplus.shueisha.co.jp/titles/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
let lastUrl = location.href;
function sortChapters() {
const sortIcon = document.querySelector('.ChapterList-module_sortIcon_1dGE4');
if (sortIcon && sortIcon.tagName === 'IMG') {
// Check if it's in ascending order by checking the src attribute
if (sortIcon.src && sortIcon.src.startsWith('data:image/png;base64,iVBOR')) {
sortIcon.click();
}
}
}
// Initial sort on page load
function initialize() {
setTimeout(sortChapters, 100);
}
// Watch for URL changes (SPA navigation)
function checkForUrlChange() {
if (location.href !== lastUrl) {
lastUrl = location.href;
// URL changed, wait for new content to load then sort
setTimeout(sortChapters, 500);
}
}
// Watch for DOM changes
const observer = new MutationObserver(function(mutations) {
let shouldCheck = false;
mutations.forEach(function(mutation) {
// Check if chapter list or sort icon was added/modified
if (mutation.type === 'childList') {
mutation.addedNodes.forEach(function(node) {
if (node.nodeType === 1) { // Element node
if (node.classList && node.classList.contains('ChapterList-module_sortIcon_1dGE4') ||
node.querySelector && node.querySelector('.ChapterList-module_sortIcon_1dGE4')) {
shouldCheck = true;
}
}
});
}
});
if (shouldCheck) {
setTimeout(sortChapters, 100);
}
});
// Start observing
observer.observe(document.body, {
childList: true,
subtree: true
});
// Check for URL changes periodically
setInterval(checkForUrlChange, 1000);
// Initial load
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initialize);
} else {
initialize();
}
})();
@shotasenga
Copy link
Author

Click this link to install the script. (Tampermonkey or similar is required)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment