Last active
July 7, 2022 19:32
-
-
Save unarist/6b445cbb588b405389defb6dbb36e0d9 to your computer and use it in GitHub Desktop.
Mastodon - Add older/newer link
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Mastodon - Add older/newer link | |
// @namespace https://github.com/unarist/ | |
// @version 0.2 | |
// @description Add user timeline link with max_id/min_id to status pages | |
// @author unarist | |
// @downloadURL https://gist.github.com/unarist/6b445cbb588b405389defb6dbb36e0d9/raw/mastodon-add-older-newer-link.user.js | |
// @match https://*/@*/* | |
// @grant none | |
// @noframes | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const tag = (name, props = {}) => Object.assign(document.createElement(name), props), | |
incr = s => s.replace(/(.?)(9*)$/, (_, x, y) => ++x + y.replace(/9/g, 0)), | |
decr = s => s.replace(/(.?)(0*)$/, (_, x, y) => --x + y.replace(/0/g, 9)), | |
target = document.querySelector('.detailed-status__meta'); | |
if (!target) return; | |
[ | |
tag('a', { href: location.href.replace(/\d+$/, id => '?max_id=' + incr(id)), textContent: 'older', style: 'margin-left: 1ex; color: inherit' }), | |
tag('a', { href: location.href.replace(/\d+$/, id => '?min_id=' + decr(id)), textContent: 'newer', style: 'margin-left: 1ex; color: inherit' }), | |
].forEach(target.appendChild.bind(target)); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment