Beehaw.org Open Posts in New Tab

Opens specific links in a new tab on beehaw.org

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

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

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         Beehaw.org Open Posts in New Tab
// @namespace    https://greasyfork.org/en/users/1127287-harasho
// @version      0.6
// @description  Opens specific links in a new tab on beehaw.org
// @author       You
// @match        https://beehaw.org/*
// @grant        none
// @license MIT
// ==/UserScript==

(function () {
    'use strict';

    // Function to add onclick attribute to specific links
    function addTargetBlankToLinks() {
        const addOnclickToLink = (link) => {
            link.setAttribute('onclick', "window.open(this.href,'_blank');return false;");
        };

        const primaryLinks = document.querySelectorAll('a.link-primary');
        const darkLinksInH1 = document.querySelectorAll('h1 a.link-dark');
        const specificLinks = document.querySelectorAll('.btn.btn-link.btn-sm.text-muted.ps-0');
        const otherLinks = document.querySelectorAll('a.thumbnail.rounded.overflow-hidden.d-inline-block.position-relative.p-0.border-0');

        primaryLinks.forEach(addOnclickToLink);
        darkLinksInH1.forEach(addOnclickToLink);
        specificLinks.forEach(addOnclickToLink);
        otherLinks.forEach(addOnclickToLink);
    }

    // Observe DOM changes and add onclick attribute to newly added links
    const observer = new MutationObserver(() => {
        addTargetBlankToLinks();
    });

    const targetNode = document.body;
    const observerConfig = {
        childList: true,
        subtree: true,
    };

    observer.observe(targetNode, observerConfig);

    // Call the function to add onclick attribute to existing links
    addTargetBlankToLinks();
})();