Reddit Post Paging

Allows you to view the next/previous post globally on reddit

Click here to install Browse More Scripts
// ==UserScript==
// @name         Reddit Post Paging
// @namespace    f2e86182cf661d6afda4d09c4868921d052c42c0
// @version      0.1
// @description  Allows you to view the next/previous post globally on reddit
// @author       /u/AyrA_ch
// @match        https://www.reddit.com/*
// @grant        none
// ==/UserScript==

(function (box) {
    'use strict';
    var nav = {
        id: parseInt(location.pathname.match(/\/comments\/([a-z\d]+)/)[1] || "0", 36),
        next: function () {
            location.href = "https://redd.it/" + (nav.id + 1).toString(36);
        },
        prev: function () {
            location.href = "https://redd.it/" + (nav.id - 1).toString(36);
        }
    };

    //URL might ot have an id if it's not for a submission
    if (nav.id !== 0) {
        if (box) {
            var holder = document.createElement("div");
            var btn = document.createElement("button");
            btn.textContent = "<< Prev";
            btn.addEventListener("click", nav.prev);
            holder.appendChild(btn);

            btn = btn.cloneNode(false);
            btn.textContent = "Next >>";
            btn.addEventListener("click", nav.next);
            holder.appendChild(btn);

            holder.setAttribute("style", "display:block;text-align:center;margin:1em");

            box.appendChild(holder);

            box.style.display = "block";
            box.style.visibility = "visible";
        } else {
            console.error("No box or body found", box);
        }
    }
})((document.querySelector("#shortlink-text") || document.querySelector("#classy-error")).parentNode);

/*
LICENSE:
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
The full license text can be found here: http://creativecommons.org/licenses/by-nc-sa/4.0/
The link has an easy to understand version of the license and the full license text.

DISCLAIMER:
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
*/

Copyright © 2018 by Kevin Gut 📧 | More services | Generated for 54.236.62.49