Return Pagination to Google

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

当前为 2023-06-10 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Return Pagination to Google
  3. // @description Makes Google searches break down into separate pages, rather than displaying as one continuous page. (Quick & Dirty)
  4. // @namespace Violentmonkey Scripts
  5. // @match https://www.google.com/search
  6. // @grant none
  7. // @version 1.0
  8. // @author Jupiter Liar
  9. // @license Attribution CC BY
  10. // @description 6/10/2023, 6:48 AM
  11. // ==/UserScript==
  12.  
  13.  
  14. // Check if the page has the required conditions
  15. if (document.getElementById('botstuff') && !document.querySelector('table.AaVjTc')) {
  16. // Create the table element
  17. var table = document.createElement('table');
  18. table.className = 'AaVjTc';
  19. table.style.margin = 'auto';
  20. table.style.marginBottom = '32px';
  21.  
  22. // Create a variable to store the page number
  23. var pageNumber;
  24.  
  25. // Extract the page number from the URL
  26. var startParam = "&start=";
  27. var startIndex = window.location.href.indexOf(startParam);
  28.  
  29. if (startIndex === -1) {
  30. pageNumber = 1;
  31. } else {
  32. var startValue = parseInt(window.location.href.substring(startIndex + startParam.length));
  33. pageNumber = Math.floor(startValue / 10) + 1;
  34. }
  35.  
  36. // Create the table columns
  37. for (var i = 0; i < 11; i++) {
  38. var column = document.createElement('td');
  39. column.style.textAlign = 'center';
  40. column.style.verticalAlign = 'baseline';
  41. column.style.minWidth = '20px';
  42. column.style.fontSize = '16pt';
  43.  
  44. // Add padding to middle columns
  45. if (i > 0 && i < 10) {
  46. column.style.padding = '0 8pt';
  47. }
  48.  
  49. // Add padding to previous and next columns
  50. if (i === 0 || i === 10) {
  51. column.style.padding = '0 24pt';
  52. }
  53.  
  54. // Add content to the columns
  55. if (i === 0) {
  56. if (pageNumber !== 1) {
  57. var previousLink = document.createElement('a');
  58. previousLink.href = window.location.href.replace(startParam + startValue, startParam + (startValue - 10));
  59. previousLink.innerText = '< Previous';
  60. column.appendChild(previousLink);
  61. }
  62. } else if (i === 10) {
  63. var nextLink = document.createElement('a');
  64. nextLink.href = window.location.href.replace(startParam + startValue, startParam + (startValue + 10));
  65. nextLink.innerText = 'Next >';
  66. column.appendChild(nextLink);
  67. } else {
  68. // Calculate the page number for the column
  69. var columnNumber;
  70. if (pageNumber < 5) {
  71. columnNumber = i;
  72. } else if (pageNumber >= 5) {
  73. columnNumber = pageNumber - 5 + i;
  74. }
  75.  
  76. if (columnNumber === pageNumber) {
  77. // Add page number without link
  78. column.innerText = columnNumber;
  79. } else {
  80. // Add page number with link
  81. var newStartValue = (columnNumber - 1) * 10;
  82. if (newStartValue === 0) {
  83. newStartValue = "0";
  84. }
  85. if (startIndex === -1) {
  86. column.innerHTML = `<a href="${window.location.href + startParam + newStartValue}">${columnNumber}</a>`;
  87. } else {
  88. column.innerHTML = `<a href="${window.location.href.replace(startParam + startValue, startParam + newStartValue)}">${columnNumber}</a>`;
  89. }
  90. }
  91. }
  92.  
  93. // Append the column to the table
  94. table.appendChild(column);
  95. }
  96.  
  97. // Append the table to the 'botstuff' div
  98. var botstuffDiv = document.getElementById('botstuff');
  99. botstuffDiv.appendChild(table);
  100. }