糊了个脚本,大概是能工作的,会在时间后面加一个 [ Copy Link ]
,点击后会复制这个时间对应的链接,不过没有任何反馈。(懒
// ==UserScript==
// @name 就复制链接呗
// @namespace 什么什么就是不想写代码
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://twitter.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=twitter.com
// @grant none
// ==/UserScript==
(function() {
'use strict';
const copyText = text => {
const textArea = document.createElement('textarea')
textArea.setAttribute('readonly', 'readonly')
textArea.value = text
document.body.appendChild(textArea)
textArea.select()
document.execCommand('copy')
document.body.removeChild(textArea)
}
const setupCopyLink = ()=>{
document.body.querySelectorAll('a>time').forEach(e=>{
const timeLink = e.parentElement
if(!timeLink.getAttribute('copylink-mark') && /^https:\/\/twitter\.com\/[\w-]+\/status\/\d+/.test(timeLink.href)){
const copyLink = document.createElement('a')
copyLink.innerText = ' [ Copy link ]'
copyLink.addEventListener('click', e=>{
e.preventDefault()
copyText(timeLink.href)
}, false)
timeLink.parentElement.appendChild(copyLink)
timeLink.setAttribute('copylink-mark', 'true')
}
})
}
document.addEventListener('scroll', setupCopyLink)
})();