baidu fanyi radius and shadow

百度翻译添加圆角和阴影以及删除广告

  1. // ==UserScript==
  2. // @name baidu fanyi radius and shadow
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.4
  5. // @description 百度翻译添加圆角和阴影以及删除广告
  6. // @author 宏斌
  7. // @match https://fanyi.baidu.com/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13. function addRadiusAndShadow (className,widthPercent) {
  14. const targetElement = document.getElementsByClassName(className)[0];
  15. handleStyled(targetElement,widthPercent);
  16. };
  17.  
  18. function handleStyled (targetElement,widthPercent) {
  19. targetElement.style['border-radius']='10px';
  20. targetElement.style['box-shadow']='2px 2px 10px #ccc';
  21. targetElement.style['overflow']='hidden';
  22. if(widthPercent) targetElement.style['width'] = widthPercent+'%';
  23. }
  24.  
  25. addRadiusAndShadow('trans-left',49.5);
  26. addRadiusAndShadow('trans-right',49.5);
  27. addRadiusAndShadow('history-wrap',99);
  28. addRadiusAndShadow('trans-input-wrap');
  29. //右侧广告
  30. const transRight = document.getElementsByClassName("trans-right")[1];
  31. transRight.parentNode.removeChild(transRight);
  32. //翻译结果
  33. const content = document.getElementById("left-result-container");
  34.  
  35. const config = { attributes: false, childList: true, subtree: false };
  36.  
  37. // 当观察到突变时执行的回调函数
  38. const callback = function (mutationsList) {
  39. const targetElement = mutationsList[0].target.children[0];
  40. if (targetElement && targetElement.nodeName) {
  41. handleStyled(targetElement);
  42. }
  43. };
  44.  
  45. // 创建一个链接到回调函数的观察者实例
  46. const observer = new MutationObserver(callback);
  47.  
  48. // 开始观察已配置突变的目标节点
  49. observer.observe(content, config);
  50. //搜索内容直接打开百度搜索
  51. // https://www.baidu.com/s?ie=UTF-8&wd=%E5%93%88%E5%93%88
  52. const sBtn = document.createElement('button')
  53. sBtn.id="sbtn"
  54. sBtn.innerText="search"
  55. $(".input-wrap").append(sBtn)
  56. $("#sbtn").css({position: 'absolute',bottom: 0,right: 0,border:'none','border-top-left-radius':'5px',cursor: 'pointer',height:'2rem','text-transform':'uppercase',color:"#fff",'background-color':"#999"})
  57. $("#sbtn").on('click',()=>{
  58. window.open("https://www.baidu.com/s?ie=UTF-8&wd="+$("#baidu_translate_input").val(),'newwindow');
  59. })
  60. })();

QingJ © 2025

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