Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name telegra.ph enum
- // @namespace https://telegra.ph/
- // @version 2025-11-20
- // @description Позволяет одной кнопкой скроллить по датам и страницам на telegra.ph
- // @author anon
- // @match https://telegra.ph/*
- // @icon https://www.google.com/s2/favicons?sz=64&domain=2ch.org
- // @grant none
- // ==/UserScript==
- (function() {
- 'use strict';
- const addButtons = () => {
- const buttonsContainer = document.createElement('div');
- buttonsContainer.style.position = 'fixed';
- buttonsContainer.style.display = 'flex';
- buttonsContainer.style.flexFlow = 'column nowrap';
- buttonsContainer.style.top = '50%';
- buttonsContainer.style.right = '10px';
- buttonsContainer.style.transform = 'translateY(-50%)';
- buttonsContainer.style.zIndex = '1000';
- buttonsContainer.style.backgroundColor = 'white';
- buttonsContainer.style.padding = '10px';
- buttonsContainer.style.borderRadius = '5px';
- buttonsContainer.style.boxShadow = '0 2px 5px rgba(0, 0, 0, 0.5)';
- const createButton = (text, onClick) => {
- const button = document.createElement('button');
- button.innerText = text;
- button.style.margin = '5px';
- button.onclick = onClick;
- buttonsContainer.appendChild(button);
- };
- const changeDate = (dayChange, pageChange) => {
- let currentPath = window.location.pathname.split('/');
- let wordWithDate = currentPath[1]; // Keep the whole string, e.g., "word-02-12[-1]"
- let datePart = wordWithDate.match(/(.*?)-(\d{2})-(\d{2})(?:-(\d+))?/);
- let word = datePart[1]; // Extract the word part
- let month = parseInt(datePart[2]);
- let dayNum = parseInt(datePart[3]) + dayChange;
- // let pageNum = datePart[4] ? parseInt(datePart[4]) + pageChange : 0;
- let pageNum = datePart[4] ? parseInt(datePart[4]) + pageChange : 0;
- // Handle day overflow
- if (dayNum < 1) {
- month -= 1;
- if (month < 1) {
- month = 12;
- }
- dayNum = 31; // Reset to the last day of the previous month (simplistically)
- }
- if (dayNum > 31) {
- dayNum = 1;
- month += 1;
- if (month > 12) {
- month = 1;
- }
- }
- const newDate = `${String(month).padStart(2, '0')}-${String(dayNum).padStart(2, '0')}`;
- const newPage = pageNum > 0 ? `-${pageNum}` : pageChange === 1 ? '-1' : '';
- const newPath = `/${word}-${newDate}${newPage}`;
- window.history.pushState({}, '', newPath); // Update URL in the address bar
- window.location.pathname = newPath; // Trigger page load
- };
- createButton('◄', () => changeDate(-1, 0)); // Back by day
- createButton('►', () => changeDate(1, 0)); // Forward by day
- createButton('▲', () => changeDate(0, -1)); // Page up
- createButton('▼', () => changeDate(0, 1)); // Page down
- document.body.appendChild(buttonsContainer);
- };
- addButtons();
- })();
Advertisement
Add Comment
Please, Sign In to add comment