度盘给我播!

强迫度盘打开 ts mts f4v m2ts等视频文件的播放页面。

  1. // ==UserScript==
  2. // @name 度盘给我播!
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2.1
  5. // @description 强迫度盘打开 ts mts f4v m2ts等视频文件的播放页面。
  6. // @author coolwind2012
  7. // @match http*://pan.baidu.com/disk/home*
  8. // @exclude http*://pan.baidu.com/disk/home*search*
  9. // @icon https://pan.baidu.com/box-static/disk-system/images/favicon.ico
  10. // @require https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js
  11. // @grant none
  12. // @run-at document-end
  13. // ==/UserScript==
  14. let myPath;
  15. (function () {
  16. const timer = setInterval(() => {
  17. if (document.querySelector(".vdAfKMb")) {
  18. work();
  19. clearInterval(timer);
  20. }
  21. }, 200);
  22. window.addEventListener("hashchange", afterHashChanged, false);
  23. afterHashChanged();
  24. })()
  25.  
  26. function afterHashChanged() {
  27. // https://pan.baidu.com/disk/home#list/path=%2F&vmode=list
  28. if (location.href.indexOf('/disk/home') !== -1) {
  29. myPath = location.href.split('path=')[1].split('&')[0];
  30. }
  31. myPath += (decodeURIComponent(myPath).slice(-1) === '/') ? '' : '%2F';
  32. }
  33.  
  34. function work() {
  35. 'use strict';
  36. const mediaType = new Array('ts', '3gp2', '3g2', '3gpp', 'amv', 'divx', 'dpg', 'f4v', 'm2t', 'm2ts', 'm2v', 'mpe', 'mpeg', 'mts', 'vob', 'webm', 'wxp', 'wxv');
  37. init();
  38.  
  39. // 小图标的变化与处理
  40. //启动检测: 修改动作 监测对象与配置
  41. new MutationObserver(listChange).observe(document.querySelector('.vdAfKMb'), {
  42. attributes: false,
  43. childList: true,
  44. subtree: false
  45. });
  46.  
  47. new MutationObserver(listChange).observe(document.querySelector('.JKvHJMb'), {
  48. attributes: false,
  49. childList: true,
  50. subtree: false
  51. });
  52.  
  53. function init() {
  54. updateItem(document.querySelectorAll('.vdAfKMb>dd'));
  55. }
  56.  
  57. function listChange(mutationList) {
  58. updateItem(mutationList[0].addedNodes);
  59. }
  60.  
  61. function isMedia(str) {
  62. str = str.toLowerCase();
  63. str = str.split('.').pop();
  64. return mediaType.includes(str);
  65. }
  66.  
  67. function updateItem(itemList) {
  68. const itemQueryStr = document.querySelector('.fyQgAEb').style.display == 'none'? '.text a':'.file-name a'; // :not(.open-enable)
  69. if(itemQueryStr == '.file-name a'){
  70. let tmp = [];
  71. itemList.forEach(item =>{
  72. for(let i=0;i<item.children.length;i++){
  73. tmp.push(item.children[i]);
  74. }
  75. })
  76. itemList = tmp;
  77. }
  78. itemList.forEach(item => {
  79. const aEle = item.querySelector(itemQueryStr);
  80. const suffix = aEle.title.split('.').pop();
  81. if (isMedia(suffix) && aEle.href === 'javascript:void(0);') {
  82. aEle.onclick = ()=>{
  83. window.open('https://pan.baidu.com/play/video#video/path=' + myPath + encodeURIComponent(aEle.title));
  84. };
  85. aEle.href = '';
  86. aEle.target = '_blank_';
  87. item.querySelector('.twwJWy').className = 'twwJWy fileicon-sys-s-video';
  88. }
  89. });
  90. }
  91. }