98手机网页版复制代码增强

解决98手机网页版复制代码只复制第一行问题

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         98手机网页版复制代码增强
// @namespace    http://tampermonkey.net/
// @version      1.5
// @description  解决98手机网页版复制代码只复制第一行问题
// @author       bbbyqq
// @match        *://*/forum.php?mod=viewthread*
// @license      bbbyqq
// ==/UserScript==

(function () {
  'use strict'

  document.querySelectorAll('.blockbtn').forEach(btn => {
    btn.addEventListener('click', () => {
      const id = btn.getAttribute('data-clipboard-target')
      const code = []
      document.querySelector(id).parentNode.querySelectorAll('li').forEach(item => {
        code.push(item.innerText)
      })
      const codeText = code.join('\n')
      setTimeout(() => {
        copyContent(codeText)
      }, 500)
    })
  })

  function copyContent (text) {
    const textarea = document.createElement('textarea')
    textarea.value = text
    document.body.appendChild(textarea)
    textarea.select()
    document.execCommand('copy')
    document.body.removeChild(textarea)
  }

})()