创建新窗口 with 链接

在当前页面点击悬浮图标后,在新窗口中打开当前页面的链接

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         创建新窗口 with 链接
// @namespace    http://your-namespace.com
// @version      1.1.0
// @description  在当前页面点击悬浮图标后,在新窗口中打开当前页面的链接
// @author       吃不吃香菜
// @license      MIT
// @match        http://*/*
// @match        https://*/*
// @grant        GM_getValue
// @grant        GM_setValue
// ==/UserScript==

(function() {
    'use strict';

    var iconUrl = GM_getValue('iconUrl', 'https://vip.helloimg.com/images/2023/10/18/o2TCvg.jpg'); // 获取保存的图标地址,默认为默认图标地址

    // 创建悬浮图标
    var floatingIcon = document.createElement('div');
    floatingIcon.style.backgroundImage = 'url(' + iconUrl + ')';
    floatingIcon.style.backgroundSize = '100% 100%';
    floatingIcon.style.position = 'fixed';
    floatingIcon.style.bottom = '20px';
    floatingIcon.style.right = '20px';
    floatingIcon.style.width = '50px';
    floatingIcon.style.height = '50px';
    floatingIcon.style.borderRadius = '50%';
    floatingIcon.style.cursor = 'pointer';
    document.body.appendChild(floatingIcon);

    // 取消窗口和文档失去焦点事件的处理函数,并在控制台中输出“运行成功”
    window.onblur = null;
    document.onblur = null;
    console.log("运行成功");

    // 点击悬浮图标时创建新窗口
    floatingIcon.addEventListener('click', function() {
        var newWindow = window.open(window.location.href, '_blank', 'width=300,height=300');
        newWindow.focus();
    });

    // 右击悬浮图标时上传新图标
    floatingIcon.addEventListener('contextmenu', function(event) {
        event.preventDefault();
        var fileInput = document.createElement('input');
        fileInput.type = 'file';
        fileInput.accept = 'image/*';
        fileInput.style.display = 'none';
        document.body.appendChild(fileInput);

        fileInput.addEventListener('change', function() {
            var file = fileInput.files[0];
            var reader = new FileReader();
            reader.onload = function(e) {
                iconUrl = e.target.result;
                floatingIcon.style.backgroundImage = 'url(' + iconUrl + ')';
                GM_setValue('iconUrl', iconUrl); // 保存图标地址
            };
            reader.readAsDataURL(file);
            document.body.removeChild(fileInput);
        });

        fileInput.click();
    });

})();