Return Pagination to Google

Makes Google searches break down into separate pages, rather than displaying as one continuous page. (Quick & Dirty)

目前為 2023-06-10 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Return Pagination to Google
// @description Makes Google searches break down into separate pages, rather than displaying as one continuous page. (Quick & Dirty)
// @namespace   Violentmonkey Scripts
// @match       https://www.google.com/search
// @grant       none
// @version     1.1
// @author      Jupiter Liar
// @license     Attribution CC BY
// @description 6/10/2023, 6:48 AM
// ==/UserScript==



// Check if the page has the required conditions
if (document.getElementById('botstuff') && !document.querySelector('table.AaVjTc')) {
  // Create the table element
  var table = document.createElement('table');
  table.className = 'AaVjTc';
  table.style.margin = 'auto';
  table.style.marginBottom = '32px';
  table.style.scale = '80%';

  // Create a variable to store the page number
  var pageNumber;

  // Extract the page number from the URL
  var startParam = "&start=";
  var startIndex = window.location.href.indexOf(startParam);

  if (startIndex === -1) {
    pageNumber = 1;
  } else {
    var startValue = parseInt(window.location.href.substring(startIndex + startParam.length));
    pageNumber = Math.floor(startValue / 10) + 1;
  }

  // Create the table columns
  for (var i = 0; i < 11; i++) {
    var column = document.createElement('td');
    column.style.textAlign = 'center';
    column.style.verticalAlign = 'middle'; // Changed from 'baseline' to 'middle'
    column.style.minWidth = '20px';
    column.style.fontSize = '20pt';

    // Add padding to middle columns
    if (i > 0 && i < 10) {
      column.style.padding = '0 8pt'; // Changed from '0 8px' to '0 8pt'
    }

    // Add padding to previous and next columns
    if (i === 0 || i === 10) {
      column.style.padding = '0 16pt'; // Changed from '0 16px' to '0 16pt'
    }

    // Add content to the columns
    if (i === 0) {
      if (pageNumber !== 1) {
        var previousLink = document.createElement('a');
        previousLink.href = window.location.href.replace(startParam + startValue, startParam + (startValue - 10));
        var previousSpan = document.createElement('span');
        previousSpan.style.padding = '0 16pt'; // Changed from '0 8pt' to '0 16pt'
        previousSpan.style.fontSize = '28pt';
        previousSpan.style.verticalAlign = 'middle'; // Added vertical-align style
        previousSpan.innerText = '<';
        previousLink.appendChild(previousSpan);
        var previousTextSpan = document.createElement('span');
        previousTextSpan.style.verticalAlign = 'middle'; // Added vertical-align style
        previousTextSpan.innerText = 'Previous';
        previousLink.appendChild(previousTextSpan);
        column.appendChild(previousLink);
      }
    } else if (i === 10) {
      var nextLink = document.createElement('a');
      nextLink.href = window.location.href.replace(startParam + startValue, startParam + (startValue + 10));
      var nextTextSpan = document.createElement('span');
      nextTextSpan.style.verticalAlign = 'middle'; // Added vertical-align style
      nextTextSpan.innerText = 'Next';
      nextLink.appendChild(nextTextSpan);
      var nextSpan = document.createElement('span');
      nextSpan.style.padding = '0 16pt'; // Changed from '0 8pt' to '0 16pt'
      nextSpan.style.fontSize = '28pt';
      nextSpan.style.verticalAlign = 'middle'; // Added vertical-align style
      nextSpan.innerText = '>';
      nextLink.appendChild(nextSpan);
      column.appendChild(nextLink);
    } else {
      // Calculate the page number for the column
      var columnNumber;
      if (pageNumber < 5) {
        columnNumber = i;
      } else if (pageNumber >= 5) {
        columnNumber = pageNumber - 5 + i;
      }

      if (columnNumber === pageNumber) {
        // Add page number without link
        column.innerText = columnNumber;
      } else {
        // Add page number with link
        var newStartValue = (columnNumber - 1) * 10;
        if (newStartValue === 0) {
          newStartValue = "0";
        }
        if (startIndex === -1) {
          column.innerHTML = `<a href="${window.location.href + startParam + newStartValue}">${columnNumber}</a>`;
        } else {
          column.innerHTML = `<a href="${window.location.href.replace(startParam + startValue, startParam + newStartValue)}">${columnNumber}</a>`;
        }
      }
    }

    // Append the column to the table
    table.appendChild(column);
  }

  // Check if the first column is empty and delete it
  var firstColumn = table.querySelector('td:first-child');
  if (firstColumn.innerText === '') {
    table.removeChild(firstColumn);
  }

  // Append the table to the 'botstuff' div
  var botstuffDiv = document.getElementById('botstuff');
  botstuffDiv.appendChild(table);
}


// Check if the page has the required conditions
if (document.getElementById('botstuff')) {
  var botstuffDiv = document.getElementById('botstuff');
  var divsToHide = botstuffDiv.querySelectorAll('div[jscontroller="ogmBcd"]');
  for (var i = 0; i < divsToHide.length; i++) {
    divsToHide[i].style.display = "none";
  }
}