Guest User

Untitled

a guest
Nov 20th, 2025
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. // ==UserScript==
  2. // @name telegra.ph enum
  3. // @namespace https://telegra.ph/
  4. // @version 2025-11-20
  5. // @description Позволяет одной кнопкой скроллить по датам и страницам на telegra.ph
  6. // @author anon
  7. // @match https://telegra.ph/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=2ch.org
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. const addButtons = () => {
  16. const buttonsContainer = document.createElement('div');
  17. buttonsContainer.style.position = 'fixed';
  18. buttonsContainer.style.display = 'flex';
  19. buttonsContainer.style.flexFlow = 'column nowrap';
  20. buttonsContainer.style.top = '50%';
  21. buttonsContainer.style.right = '10px';
  22. buttonsContainer.style.transform = 'translateY(-50%)';
  23. buttonsContainer.style.zIndex = '1000';
  24. buttonsContainer.style.backgroundColor = 'white';
  25. buttonsContainer.style.padding = '10px';
  26. buttonsContainer.style.borderRadius = '5px';
  27. buttonsContainer.style.boxShadow = '0 2px 5px rgba(0, 0, 0, 0.5)';
  28.  
  29. const createButton = (text, onClick) => {
  30. const button = document.createElement('button');
  31. button.innerText = text;
  32. button.style.margin = '5px';
  33. button.onclick = onClick;
  34. buttonsContainer.appendChild(button);
  35. };
  36.  
  37. const changeDate = (dayChange, pageChange) => {
  38. let currentPath = window.location.pathname.split('/');
  39. let wordWithDate = currentPath[1]; // Keep the whole string, e.g., "word-02-12[-1]"
  40.  
  41. let datePart = wordWithDate.match(/(.*?)-(\d{2})-(\d{2})(?:-(\d+))?/);
  42. let word = datePart[1]; // Extract the word part
  43. let month = parseInt(datePart[2]);
  44. let dayNum = parseInt(datePart[3]) + dayChange;
  45. // let pageNum = datePart[4] ? parseInt(datePart[4]) + pageChange : 0;
  46. let pageNum = datePart[4] ? parseInt(datePart[4]) + pageChange : 0;
  47.  
  48. // Handle day overflow
  49. if (dayNum < 1) {
  50. month -= 1;
  51. if (month < 1) {
  52. month = 12;
  53. }
  54. dayNum = 31; // Reset to the last day of the previous month (simplistically)
  55. }
  56. if (dayNum > 31) {
  57. dayNum = 1;
  58. month += 1;
  59. if (month > 12) {
  60. month = 1;
  61. }
  62. }
  63.  
  64. const newDate = `${String(month).padStart(2, '0')}-${String(dayNum).padStart(2, '0')}`;
  65. const newPage = pageNum > 0 ? `-${pageNum}` : pageChange === 1 ? '-1' : '';
  66.  
  67. const newPath = `/${word}-${newDate}${newPage}`;
  68. window.history.pushState({}, '', newPath); // Update URL in the address bar
  69. window.location.pathname = newPath; // Trigger page load
  70. };
  71.  
  72. createButton('◄', () => changeDate(-1, 0)); // Back by day
  73. createButton('►', () => changeDate(1, 0)); // Forward by day
  74. createButton('▲', () => changeDate(0, -1)); // Page up
  75. createButton('▼', () => changeDate(0, 1)); // Page down
  76.  
  77. document.body.appendChild(buttonsContainer);
  78. };
  79.  
  80. addButtons();
  81. })();
  82.  
Advertisement
Add Comment
Please, Sign In to add comment