B站-复制视频引用.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // ==UserScript==
  2. // @name T-B站-复制视频引用
  3. // @namespace Violentmonkey Scripts
  4. // @match https://www.bilibili.com/video/*
  5. // @grant none
  6. // @version 1.0
  7. // @author tianyunperfect
  8. // @require https://cdn.bootcdn.net/ajax/libs/jquery/3.3.1/jquery.min.js
  9. // @description 2021/1/30 下午7:09:51
  10. // ==/UserScript==
  11. (function () {
  12. 'use strict';
  13. jQuery.noConflict();
  14. function getTempId() {
  15. return "myTmp" + Math.floor(Math.random() * 10000);
  16. }
  17. function myCopy(string) {
  18. let tmpId = getTempId();
  19. jQuery('body').append(jQuery("<div id='" + tmpId + "'>" + string + "</div>"))
  20. let range = document.createRange();
  21. range.selectNode(jQuery("#" + tmpId)[0]);
  22. // 清除选择
  23. window.getSelection().removeAllRanges();
  24. window.getSelection().addRange(range);
  25. console.log('复制成功');
  26. document.execCommand('copy');
  27. // 清除选择
  28. window.getSelection().removeAllRanges();
  29. jQuery('#' + tmpId).remove();
  30. }
  31. jQuery('.tit').dblclick(function () {
  32. let bvid = window.__INITIAL_STATE__.videoData.bvid;
  33. let aid = window.__INITIAL_STATE__.videoData.aid;
  34. let cid = window.__INITIAL_STATE__.videoData.cid;
  35. // let url = `https://player.bilibili.com/player.html?high_quality=1&danmaku=0&bvid=${bvid}`;
  36. let url = `https://video-direct-link.vercel.app/bili.mp4?aid=${aid}&bvid=${bvid}&cid=${cid}`;
  37. myCopy(url);
  38. let tmpId = getTempId();
  39. jQuery(".tit").eq(0).append(jQuery('<span class="tag" id="' + tmpId + '">:已复制</span>'));
  40. setTimeout(() => {
  41. jQuery('#' + tmpId).remove();
  42. }, 1500)
  43. });
  44. })();