From 218c6adfa025b2b3f328c759872d1d1de4ee24bc Mon Sep 17 00:00:00 2001 From: tophf Date: Sun, 11 Jun 2017 15:01:48 +0300 Subject: [PATCH] patch buggy USO site pagination links in category mode --- install.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/install.js b/install.js index 12a433c1..faba121c 100644 --- a/install.js +++ b/install.js @@ -91,9 +91,29 @@ document.documentElement.appendChild(document.createElement('script')).text = '( }; } + ')()'; +// TODO: remove the following statement when USO pagination is fixed +if (location.search.includes('category=')) { + document.addEventListener('DOMContentLoaded', function _() { + document.removeEventListener('DOMContentLoaded', _); + new MutationObserver((_, observer) => { + if (!document.getElementById('pagination')) { + return; + } + observer.disconnect(); + const category = '&' + location.search.match(/category=[^&]+/)[0]; + const links = document.querySelectorAll('#pagination a[href*="page="]:not([href*="category="])'); + for (let i = 0; i < links.length; i++) { + links[i].href += category; + } + }).observe(document, {childList: true, subtree: true}); + }); +} + new MutationObserver((mutations, observer) => { if (document.body) { observer.disconnect(); + // TODO: remove the following statement when USO pagination title is fixed + document.title = document.title.replace(/^\d+&category=/, ''); chrome.runtime.sendMessage({ method: 'getStyles', url: getMeta('stylish-id-url') || location.href