Skip to content

Instantly share code, notes, and snippets.

@mfd mfd/arr.js
Last active Aug 2, 2018

Embed
What would you like to do?
js snipp
elems = document.querySelectorAll('ul.projects-list span.project-name');
for (var i in elems) {
arr.push(elems[i].innerText)
}
// delete similar
var uniq = arr
.map((name) => {
return {count: 1, name: name}
})
.reduce((a, b) => {
a[b.name] = (a[b.name] || 0) + b.count
return a
}, {})
var sorted = Object.keys(uniq).sort((a, b) => uniq[a] < uniq[b])
console.log(sorted.sort().join('\n'));
//import $ from 'jquery';
var subElements=document.querySelectorAll('.js-nav-link');
subElements.forEach(function(el) {
el.addEventListener('click', function(event) {
event.currentTarget.closest('.js-mob-nav').classList.toggle('is-visible');
$('.js-mob-menu-trigger').toggleClass('is-clicked');
});
});
$('.js-mob-menu-trigger').click(function() {
$(this).toggleClass('is-clicked');
$('.js-mob-nav').toggleClass('is-visible');
});
$('.nav').on('click','a', function(event) {
//отменяем стандартную обработку нажатия по ссылке
event.preventDefault();
//забираем идентификатор бока с атрибута href
var id = $(this).attr('href'),
//узнаем высоту от начала страницы до блока на который ссылается якорь
top = $(id).offset().top;
//анимируем переход на расстояние - top за 1500 мс
$('body,html').animate({scrollTop: top}, 1500);
});
var buttons = document.querySelectorAll('button');
for (var i=0; i<buttons.length; ++i) {
buttons[i].addEventListener('click', clickFunc);
}
function clickFunc() {
alert(this.id);
}
var change = document.getElementById('size');
var color = document.getElementById('color');
var changeVal = document.getElementById('size-value');
var count = document.getElementById('count');
var autoselect = document.getElementsByClassName('autoselect');
var icons = document.getElementsByClassName('icon');
//https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach
Array.prototype.forEach.call(autoselect, function(el) {
el.onclick = function() {
this.focus();
this.select();
};
});
change.oninput = function() {
var val = this.value;
changeVal.value = val;
Array.prototype.forEach.call(icons, function(el) {
el.style.fontSize = val + 'px';
});
}
color.onchange = function() {
var val = this.value;
Array.prototype.forEach.call(icons, function(el) {
el.style.fill = val;
});
}
count.innerHTML = icons.length
arr = []
elems = json.response.feedMessageResponse.messages.message
for(var i in elems) {
var time = new Date(elems[i].unixTime * 1000);
var rr = `${elems[i].messengerName}, ${time}, ${elems[i].latitude}, ${elems[i].longitude}`;
arr.push(rr);
}
console.log(arr.join('\n'));
// https://annual.awwwards.com/static/data.json
json.categories[0].nominees.filter(function(item) {
console.log(item.title+' // '+item.url)
})
arr = [];
elems = document.querySelectorAll('ul.projects-list .project-name');
for (var i = 0; i < elems.length; i++) {
//arr+=elems[i].textContent
arr.push(elems[i].textContent.replace(/\n/g, ''))
}
console.table(arr)
arr = [];
elems = document.querySelectorAll('ul.projects-list span.project-name');
for (var i in elems) {
arr.push(elems[i].innerText)
}
console.log(arr.join('\n'))
[...document.querySelectorAll('.more__toggle_show')].forEach($el=>$el.click())
sidebarScroll: function(sidebar) {
sidebar = sidebar || this.sidebar;
if (sidebar.length > 0) {
sidebar.find('.js-content').perfectScrollbar();
}
}
// https://www.youtube.com/watch?v=y4gZMJKAeWs&index=6&list=PLu8EoSxDXHP6CGK4YVJhL_VWetA865GOH&t=11s
// https://github.com/wesbos/JavaScript30/blob/master/06%20-%20Type%20Ahead/index-FINISHED.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.