一键复制

try to take over the world!

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         一键复制
// @namespace    http://tampermonkey.net/
// @version      0.7
// @description  try to take over the world!
// @author       You
// @match        http://*/*
// @match        https://*/*
// @require      https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js
// @grant        GM_setClipboard
// @license MIT
// ==/UserScript==
(function () {
  'use strict'
  $('body').on('click', '*', function (event) {
    if (event.altKey) {
      event.preventDefault()
      event.stopPropagation()
      let text = $(this).text().trim() || $(this).val()
      if (text) {
        text = text
          .replace(/[::]$/, '')
          .replace(/^'(.*)'$/, '$1')
          .replace(/^"(.*)"$/, '$1')
        if (text) {
          highlight(event.target)
          GM_setClipboard(text)
        }
      } else if ($(this).find('input')) {
        const val = $(this).find('input').eq(0).val()
        if (val) {
          highlight($(this).find('input')[0])
          GM_setClipboard(val)
        }
      }
    }
  })

  let addedList = []
  if (location.origin === 'https://codesign.qq.com') {
    setInterval(() => {
      const iframes = document.querySelectorAll('iframe');
      iframes.forEach(item => {
        if (!addedList.includes(item.src)) {
          addedList.push(item.src)
          if (item.contentDocument?.body) {
            $(item.contentDocument.body).on('click', '*', function (event) {
              if (event.altKey) {
                event.preventDefault()
                event.stopPropagation()
                let text = $(this).text().trim() || $(this).val()
                if (text) {
                  text = text
                    .replace(/[::]$/, '')
                    .replace(/^'(.*)'$/, '$1')
                    .replace(/^"(.*)"$/, '$1')
                  if (text) {
                    highlight(event.target, item)
                    GM_setClipboard(text)
                  }
                } else if ($(this).find('input')) {
                  const val = $(this).find('input').eq(0).val()
                  if (val) {
                    highlight($(this).find('input')[0], item)
                    GM_setClipboard(val)
                  }
                }
              }
            })
          }

        }
      })
    }, 300)
  }

  function highlight(clickedElement, doc) {
    let d = document
    let frameX = 0
    let frameY = 0
    if (doc) {
      d = doc.contentDocument
      const rect = doc.getBoundingClientRect()
      frameX = rect.x
      frameY = rect.y
    }
    const rect = clickedElement.getBoundingClientRect()
    const frame = d.createElement('div')
    frame.style.position = 'absolute'
    frame.style.top = frameY + rect.top + window.scrollY - 4 + 'px'
    frame.style.left = frameX + rect.left + window.scrollX - 4 + 'px'
    frame.style.width = rect.width + 8 + 'px'
    frame.style.height = rect.height + 8 + 'px'
    frame.style.border = 'solid 2px gold'
    frame.style.borderRadius = '5px'
    frame.style.zIndex = '99999'
    frame.style.pointerEvents = 'none'
    document.body.appendChild(frame)
    $(frame).fadeIn(300, 'swing').delay(500).fadeOut(500, 'swing')
  }
})();