Copy and Search URL Fragment + Page Navigator

Space to Google search current URL fragment, Q to go to previous page, E to go to next page.

  1. // ==UserScript==
  2. // @name Copy and Search URL Fragment + Page Navigator
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description Space to Google search current URL fragment, Q to go to previous page, E to go to next page.
  6. // @author Druid
  7. // @match *://fitgirl-repacks.site/*
  8. // @license MIT
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. document.addEventListener('keydown', function(event) {
  16. const currentUrl = window.location.href;
  17.  
  18. // SPACE - Google search the URL fragment
  19. if (event.code === 'Space') {
  20. event.preventDefault();
  21.  
  22. let urlFragment = currentUrl.replace(/https?:\/\/[^/]+\//, '').replace(/-/g, ' ').replace(/\/$/, '');
  23. const searchUrl = `https://www.google.com/search?q=${encodeURIComponent(urlFragment)}`;
  24. window.open(searchUrl, '_blank');
  25. }
  26.  
  27. // Q - Go to previous page
  28. if (event.code === 'KeyQ') {
  29. event.preventDefault();
  30.  
  31. let newUrl = currentUrl.replace(/(\/page\/)(\d+)(\/?)/, function(match, prefix, pageNum) {
  32. let prevPage = Math.max(parseInt(pageNum) - 1, 1);
  33. return `${prefix}${prevPage}/`;
  34. });
  35.  
  36. // If no /page/ in URL, go to page 1
  37. if (!/\/page\/\d+/.test(currentUrl)) {
  38. newUrl = currentUrl.replace(/\/$/, '') + '/page/1/';
  39. }
  40.  
  41. window.location.href = newUrl;
  42. }
  43.  
  44. // E - Go to next page
  45. if (event.code === 'KeyE') {
  46. event.preventDefault();
  47.  
  48. if (/\/page\/\d+/.test(currentUrl)) {
  49. let newUrl = currentUrl.replace(/(\/page\/)(\d+)(\/?)/, function(match, prefix, pageNum) {
  50. let nextPage = parseInt(pageNum) + 1;
  51. return `${prefix}${nextPage}/`;
  52. });
  53. window.location.href = newUrl;
  54. } else {
  55. // If no page number in URL, start with page 2
  56. let baseUrl = currentUrl.replace(/\/$/, '');
  57. window.location.href = baseUrl + '/page/2/';
  58. }
  59. }
  60. });
  61. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址