好看视频标题搜索

在好看视频网页中添加按钮,点击后在抖音和B站搜索视频标题

  1. // ==UserScript==
  2. // @name 好看视频标题搜索
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.0.1
  5. // @description 在好看视频网页中添加按钮,点击后在抖音和B站搜索视频标题
  6. // @author zzx114
  7. // @match *://haokan.baidu.com/*
  8. // @grant GM_openInTab
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // 确保页面加载完成后运行脚本
  16. const observer = new MutationObserver(() => {
  17. if (document.body) {
  18. observer.disconnect(); // 停止监听
  19. main();
  20. }
  21. });
  22.  
  23. observer.observe(document.documentElement, { childList: true, subtree: true });
  24.  
  25. function main() {
  26. // 创建按钮
  27. const searchButton = document.createElement("button");
  28. searchButton.textContent = "搜索标题";
  29. searchButton.style.position = "fixed";
  30. searchButton.style.top = "10px"; // 距离页面顶部10px
  31. searchButton.style.left = "50%"; // 水平居中
  32. searchButton.style.transform = "translateX(-50%)"; // 精确居中
  33. searchButton.style.padding = "5px 10px";
  34. searchButton.style.fontSize = "14px";
  35. searchButton.style.backgroundColor = "#4CAF50";
  36. searchButton.style.color = "white";
  37. searchButton.style.border = "none";
  38. searchButton.style.borderRadius = "5px";
  39. searchButton.style.zIndex = "9999"; // 确保按钮在最上层
  40. searchButton.style.cursor = "pointer";
  41.  
  42. // 将按钮添加到页面
  43. document.body.appendChild(searchButton);
  44.  
  45. // 获取视频标题
  46. let videoTitle = document.title || ""; // 默认使用页面标题
  47. if (!videoTitle) {
  48. alert("未找到视频标题!");
  49. return;
  50. }
  51.  
  52. // 使用正则表达式匹配英文逗号前的内容
  53. const match = videoTitle.match(/([^,]+),/);
  54. if (match) {
  55. videoTitle = match[1].trim(); // 获取匹配的内容并去除两端空白字符
  56. } else {
  57. videoTitle = videoTitle.trim(); // 如果没有匹配到,使用原始标题
  58. }
  59.  
  60. // 按钮点击事件
  61. searchButton.addEventListener("click", () => {
  62. const encodedTitle = encodeURIComponent(videoTitle);
  63.  
  64. // 在抖音搜索
  65. GM_openInTab(`https://www.douyin.com/search/${encodedTitle}`, { active: false });
  66.  
  67. // 在B站搜索
  68. GM_openInTab(`https://www.bilibili.com/search?keyword=${encodedTitle}`, { active: false });
  69. });
  70.  
  71. console.log("搜索按钮已添加到页面!");
  72. }
  73. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址