Pop-up window

Open current page or links to a standalone window without UI elements

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Pop-up window
// @namespace   Open current page or links to a standalone window without UI elements
// @match       *://*/*
// @grant       none
// @version     Alpha-v1
// @description Open current page or links to a standalone window without UI elements
// @author      JesusisLord
// @license     MIT
// ==/UserScript==
(function() {
  "use strict";

  function createStandaloneWindow(url, targetWindow = window) {
    const win = targetWindow.open(url, "_blank", "width=800,height=600,toolbar=no,location=no,menubar=no,scrollbars=no");
    win.focus();
    return win;
  }

  const openLinkHandler = (event) => {
    // Prevent default link behavior (needed):
    event.preventDefault();
    const url = event.target.href || event.target.parentNode.href;
    createStandaloneWindow(url);
  };

  const movePageHandler = () => {
    createStandaloneWindow(window.location.href);
  };

  document.addEventListener("click", (event) => {
    if (event.ctrlKey) {
      if (event.target.nodeName === "A") {
        openLinkHandler(event);
      } else if (!event.target.isContentEditable && !event.target.matches('input, textarea, button, select')) {
        event.preventDefault(); // Optional: Prevent default actions on empty space
        movePageHandler();
      }
    }
  });
})();