Guardian Previous/Next

Add Previous and Next buttons to Guardian (Cryptic) Crosswords

// ==UserScript==
// @license MIT
// @name         Guardian Previous/Next
// @namespace    http://greasyfork.org/
// @version      2025-09-04
// @description  Add Previous and Next buttons to Guardian (Cryptic) Crosswords
// @author       GaryT
// @match        https://www.theguardian.com/crosswords/cryptic/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=theguardian.com
// @grant        none
// ==/UserScript==

function styleElem(astyle) {
    const series = document.querySelector("a.dcr-a0da13");
    astyle.fontWeight="bold";
    astyle.textDecoration = "none";
    astyle.color = window.getComputedStyle(series).color;
}

(function() {
    'use strict';
//    console.log("GTPN");
    const crozzi = "https://www.theguardian.com/crosswords/cryptic/"
    const title = document.querySelector("h1.dcr-uc7bn6");
    const gtURL = window.location.href;
    const match = /https:.*\/cryptic\/([0-9]+)/.exec(gtURL);
    const this1 = parseInt(match[1]);
    const prev1=(this1+2)%6?this1-1:this1-2; //sorry, but I love ternaries...
    const next1=(this1-2)%6?this1+1:this1+2;


    let GTPrev = document.createElement('a');
    GTPrev.href = crozzi+(prev1);
    GTPrev.text = "< ";
    GTPrev.title = "Previous Crossword";
    styleElem(GTPrev.style);

    let GTNext = document.createElement('a');
    GTNext.href = crozzi+(next1);
    GTNext.text = " >";
    GTNext.title = "Next Crossword";
    styleElem(GTNext.style);

    title.insertBefore(GTPrev,title.firstChild);
    title.appendChild(GTNext);
})();