Thread Navigating by Arrow keys

Use ← or → and Ctrl to navigate to previous, next, first or last page

Versione datata 10/04/2015. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name        Thread Navigating by Arrow keys
// @namespace   https://greasyfork.org/scripts/6849-thread-navigating-by-arrow-keys
// @description Use ← or → and Ctrl to navigate to previous, next, first or last page
// @author      theheroofvn
// @include     /^.*(thread|forum|diendan).*$/
// @include     http://www.vn-zoom.com/*
// @require     http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js
// @grant       none
// @version     5.7
// ==/UserScript==
if (frameElement) return;
this.$ = this.jQuery = jQuery.noConflict(true);
var prev, next, first, last, up, up_sub = '[itemtype="http://data-vocabulary.org/Breadcrumb"] a';
var site_info = [
    {
		host: "www.webtretho.com",
		prev: "a.arrowPrePage",
		next: "a.arrowNextPage",
		first: "a.arrowFstPage",
		last: "a.arrowLstPage"
    },
    {
        host: "forum.bkav.com.vn",
        prev: "a.js-pagenav-prev-button[href]:not([href=''])",
        next: "a.js-pagenav-next-button[href]:not([href=''])",
        first: "a[data-page='1']",
        last: "a.js-pagenav-button[href]:not([href='']):nth-last-child(2)",
        up: "#breadcrumbs a.crumb-link"
    }
];
function custom_site(list) {
    if (list.length === 0) return 0;
    for (var i = 0; i < list.length; i++) {
        if (location.hostname == list[i].host) {
			prev  = list[i].prev;
			next  = list[i].next;
			first = list[i].first;
			last  = list[i].last;
			up    = list[i].up;
            return 1;
        }
    }
    return 0;
}
function checkScriptExist(script) {
    return $('script[src*="' + script + '"]').length > 0 ? true : false;
}
function detect_forum() {
    var result = "";
    if (checkScriptExist("vbulletin")) result = "vbb"; else if (checkScriptExist("xenforo")) result = "xenforo"; else if (checkScriptExist("general.js")) result = "mybb"; else if (checkScriptExist("forum_fn.js")) result = "phpbb";
    return result;
}
var detect = detect_forum();
if (custom_site(site_info) === 0) {
    if (detect == "vbb") {
		prev  = 'a[rel="prev"]';
		next  = 'a[rel="next"]';
		first = 'a[rel="start"]';
		last  = 'a[title^="Last"], a[title*="uối"]';
		up    = "span.navbar a, li.navbit a";
    } else if (detect == "xenforo") {
		prev  = ".PageNav a.text:first-child";
		next  = ".PageNav a.text:last-child";
		last  = ".PageNav nav > a:nth-last-child(2)";
		first = 'a[rel="start"]';
		up    = "a.crumb";
    } else if (detect == "mybb") {
		prev  = "a.pagination_previous";
		next  = "a.pagination_next";
		first = "a.pagination_first";
		last  = "a.pagination_last";
		up    = ".navigation > a";
    } else if (detect == "phpbb") {
		prev  = ".display-options a.left-box.left";
		next  = ".display-options a.right-box.right";
		first = ".pagination > span > a:first-child";
		last  = ".pagination > span > a:last-child";
		up    = ".navlinks > .icon-home a";
    } else return;
}
var multi = {17:!1,8:!1,37:!1,39:!1}, multi1 = {17:!1,8:!1}, multi2 = {17:!1,37:!1}, multi3 = {17:!1,39:!1};
var nav = {
    prev: $(prev)[0],
    next: $(next)[0],
    first: $(first)[0],
    last: $(last)[0],
    up: function() {
        return $(up).length > 0 ? $(up).last()[0] : $(up_sub).last()[0];
    }
};
$(window).keydown(function(e) {
    var key = e.keyCode, action = null, link = null;
    if (key in multi) multi[key] = true; else return;
    if (key in multi1) {
        if (multi[17] && multi[8]) action = "up";
    } else if (key in multi2) {
        if (!multi[17] && multi[37]) action = "prev"; else if (multi[17] && multi[37]) action = "first";
    } else if (key in multi3) {
        if (!multi[17] && multi[39]) action = "next"; else if (multi[17] && multi[39]) action = "last";
    }
    if (!action || typeof nav[action] === "undefined" || e.target.tagName == "INPUT" || e.target.tagName == "TEXTAREA") return;
    if (typeof nav[action] === "function") link = nav[action](); else link = nav[action];
    window.location = link;
}).keyup(function(e) {
    if (e.keyCode in multi) multi[e.keyCode] = false;
});