NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript==
// @name CoverMore辅助工具
// @namespace http://tampermonkey.net/
// @version v0.1.0
// @description CoverMore辅助工具
// @author EchoJ
// @include *insurance*
// @include *covermore*
// @grant none
// @license MIT
// ==/UserScript==
(function () {
'use strict';
// 创建一个悬浮按钮
function createButton(text, clickHandler) {
var button = document.createElement('button');
button.textContent = text;
button.style.position = 'fixed';
// 计算 bottom 和 right 的值
var numButtons = document.querySelectorAll('.echo-j-button').length;
var bottom = 50 + numButtons * 60 + 'px';
var right = '20px';
button.style.bottom = bottom;
button.style.right = right;
button.style.padding = '10px';
button.style.backgroundColor = '#007bff';
button.style.color = 'white';
button.style.border = 'none';
button.style.borderRadius = '5px';
button.style.cursor = 'pointer';
button.addEventListener('click', clickHandler);
button.classList.add('echo-j-button'); // 添加类名 "echo-j-button"
document.body.appendChild(button);
}
// 复制文本到剪贴板
function copyToClipboard(text) {
var tempInput = document.createElement('input');
tempInput.value = text;
document.body.appendChild(tempInput);
tempInput.select();
document.execCommand('copy');
document.body.removeChild(tempInput);
alert(text + '已复制');
}
// 生成链接方法
function generateLink() {
var recallElement = document.getElementById('recallID');
if (recallElement) {
var recallID = recallElement.value;
var currentURL = window.location.origin; // 获取协议和域名部分
var recallLink = `${currentURL}/recall-quote-v2?quoteId=${recallID}`;
// 创建一个临时文本框来实现复制链接
copyToClipboard(recallLink);
}
else {
alert('未找到 recallID 元素');
}
}
// 获取 SiteID
function getSiteID() {
var linkElements = document.querySelectorAll('link[rel="icon"]');
var pattern = /\/sites\/g\/files\/xfwnwa(\d+)/;
var siteid = '';
linkElements.forEach(function (linkElement) {
var href = linkElement.getAttribute('href');
var match = href.match(pattern);
if (match) {
// 提取数字部分
siteid = match[1];
}
});
return siteid;
}
// 复制 SiteID
function copySiteID() {
var recallElement = getSiteID();
if (recallElement) {
copyToClipboard(recallElement);
}
else {
alert('未找到 site ID ');
}
}
// 获取 recallID
function getRecallID() {
var recallElement = document.getElementById('recallID');
if (recallElement) {
return recallElement.value;
}
else {
return 'Nil';
}
}
// 复制 recallID
function copyRecallID() {
var recallElement = getRecallID();
if (recallElement) {
copyToClipboard(recallElement);
}
else {
alert('未找到 recallID 元素');
}
}
// 创建生成链接按钮
createButton('生成 recall-v2 链接', generateLink);
// 创建复制 recallID 值按钮
createButton('复制 recallID: ' + getRecallID(), copyRecallID);
// 创建复制 recallID 值按钮
createButton('复制 siteID: ' + getSiteID(), copySiteID);
})();