Skip to content

Instantly share code, notes, and snippets.

@Getaji
Last active October 29, 2019 15:16
Show Gist options
  • Select an option

  • Save Getaji/b871e421c7fde20ea415884ec343e6f4 to your computer and use it in GitHub Desktop.

Select an option

Save Getaji/b871e421c7fde20ea415884ec343e6f4 to your computer and use it in GitHub Desktop.
HOME'Sの物件一覧を築年数でフィルタするスクリプト。最大築年数をプロンプトで入力。キャンセルか無効な値で解除。
(function() {
const jqMansions = $('.rMansion');
const maxAge = Number.parseInt(prompt('最大築年数', '38'));
if (Number.isNaN(maxAge)) {
if (confirm('フィルタを解除しますか?')) {
jqMansions.each(function() { this.style.display = 'block'; });
}
return;
}
jqMansions.each(function() {
const elAgeAndFloor = this.querySelector('.bukkenSpec tr:nth-child(3) td');
if (!elAgeAndFloor) return;
const mAge = elAgeAndFloor.innerText.match(/(\d+)年/);
const age = mAge ? Number.parseInt(mAge[1]) : -1;
if (age > maxAge) {
this.style.display = 'none';
}
})
})()
// minified
(function(){const jqMansions=$('.rMansion');const maxAge=Number.parseInt(prompt('最大築年数','38'));if(Number.isNaN(maxAge)){if(confirm('フィルタを解除しますか?')){jqMansions.each(function(){this.style.display='block'})}
return}
$('.rMansion').each(function(){const elAgeAndFloor=this.querySelector('.bukkenSpec tr:nth-child(3) td');if(!elAgeAndFloor)return;const mAge=elAgeAndFloor.innerText.match(/(\d+)年/);const age=mAge?Number.parseInt(mAge[1]):-1;if(age>maxAge){this.style.display='none'}})})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment