OurChan New Tab Hotfix

Temporary fix to open threads in new tabs

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

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