Greasy Fork is available in English.

Bilibili网页应用增强(强制所有操作在应用中打开,不跳转edge浏览器)

使用方法:【edge打开bilibili->右上角->"..."->应用->将此站点安装为应用】优化B站/哔哩哔哩/知乎作为网站应用安装后会跳转浏览器

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください。
// ==UserScript==
// @name     Bilibili网页应用增强(强制所有操作在应用中打开,不跳转edge浏览器)
// @description  使用方法:【edge打开bilibili->右上角->"..."->应用->将此站点安装为应用】优化B站/哔哩哔哩/知乎作为网站应用安装后会跳转浏览器
// @version  1
// @author   Phoeky
// @match  https://*.bilibili.com/*
// @match  https://*.zhihu.com/*
// @namespace https://greasyfork.org/users/1247761
// ==/UserScript==
(function() {
    'use strict';

    // Function to change link's target to "_self"
    const changeLinkTarget = (link) => {
        link.setAttribute('target', '_self');
    };

    // Observe new nodes added to the document
    const observer = new MutationObserver((mutations) => {
        mutations.forEach((mutation) => {
            if (mutation.type === 'childList') {
                const links = mutation.addedNodes.flatMap((node) => {
                    if (node.tagName === 'A') {
                        return [node];
                    }
                    return node.getElementsByTagName('a');
                });

                links.forEach(changeLinkTarget);
            }
        });
    });

    // Start observing the document
    observer.observe(document.documentElement, {
        childList: true,
        subtree: true,
    });

    // Also change existing links on the page
    document.querySelectorAll('a').forEach(changeLinkTarget);

    // Wait for the page to load completely
    window.onload = () => {
        // Start observing the document after the page is loaded
        observer.observe(document.documentElement, {
            childList: true,
            subtree: true,
        });

        // Also change existing links on the page after the page is loaded
        document.querySelectorAll('a').forEach(changeLinkTarget);
    };
})();