Hatena Bookmark Users Filter

はてなブックマークの検索結果ページで、ブックマーク数によるフィルタリング選択肢を改変します。

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        Hatena Bookmark Users Filter
// @description はてなブックマークの検索結果ページで、ブックマーク数によるフィルタリング選択肢を改変します。
// @namespace   knoa.jp
// @include     https://b.hatena.ne.jp/search/*
// @version     1.0.2
// @grant       none
// ==/UserScript==

/*
正常動作を確認しました。
*/
(function(){
  const COUNTS = [1, 3, 10, 30, 100, 300, 1000];
  const DEFAULT = 3;
  let current = location.href.includes('&users=') ? parseInt(location.href.match(/&users=([0-9]*)/)[1]) : DEFAULT;
  let filterH3s = document.querySelectorAll('.left-container h3');
  let countsH3 = Array.from(filterH3s).find(h3 => h3.textContent === 'ブックマーク数');
  if(countsH3 === undefined) return console.log('Not found H3.');
  let countsUl = countsH3.parentNode.querySelector('ul');
  let countsLis = countsUl.querySelectorAll('ul > li');
  while(countsUl.children.length > 1) countsUl.removeChild(countsUl.lastElementChild);
  COUNTS.forEach(c => {
    if(c === 1) return;
    let li = countsLis[0].cloneNode(true);
    let a = li.querySelector('a');
    if(a === null) return console.log('Not found a.');
    if(c === current) a.classList.add('is-current');
    else a.classList.remove('is-current');
    a.href = a.href.replace(/(&users)=1\b/, '$1=' + c);
    a.textContent = c + ' users';
    countsUl.appendChild(li);
  });
})();