Hitomi - Language & Tag Filtering

Filters search results by languages and tags

Verze ze dne 22. 10. 2018. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name      	    Hitomi - Language & Tag Filtering
// @namespace 		brazenvoid
// @version   		2.0
// @author          brazenvoid
// @description     Filters search results by languages and tags
// @include   		https://hitomi.la/*
// @run-at			document-idle
// ==/UserScript==

// Define languages to keep and tags to exclude here (search urls)

let allowedLanguages = [
  "japanese", 
  "english"
];
let excludedTags = [
  "anthology", 
  "female:loli", 
  "sample", 
  "male:yaoi"
];

// Formatting filters

let formatFilters = function (filters, prefix, suffix) {
  
  for (let index = 0; index < filters.length; index++) {
    
  	filters[index] = '[href="'+ prefix + encodeURIComponent(filters[index]) + suffix +'.html"]';
	}
	return filters.join(", ");
};

let languageFiltersSelector = formatFilters(allowedLanguages, "/index-", "-1");
let tagFiltersSelector = formatFilters(excludedTags, "/tag/", "-all-1");

console.log(languageFiltersSelector);
console.log(tagFiltersSelector);

// Filteration logic

let complianceCallback = function(target) {
  
  let elements = target.querySelectorAll('.manga, .dj, .acg');
  
  for (let element of elements) {

    if (element.querySelectorAll(languageFiltersSelector).length == 0 || 
        element.querySelectorAll(tagFiltersSelector).length > 0) {
      element.remove();
    }
  }
};

// Setting up configuration and galleries list node

let galleriesList = document.querySelector('.gallery-content');
let observerConfig = { 
  attributes: false, 
  childList: true, 
  subtree: false 
};

// Checking compliance in case of gallery page

complianceCallback(galleriesList);

// Adding observer to check compliance of galleries on search pages

let observer = new MutationObserver(function(mutations, observer) {
  for(let mutation of mutations) {
    complianceCallback(mutation.target);
  }
});
observer.observe(galleriesList, observerConfig);