StartPage.com - Number Results

Number search results on StartPage.com and other Ixquick sites - StartingPage.com and Ixquick.com

目前為 2019-08-21 提交的版本,檢視 最新版本

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

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 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 and other Ixquick sites - StartingPage.com and Ixquick.com
// @match          https://*.startpage.com/*/search*
// @author         r-a-y
// @version        1.1.4
// @license        GPL v3
// ==/UserScript==

var results = document.querySelectorAll( 'li.search-item' ), hasPagination = true, pageNumber,
    pagination, multiple, next, resultsNumber;

if ( results.length ) {
  hasPagination = false;
}

// Sometimes Startpage uses pagination.
if ( hasPagination ) {
  results = document.querySelectorAll( '.w-gl__result-title h3' );
  pageNumber = document.querySelector('.pagination .num--active').textContent;
console.log(results);
// If no pagination, calculate page number from prev/next links.
} else {
  pagination = document.querySelectorAll('.pagination__link');
  multiple = pagination[1].value;
  next = pagination[1].value;

  // We're on the last page.
  if ( multiple === '-1' ) {
    multiple = pagination[0].value;
  }

  // Get number of results.
  if ( multiple % 20 === 0 ) {
    resultsNumber = 20;
  } else {
    resultsNumber = 10;
  }

  // Calculate the current page number.
  if ( next === '-1' ) {
    pageNumber = multiple / resultsNumber + 1;
  } else {
    pageNumber = next / resultsNumber - 1;
  } 
}

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

  if ( hasPagination ) {
   newContent = document.createTextNode( ( ( pageNumber - 1 ) * len + i + 1 ) + ". ");
  } else {
   newContent = document.createTextNode( ( pageNumber * resultsNumber + i + 1 ) + ". "); 
  }
  newSpan.appendChild( newContent );

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