B 站获取时间戳 markdown 链接

按 T 就能复制带时间戳的 URL 的 markdown连接了

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         B 站获取时间戳 markdown 链接
// @description  按 T 就能复制带时间戳的 URL 的 markdown连接了
// @match        https://www.bilibili.com/video/*
// @icon         https://www.google.com/s2/favicons?domain=bilibili.com
// @namespace    http://shawroger.gitee.io/
// @version      0.0.1
// @author       shawroger
// @license MIT
// ==/UserScript==

(function() {
	'use strict';

	document.addEventListener('keypress', function(e) {
		if(e.keyCode === 84) {
			e.preventDefault();
			let timeVal = 0;
			const timeStr = document.querySelectorAll('.bpx-player-ctrl-time-current')[0].innerHTML;
			const time = timeStr.split(':');

			if(time.length === 3) {
				timeVal = time[0]*3600  + time[1]*60 + time[2];
			} else if(time.length === 2) {
				timeVal = time[0] ? time[0]*60 + time[1] : time[1];
			}

			const burl = window.location.href.split('?')[0] + '#t=' + timeVal;

			if (navigator.clipboard) {
				navigator.clipboard.writeText(`[${timeStr}](${burl})`);
			}
		}
	})
})();