PDA

View Full Version : Navigate TA threads with arrow keys (+ last unread shortcut) script



sacha
04-11-2024, 01:27 AM
I'm a very lazy lady and I made a 'copy codeblock button' script (https://www.theapricity.com/forum/showthread.php?381327-A-small-copy-button-script) a few months ago because I hate copying calculators manually. Now I have made another script and I am sharing it with you all in case you are lazy like me. What does it do?

~ You can go through TA threads with multiple pages using the left and right arrow keys
~ You can jump to the latest unread post in a thread using Alt+U

Note: going through pages will have some lag, not because of the script but because of TA. They will load at the same speed that they normally do. No magic for that.

But Sacha, how do I install the script?

It's very easy, all you must do is install TamperMonkey (https://www.tampermonkey.net/) and click "Create new userscript", then paste this code in. You will need to refresh TA for it to start working.

Are you stealing my information?

Yes, I will seize your bank account and spend 500€ on model airplanes after you install this.

The script:


// ==UserScript==
// @name TA thread navi
// @namespace http://tampermonkey.net/
// @version 0.2
// @description Navigate TA threads with left and right arrow keys, see latest unread using alt + U
// @author sacha
// @match https://www.theapricity.com/forum/showthread.php*
// @grant none
// @run-at document-end
// ==/UserScript==

(function() {
'use strict';

document.addEventListener('keydown', function(e) {
if (e.key === "ArrowRight") {
const nextButton = document.querySelector('span.prev_next a[rel="next"]');
if (nextButton && nextButton.href) {
window.location.href = nextButton.href;
}
}

else if (e.key === "ArrowLeft") {
const prevButton = document.querySelector('span.prev_next a[rel="prev"]');
if (prevButton && prevButton.href) {
window.location.href = prevButton.href;
}
}

else if (e.key === "u" && e.altKey) {
const firstUnreadButton = document.querySelector('a.firstunread');
if (firstUnreadButton && firstUnreadButton.href) {
window.location.href = firstUnreadButton.href;
}
}
});
})();

sacha
04-11-2024, 01:44 AM
Also I just made this:



// ==UserScript==
// @name TA thumbs up hotkey
// @namespace http://tampermonkey.net/
// @version 0.1
// @description If you press "ctrl+alt+t" while hovering over a post, it will like/unlike that post
// @author sacha
// @match https://www.theapricity.com/forum/showthread.php*
// @grant none
// @run-at document-end
// ==/UserScript==

(function() {
'use strict';

let hoveredPostId = null;

document.querySelectorAll('#posts > li').forEach(post => {
post.addEventListener('mouseover', function() {
hoveredPostId = this.id;
});
post.addEventListener('mouseout', function() {
hoveredPostId = null;
});
});

document.addEventListener('keydown', function(e) {
if (e.ctrlKey && e.altKey && e.key === 't') {
if (hoveredPostId) {
const postIdNumber = hoveredPostId.replace('post_', '');
const thumbsUpButton = document.querySelector(`a#sc_thumbs_button_${postI dNumber}`);
if (thumbsUpButton) {
thumbsUpButton.click();
} else {
alert('No thumbs up button found :(');
}
} else {
alert("You're not hovering over a post :(.");
}
}
});
})();


Self-explanatory, the lag is again just normal TA lag but you can like posts by hovering over them and pressing "CTRL+ALT+T". Disliking works the same way, just do it again.

Don't spam the hotkeys please :(

Annihilus
04-12-2024, 07:12 AM
nerd :p :)