StartPage.com - Number Results

Number search results on StartPage.com

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 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 );
}