Hatena Bookmark Users Filter

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

当前为 2020-02-04 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

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

(function(){
  const COUNTS = [1, 3, 10, 30, 100, 300, 1000];
  let current = location.href.includes('&users=') ? parseInt(location.href.match(/&users=([0-9]*)/)[1]) : 0;
  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');
    a.href = a.href.replace(/(&users)=1$/, '$1=' + c);
    a.textContent = c + ' users';
    countsUl.appendChild(li);
  });
})();