OurChan New Tab Hotfix

Temporary fix to open threads in new tabs

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         OurChan New Tab Hotfix
// @namespace    https://ourchan.org/
// @version      1.0
// @description  Temporary fix to open threads in new tabs
// @author       Sneed
// @match        https://ourchan.org/*/index.html
// @match        https://ourchan.org/*/catalog.html
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';
    
    // Check page type once for efficiency
    const isIndex = location.pathname.indexOf('/index.html') > -1;
    
    // Single event handler w/ capture phase
    document.addEventListener('click', function(e) {
        // Find clicked anchor or parent anchor
        const a = e.target.closest('a');
        if (!a || !a.href || a.href.indexOf('/thread/') === -1) return;
        
        // Handle Open links on index pages
        if (isIndex) {
            if (a.textContent === '[Open]' && a.parentNode.className === 'noselect') {
                e.preventDefault();
                window.open(a.href, '_blank');
            }
        } 
        // Handles thumbnails on catalog pages
        else if (e.target.classList.contains('catalog-thumb') || a.closest('.post-file-src')) {
            e.preventDefault();
            window.open(a.href, '_blank');
        }
    }, true); // Using capture phase for better performance
})();