baidu fanyi radius and shadow

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

目前為 2021-04-05 提交的版本,檢視 最新版本

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

You will need to install an extension such as Tampermonkey to install this script.

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         baidu fanyi radius and shadow
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  百度翻译添加圆角和阴影以及删除广告
// @author       宏斌
// @match        https://fanyi.baidu.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    function addRadiusAndShadow (className,widthPercent) {
            const targetElement = document.getElementsByClassName(className)[0];
            handleStyled(targetElement,widthPercent);
    };

    function handleStyled (targetElement,widthPercent) {
        targetElement.style['border-radius']='10px';
        targetElement.style['box-shadow']='2px 2px 10px #ccc';
        targetElement.style['overflow']='hidden';
        if(widthPercent) targetElement.style['width'] = widthPercent+'%';
    }

            addRadiusAndShadow('trans-left',49.5);
            addRadiusAndShadow('trans-right',49.5);
            addRadiusAndShadow('history-wrap',99);
            addRadiusAndShadow('trans-input-wrap');
            //右侧广告
            const transRight = document.getElementsByClassName("trans-right")[1];
            transRight.parentNode.removeChild(transRight);
    //翻译结果
     const content = document.getElementById("left-result-container");

      const config = { attributes: false, childList: true, subtree: false };

      // 当观察到突变时执行的回调函数
      const callback = function (mutationsList) {
        const targetElement = mutationsList[0].target.children[0];
        if (targetElement && targetElement.nodeName) {
          handleStyled(targetElement);
        }
      };

      // 创建一个链接到回调函数的观察者实例
      const observer = new MutationObserver(callback);

      // 开始观察已配置突变的目标节点
      observer.observe(content, config);
})();