Open in Current

Always open pages in the current window, instead of creating a popup.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Open in Current
// @namespace    http://tampermonkey.net/
// @version      0.1.0
// @description  Always open pages in the current window, instead of creating a popup.
// @author       PRO-2684
// @match        none
// @icon         none
// @license      gpl-3.0
// @grant        unsafeWindow
// ==/UserScript==

(function() {
    "use strict";
    const { name, version } = GM_info.script;
    const debug = console.debug.bind(console, `[${name}@${version}]`);

    const originalOpen = unsafeWindow.open.bind(unsafeWindow);
    function filteredOpen(url, target, features) {
        debug("Intercepted open", url, target, features);
        // Only keep noopener, noreferrer, and attributionsrc
        if (typeof features === "string") {
            // Example: window.open(url, "_blank", "width=780,height=490, top=100, left=380, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no")
            const filteredFeatures = features.split(",").map(f => f.trim()).filter(f =>
                f === "noopener" || f === "noreferrer" || f.startsWith("attributionsrc=")
            ).join(", ");
            return originalOpen(url, target, filteredFeatures);
        } else if (typeof features === "object" && features !== null) {
            const filteredFeatures = {};
            if (features.noopener) filteredFeatures.noopener = features.noopener;
            if (features.noreferrer) filteredFeatures.noreferrer = features.noreferrer;
            if (features.attributionsrc) filteredFeatures.attributionsrc = features.attributionsrc;
            return originalOpen(url, target, filteredFeatures);
        }
    };
    unsafeWindow.open = filteredOpen;
})();