OurChan New Tab Hotfix

Temporary fix to open threads in new tabs

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==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
})();