Skip to content

Instantly share code, notes, and snippets.

@DragorWW
Last active April 18, 2016 14:56
Show Gist options
  • Select an option

  • Save DragorWW/a338040fac03b1cb4984bda7e50e031e to your computer and use it in GitHub Desktop.

Select an option

Save DragorWW/a338040fac03b1cb4984bda7e50e031e to your computer and use it in GitHub Desktop.
vegetarianFilter - вегетарианский фильтр для меню на сайтах доставки
/**
* Фильтрация карточек суши на предмет не вегетарианской ингредиентов.
* Фильтр скрывает все itemSelector где есть стоп слова.
*
* @param {string} itemSelector селектор карточек.
* @param {string} paramSelector селектор описания внутри карточки.
*
* @return void
*/
function vegetarianFilter(itemSelector, paramSelector) {
var stopList = [
'кожа',
'лосос',
'краб',
'лава',
'мясо',
'икра',
'филе',
'креветк',
'рыбы',
'рыба',
'курица',
'угорь',
];
var itemList = document.querySelectorAll(itemSelector);
[].forEach.call(itemList, function (el) {
var text = el.querySelector(paramSelector).innerText.toLowerCase();
var isVeget = true;
stopList.forEach(function(test) {
if (!isVeget) return false;
if (text.search(test) >= 0) {
console.log('[vegetaFilter]', el, test, text);
isVeget = false;
}
});
if (!isVeget) el.style.display = 'none';
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment