OurChan New Tab Hotfix

Temporary fix to open threads in new tabs

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

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