StartPage.com - Number Results

Number search results on StartPage.com

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name           StartPage.com - Number Results
// @namespace      tag:[email protected],2012:monkey
// @description    Number search results on StartPage.com
// @match          https://*.startpage.com/*/search*
// @author         r-a-y
// @version        1.2.1
// @license        GPL v3
// ==/UserScript==

let results = document.querySelectorAll( '.result' ), pageNumber, numItems;

if ( results.length ) {
  results = document.querySelectorAll( '.result h2' );
  pageNumber = document.querySelector( '.pagination form[aria-label^=current] button' );

  if ( pageNumber ) {
    pageNumber = pageNumber.textContent;
  } else {
    pageNumber = 1;
  }

  // Deal with custom results per page.
  if ( results.length % 20 === 0 ) {
    numItems = 20;
  } else {
    numItems = 10;
  }

  // On last page, default to 20.
  if ( ! document.querySelector( '.pagination form[aria-label^=current] + form' ) ) {
    numItems = 20;
  }
}

// DOM inject.
for ( let i = 0, len = results.length; i < len; ++i ) {
  let newContent;
  let newSpan = document.createElement( "span" );
  newSpan.setAttribute( "style", "float:left; font-weight:600; font-size:1em; display:inline-block; margin-right:5px;" );

  newContent = document.createTextNode( ( ( pageNumber - 1 ) * numItems + i + 1 ) + ". ");

  newSpan.appendChild( newContent );

  results[i].insertBefore( newSpan, results[i].firstChild );
}