動漫花園 Copy torrent link shortcut

Generate a link to copy the torrent link.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         動漫花園 Copy torrent link shortcut
// @namespace    https://github.com/whoisnull
// @version      0.4
// @description  Generate a link to copy the torrent link.
// @author       James Smith
// @match        http://share.dmhy.org/topics/view/*
// @match        https://share.dmhy.org/topics/view/*
// @grant        none
// ==/UserScript==

(() => {
  let torrentUrl = document.querySelector('#tabs-1 > p:nth-child(1) > a').href

  let a = document.createElement('a')
  a.href = torrentUrl
  a.textContent = 'Copy torrent link to the clipboard'
  a.style = `
    display: block;
    padding: 10px;
  `
  a.addEventListener('click', onClick)

  let div = document.createElement('div')
  div.id = 'torrent-link'
  div.appendChild(a)
  div.style = `
    position: fixed;
    left: 0;
    bottom: 0;
    margin: 10px;
    background: #fff;
    border-radius: 2px;
    box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);
  `

  document.body.appendChild(div)

  function onClick(event) {
    a.removeEventListener('click', onClick)

    event.preventDefault()

    a.textContent = torrentUrl

    let range = document.createRange()
    range.selectNode(a)

    let selection = window.getSelection()
    selection.empty()
    selection.addRange(range)

    document.execCommand('copy')

    a.textContent = 'Copied. Click again to download the torrent.'
  }
})()