// ==UserScript== // @name AO3: tag hider // @namespace https://greasyfork.org/en/users/163551-vannius // @version 1.0 // @description Hide tags if there are too many tags on browsing page and hide work data on viewing page. // @author Vannius // @match http*://archiveofourown.org/* // @grant none // @downloadURL none // ==/UserScript== (function($) { // Config const MAX_TAGS_ON_BROWSING_PAGE = 15; const HIDE_WORK_DATA_AUTOMATICALLY_ON_VIEW_PAGE = true; if (/archiveofourown\.org\/works\/[0-9]+/.test(window.location.href)) { //viewing page const dataTag = document.getElementsByClassName('work meta group')[0]; // Make Show Data/Hide Data button const btn = document.createElement('BUTTON'); btn.type = 'button'; btn.appendChild(document.createTextNode('')); // Hide or Show data if (HIDE_WORK_DATA_AUTOMATICALLY_ON_VIEW_PAGE) { dataTag.style.display = 'none'; btn.textContent = 'Show Tags' }else{ dataTag.style.display = 'block'; btn.textContent = 'Hide Tags' } // Add click event btn.addEventListener('click', function() { if (dataTag.style.display == 'none') { dataTag.style.display = 'block'; btn.textContent = 'Hide Data' }else{ dataTag.style.display = 'none'; btn.textContent = 'Show Data' } }); // Add Show Data/Hide Data button to menu const liTag = document.createElement('li'); liTag.style.display = "inline-block"; liTag.appendChild(btn); const fragment = document.createDocumentFragment(); fragment.appendChild(document.createTextNode(' ')); fragment.appendChild(liTag); fragment.appendChild(document.createTextNode('\n\n')); const menu = document.getElementsByClassName('work navigation actions')[0]; menu.appendChild(fragment); } else { // browsing page const articles = document.getElementById('main').getElementsByClassName('blurb'); // Add Show Tags/Hide Tags button to each article. for (let article of articles) { const ao3tag = article.getElementsByClassName('tags commas')[0]; // Make Show Data/Hide Data button const btn = document.createElement('BUTTON'); btn.type = 'button'; btn.style.padding = '0%'; btn.appendChild(document.createTextNode('')); // Hide or Show tags console.log(article); console.log(ao3tag.children.length ); console.log(ao3tag.children.length > MAX_TAGS_ON_BROWSING_PAGE); if (ao3tag.children.length > MAX_TAGS_ON_BROWSING_PAGE) { ao3tag.style.display = 'none'; btn.textContent = 'Show Tags' }else{ ao3tag.style.display = 'block'; btn.textContent = 'Hide Tags' } // Add click event btn.addEventListener('click', function() { if (ao3tag.style.display == 'none') { ao3tag.style.display = 'block'; btn.textContent = 'Hide Tags' }else{ ao3tag.style.display = 'none'; btn.textContent = 'Show Tags' } }); // Add Show Data/Hide Data button to right after fandoms. const fandomTag = article.getElementsByClassName('header module')[0].children[1]; const fragment = document.createDocumentFragment(); fragment.appendChild(document.createTextNode(' ')); fragment.appendChild(btn); fandomTag.insertBefore(fragment, fandomTag.lastChild); } } })();