Wix Order E-mail Link

Generate a mailto link with order# in subject.

目前為 2024-11-22 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Wix Order E-mail Link
// @namespace    http://hierosoft.com/
// @version      2024-11-22
// @description  Generate a mailto link with order# in subject.
// @author       Hierosoft (Jake Gustafson)
// @license MIT
// @match        https://*.wix.com/*order-details*
// @grant        none
// @run-at       document-end
// ==/UserScript==

(function() {
    'use strict';

    // User preferences
    const subject_template = "Warranty Order {order_number}";
    const link_text = "Warranty E-mail";

    // Polling interval in milliseconds
    const POLLING_INTERVAL = 250;
    let rewritten = false;

    function rewrite(email_element) {
        // Find the order number
        const header = document.querySelector('div[data-hook="HeaderTitle__TitleText"]');
        if (!header) {
            console.error("Order number element not found!");
            return;
        }

        // Extract the order number and generate the subject
        const order_number = header.textContent.replace("Order ", "");
        const subject = subject_template.replace("{order_number}", order_number);

        // Generate a mailto link
        const mailto_e = document.createElement('a');
        mailto_e.href = `mailto:${email_element.textContent}?subject=${encodeURIComponent(subject)}`;
        mailto_e.style.fontFamily = '"Madefor", "Helvetica Neue", Helvetica, Arial, Meiryo, sans-serif';

        // Create the image
        const img = document.createElement('img');
        img.src = "https://upload.wikimedia.org/wikipedia/commons/c/c0/Tampermonkey_logo.svg";
        img.alt = ""; // Decorative image, no alternative text needed
        img.style.width = "1em";
        img.style.height = "1em";
        img.style.verticalAlign = "middle"; // Align with text baseline

        // Create a non-breaking space
        const nbsp = document.createTextNode('\u00A0');

        // Set the visible content of the link
        mailto_e.appendChild(img);
        mailto_e.appendChild(nbsp);
        mailto_e.appendChild(document.createTextNode(link_text));

        // Add the link to the DOM
        const line_break = document.createElement('br');
        email_element.parentElement.appendChild(line_break);
        email_element.parentElement.appendChild(mailto_e);
    }

    function pollForEmail() {
        if (rewritten) return;

        const email_element = document.querySelector('span[data-hook="InfoCard__UserEmail"]');
        if (email_element) {
            rewritten = true;
            rewrite(email_element);
        }
    }

    // Start polling
    setInterval(pollForEmail, POLLING_INTERVAL);
})();