Add copy comment link

This commit is contained in:
the1812 2020-08-08 15:10:49 +08:00
parent a4268ca85e
commit 5ff2f409e7
13 changed files with 97 additions and 8 deletions

View File

@ -496,6 +496,7 @@ declare global {
seoJump: boolean,
commentsTranslate: boolean,
copyFeedsLink: boolean,
copyCommentLink: boolean,
latestVersionLink: string,
currentVersion: string,
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -32,6 +32,7 @@
"comments-translate.min.js": "1F66CEC885A6DA36E0436C9A6E1D03E89F19ADDC2F89EC6CDA2BB272DC212A66",
"compact-layout.min.css": "CAC8B0DBA8E90B38D31F0811B7B469709052204AC36D5D3F20FE5D0899FDDCCB",
"compact-layout.min.js": "B20609A7CBBDB1845FA0156FB5BE6B1E1A1B8B069EA85F65D16241DD2C12D738",
"copy-comment-link.min.js": "55C103F372CE2B087239C2C2C447886A2DE5E9D33E3AA4870FE6E549588199B0",
"copy-feeds-link.min.js": "579381349AA2A54A7B8A9AA67A7D35E83DBB456E0A73081E80D4C8DB404604A1",
"custom-control-background.min.css": "1981FD2BF3B17ECF33F98D5DEDAF0D32ACBE9532A51FDB70822286991AB98EF3",
"custom-control-background.min.js": "B9F366B251D1572ACE801FF6ECF15D4D1AAB3EA5A5B04B961B6F4310E2AB1A84",
@ -116,7 +117,7 @@
"gbk.min.js": "872D7A4562F13A539C4A9AF1825DE89E610C775F1AD026EA6986A80DD74E4B53",
"get-number.min.js": "7B81A45D0F7D7F68CC6EDE25E02FCD76F8A05B2CF29274F94A99980BB23D8B76",
"gui-settings.min.css": "F4A6C927F3EEFA876C753E9348259D138C96F6A59DE4453275E222ABAAEC9667",
"gui-settings.min.html": "5410A798C94386A84D863A3B2E8061C935491299F6DEA858E9DA46E9E00094D5",
"gui-settings.min.html": "084A93AAE1BC9D0B6E1430160719142BEC2921A550A1BD8F9CA4D47560264066",
"gui-settings.min.js": "CB6035E301389BE5C4BAD9385135663B0E54ACD0A0B39FFE52C266980E0424FC",
"haruna-scale.min.js": "FD079C86741F614FD63E733CF9B7B896A7D20110754815A540F3341D4DC252B2",
"hide-bangumi-reviews.min.js": "7265C0CE994FDA926355A9A4F9B207E7E68E749D47332F3C537EF93E97927A23",

Binary file not shown.

1
min/copy-comment-link.min.js vendored Normal file
View File

@ -0,0 +1 @@
(()=>{return(t,e)=>{(async()=>{const{forEachCommentItem:t}=await e.importAsync("comment-apis");const i=["https://t.bilibili.com","https://space.bilibili.com","https://live.bilibli.com"];const n=t=>{if(document.URL.match(/\/\/t\.bilibili\.com\/(\d+)/)){return""}if(i.every(t=>!document.URL.includes(t))){return""}let e=t;while(e!==null&&e!==document.body){if(e.hasAttribute("data-did")){return`https://t.bilibili.com/${e.getAttribute("data-did")}`}e=e.parentElement}return""};const l=t=>{[t,...t.replies].forEach(t=>{const e=dq(t.element,".opera-list ul");if(!e||dq(e,".copy-link")){return}const i=document.createElement("li");i.classList.add("copy-link");i.textContent="复制链接";i.addEventListener("click",()=>{const e=n(t.element)||document.URL;GM_setClipboard(`${e}#reply${t.id}`,{mimetype:"text/plain"})});e.appendChild(i)})};t({added:l})})()}})();

File diff suppressed because one or more lines are too long

View File

@ -946,5 +946,11 @@ Resource.manifest = {
copyFeedsLink: '动态链接复制',
},
},
copyCommentLink: {
path: 'copy-comment-link.min.js',
displayNames: {
copyCommentLink: '评论链接复制',
},
},
}
export const resourceManifest = Resource.manifest

View File

@ -245,6 +245,7 @@ export const settings = {
volumeOverdrive: false,
seoJump: true,
copyFeedsLink: false,
copyCommentLink: false,
cache: {},
}
const fixedSettings = {

View File

@ -0,0 +1,46 @@
import { CommentItem } from '../comment-apis'
(async () => {
const { forEachCommentItem } = await import('../comment-apis')
const feedsUrls = [
'https://t.bilibili.com',
'https://space.bilibili.com',
'https://live.bilibli.com',
]
const findParentFeedsUrl = (commentElement: HTMLElement) => {
if (document.URL.match(/\/\/t\.bilibili\.com\/(\d+)/)) {
return ''
}
if (feedsUrls.every(url => !document.URL.includes(url))) {
return ''
}
let element: HTMLElement | null = commentElement
while (element !== null && element !== document.body) {
if (element.hasAttribute('data-did')) {
return `https://t.bilibili.com/${element.getAttribute('data-did')}`
}
element = element.parentElement
}
return ''
}
const addCopyLinkButton = (comment: CommentItem) => {
[comment, ...comment.replies].forEach(item => {
const operationList = dq(item.element, '.opera-list ul') as HTMLUListElement
if (!operationList || dq(operationList, '.copy-link')) {
return
}
const copyLinkButton = document.createElement('li')
copyLinkButton.classList.add('copy-link')
copyLinkButton.textContent = '复制链接'
copyLinkButton.addEventListener('click', () => {
const url = findParentFeedsUrl(item.element) || document.URL
GM_setClipboard(`${url}#reply${item.id}`, { mimetype: 'text/plain' })
})
operationList.appendChild(copyLinkButton)
})
}
forEachCommentItem({
added: addCopyLinkButton
})
})()

View File

@ -143,6 +143,7 @@
<checkbox indent="0" key="selectableColumnText" dependencies=""></checkbox>
<checkbox indent="0" key="urlParamsClean" dependencies=""></checkbox>
<checkbox indent="0" key="preferAvUrl" dependencies=""></checkbox>
<checkbox indent="0" key="copyCommentLink" dependencies=""></checkbox>
<!-- <checkbox indent="0" key="restoreFloors" dependencies=""></checkbox> -->
<category icon="touch">触摸</category>
<checkbox indent="0" key="touchNavBar" dependencies=""></checkbox>