Skip to content

获取当前页所有域名并写入剪切板

快捷使用:新建浏览器书签,写入脚本

js
javascript:(async function () {
  const domains = new Set()
  window.performance.getEntriesByType('resource').forEach((resource) => {
    const url = new URL(resource.name)
    domains.add(url.hostname)
  })
  const domainList = Array.from(domains)
  function copy(value) {
    const ta = document.createElement('textarea')
    ta.value = value ?? ''
    ta.style.position = 'absolute'
    ta.style.opacity = '0'
    document.body.appendChild(ta)
    ta.select()
    document.execCommand('copy')
    ta.remove()
  };
  console.log('%c数组:\n', 'color: green; font-weight: bold;', domainList)
  console.log('%c字符串:\n', 'color: green; font-weight: bold;', domainList.join('\n'))
  copy(JSON.stringify(domainList))
})()

把此网站的多个页面所引用的页面去重

js
javascript:(async function () {
  const input = prompt('请输入字符串数组,用英文逗号分隔')
  const matches = input.match(/"(.*?)"/g).map((val) => {
    return val.slice(1, -1)
  })
  function copy(value) {
    const ta = document.createElement('textarea')
    ta.value = value ?? ''
    ta.style.position = 'absolute'
    ta.style.opacity = '0'
    document.body.appendChild(ta)
    ta.select()
    document.execCommand('copy')
    ta.remove()
  };
  const output = Array.from(new Set(matches)).join('\n')
  console.log('%c字符串:\n', 'color: green; font-weight: bold;', output)
  copy(output)
})()